chore: drop backoff dep and convert remaining require() calls to ESM#8195
chore: drop backoff dep and convert remaining require() calls to ESM#8195
Conversation
Continues the Milestone 1 dependency-pruning work from #8189. - Replace the single `backoff` call site in `src/utils/deploy/upload-files.ts` with a small inline Fibonacci retry that preserves the existing delay sequence (5s, 5s, 10s, 15s, 25s, … capped at UPLOAD_MAX_DELAY) and the `failAfter(maxRetry)` semantics. Also migrate `tests/unit/utils/gh-auth.test.ts` off `backoff` to a plain polling loop. - Convert the three remaining `require(path)` call sites to native ESM equivalents: `functions-create.ts` and `database/legacy/utils.ts` now use `JSON.parse(readFileSync(...))` for package.json lookups; `functions-invoke.ts` becomes async and supports both `.json` (readFile) and `.js/.mjs/.cjs` (dynamic `import()`) payloads. - Remove `backoff` and `@types/backoff` from package.json. - Add unit tests for `getPackageJSON` and export + test `processPayloadFromFlag` to lock in the JSON + dynamic-import behavior. Made-with: Cursor
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR removes the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/deploy/upload-files.ts (1)
80-127: Consider adding generic typing toretryUploadto preserve response types.The retry attempt semantics are correct: with
maxRetry = n, the function allows up ton + 1total attempts (initial attempt plusnretries), matching the previousfailAfter(maxRetry)behavior.However,
retryUploadcurrently returnsPromise<unknown>, causing theresponsevariable (lines 30 and 42) to lose type information fromapi.uploadDeployFile()andapi.uploadDeployFunction(). Add a generic parameter to preserve the response type:Suggested typing refinement
-const retryUpload = (uploadFn: (retryCount: number) => Promise<unknown>, maxRetry: number) => - new Promise((resolve, reject) => { +const retryUpload = <T>(uploadFn: (retryCount: number) => Promise<T>, maxRetry: number): Promise<T> => + new Promise<T>((resolve, reject) => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/deploy/upload-files.ts` around lines 80 - 127, The retryUpload helper should be made generic so it preserves the resolved type from callers: change retryUpload to accept a type parameter (e.g. <T>) and type uploadFn as (retryCount: number) => Promise<T>, and have retryUpload return Promise<T>; keep internal variables (lastError, retryCount, scheduleNextAttempt, tryUpload) the same but ensure resolve is typed to accept T and reject remains unknown/any as before; update any call sites of retryUpload (e.g., uses with api.uploadDeployFile and api.uploadDeployFunction) to infer or pass the concrete type if needed so the response variables keep their original types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/utils/deploy/upload-files.ts`:
- Around line 80-127: The retryUpload helper should be made generic so it
preserves the resolved type from callers: change retryUpload to accept a type
parameter (e.g. <T>) and type uploadFn as (retryCount: number) => Promise<T>,
and have retryUpload return Promise<T>; keep internal variables (lastError,
retryCount, scheduleNextAttempt, tryUpload) the same but ensure resolve is typed
to accept T and reject remains unknown/any as before; update any call sites of
retryUpload (e.g., uses with api.uploadDeployFile and api.uploadDeployFunction)
to infer or pass the concrete type if needed so the response variables keep
their original types.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 63df52d9-8379-41d4-a471-a979f681d265
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (8)
package.jsonsrc/commands/database/legacy/utils.tssrc/commands/functions/functions-create.tssrc/commands/functions/functions-invoke.tssrc/utils/deploy/upload-files.tstests/unit/commands/database/legacy/utils.test.tstests/unit/commands/functions/functions-invoke.test.tstests/unit/utils/gh-auth.test.ts
💤 Files with no reviewable changes (1)
- package.json
Summary
Continues the Milestone 1 dependency-pruning work from #8189 by finishing items B and C from the follow-up list:
backoff/@types/backoff. Its only runtime use was insrc/utils/deploy/upload-files.ts; replaced with a small inline Fibonacci retry helper that preserves the existing delay sequence (5s, 5s, 10s, 15s, 25s, …capped atUPLOAD_MAX_DELAY), the0.5jitter factor, and thefailAfter(maxRetry)"6 attempts when maxRetry=5" semantics.tests/unit/utils/gh-auth.test.tsmigrated offbackoffto a plain polling loop.require()calls to ESM.src/commands/functions/functions-create.ts(x2):require(packageJson)→JSON.parse(fs.readFileSync(...))via a smallreadJsonFilehelper.src/commands/database/legacy/utils.ts:createRequire(join(dir, 'package.json'))('./package.json')→JSON.parse(fs.readFileSync(join(dir, 'package.json'), 'utf8')).src/commands/functions/functions-invoke.ts:processPayloadFromFlagbecomes async;.jsonpayloads usereadFile+JSON.parse, other files go through dynamicimport()(viapathToFileURL) withimported.default ?? importedto preserve the CJS interop the oldrequire()provided.tests/unit/commands/database/legacy/utils.test.ts(8 cases) — exercisesgetPackageJSONhappy path plus each of the shape-validation errors.tests/unit/commands/functions/functions-invoke.test.ts(7 cases) — exercisesprocessPayloadFromFlagwith inline JSON strings,.json/.mjs/.cjsfile payloads, missing paths, and load-time errors (processPayloadFromFlagis now exported for testability).Test plan
npm run typechecknpm run lintnpm exec vitest -- run tests/unit/utils/deploy/upload-files.test.ts(2/2 — retry-count-on-retries and no-retry-on-400 still pass against the inline Fibonacci implementation)npm exec vitest -- run tests/unit/utils/gh-auth.test.ts(1/1)npm exec vitest -- run tests/unit/commands/database/legacy/utils.test.ts(8/8, new)npm exec vitest -- run tests/unit/commands/functions/functions-invoke.test.ts(7/7, new)npm run test:unit— 337 passed. The 5 failures are pre-existing onmain(copy-template-dir.test.ts× 4 hit a Node 25fs.rmdirSyncdeprecation;generate-autocompletion.test.ts× 1 has a stale snapshot).npm exec vitest -- run tests/integration/commands/functions-invoke/functions-invoke.test.ts(5/5 — validates the now-asyncprocessPayloadFromFlagpath end-to-end)Made with Cursor