Skip to content

Cache package dependency collection results to avoid redundant filesystem walks#14672

Closed
dario-piotrowicz wants to merge 1 commit into
mainfrom
dario/cache-pkg-deps
Closed

Cache package dependency collection results to avoid redundant filesystem walks#14672
dario-piotrowicz wants to merge 1 commit into
mainfrom
dario/cache-pkg-deps

Conversation

@dario-piotrowicz

@dario-piotrowicz dario-piotrowicz commented Jul 13, 2026

Copy link
Copy Markdown
Member

collectPackageDependencies now accepts an optional cacheDir parameter. When provided, collected results are persisted to disk and reused on subsequent calls as long as neither package.json nor the project's lockfile have been modified. This speeds up repeated deploys when dependencies haven't changed.


Followup for #14591


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: transparent DX improvement

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aab6245

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/deploy-helpers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ask-bonk

ask-bonk Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

UnknownError: ProviderInitError

github run

@ask-bonk

ask-bonk Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@dario-piotrowicz Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14672

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@14672

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14672

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@14672

miniflare

npm i https://pkg.pr.new/miniflare@14672

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@14672

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@14672

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@14672

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@14672

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14672

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@14672

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@14672

wrangler

npm i https://pkg.pr.new/wrangler@14672

commit: aab6245

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

This comment was marked as resolved.

@dario-piotrowicz
dario-piotrowicz force-pushed the dario/cache-pkg-deps branch 2 times, most recently from a212e68 to 809a696 Compare July 13, 2026 16:11
@dario-piotrowicz
dario-piotrowicz marked this pull request as ready for review July 13, 2026 16:30
@workers-devprod
workers-devprod requested review from a team and NuroDev and removed request for a team July 13, 2026 16:30
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/cache-package-dependencies.md: [@cloudflare/wrangler]
  • packages/deploy-helpers/package.json: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/deploy/deploy.ts: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/deploy/helpers/package-dependencies.ts: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/deploy/versions-upload.ts: [@cloudflare/wrangler]
  • packages/deploy-helpers/src/shared/types.ts: [@cloudflare/wrangler]
  • packages/deploy-helpers/tests/package-dependencies.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/merge-config-args.ts: [@cloudflare/wrangler]
  • pnpm-lock.yaml: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

@dario-piotrowicz
dario-piotrowicz marked this pull request as draft July 14, 2026 12:48
for (const name of KNOWN_LOCKFILES) {
const filePath = find.file(name, { cwd: projectPath });
if (filePath) {
const content = await readFile(filePath);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth wrapping this in a try / catch so we can safely return null with a console warning instead?

return result.length > 0 ? result : undefined;
} catch (error) {
logger.debug(
logger?.debug(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is logger now nullish? I assumed it would be a singleton, no?

"@types/node": "catalog:default",
"concurrently": "^8.2.2",
"devtools-protocol": "^0.0.1182435",
"empathic": "^2.0.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this dependency really needed? Can we not achieve the same functionality as empathic/find with regular Node.js tools?

Comment on lines +392 to +393
const cwd = process.cwd();
const cacheDir = path.join(cwd, ".cache");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to use the temp directory helper for this?

Comment on lines +410 to +411
const second = await collectPackageDependencies(cwd, { cacheDir });
expect(second).toEqual(first);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be better to use mocks or something similar to check to make sure the cache actually gets hit?

@dario-piotrowicz

Copy link
Copy Markdown
Member Author

Closing in favor of #14703

@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants