[wrangler] Smart cache directory detection for Yarn PnP compatibility#12466
Merged
petebacondarwin merged 8 commits intomainfrom Feb 16, 2026
Merged
[wrangler] Smart cache directory detection for Yarn PnP compatibility#12466petebacondarwin merged 8 commits intomainfrom
petebacondarwin merged 8 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 189646a The changes in this PR will be included in the next version bump. 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 |
Contributor
|
Claude finished @petebacondarwin's task —— View job Changeset Review CompleteTodo List:
✅ All changesets look good All three changesets follow the guidelines:
|
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
ef70325 to
64524ff
Compare
64524ff to
e26e830
Compare
1 task
Add WRANGLER_HOME and WRANGLER_CACHE_DIR environment variables to allow users to configure where Wrangler stores temporary and cache files. This addresses compatibility issues with Yarn PnP projects that don't have node_modules directories. - Add WRANGLER_HOME env var to override .wrangler directory location - Add WRANGLER_CACHE_DIR env var to override cache directory location - Auto-detect Yarn PnP projects via .pnp.cjs/.pnp.js files - Update Miniflare to respect these env vars for cf.json cache - Add turbo.json passthrough for new environment variables Fixes #4299
Remove WRANGLER_HOME env var and simplify the implementation to only use: - WRANGLER_CACHE_DIR for wrangler's cache directory - MINIFLARE_CACHE_DIR for miniflare's cf.json cache - Automatic Yarn PnP detection (cached for performance) Both wrangler and miniflare now auto-detect Yarn PnP projects and use .wrangler/cache/ instead of node_modules/ directories.
Replace the Yarn PnP-specific detection with a more general approach: 1. Use WRANGLER_CACHE_DIR / MINIFLARE_CACHE_DIR env var if set 2. Use existing cache directory if found (node_modules/.cache/wrangler or .wrangler/cache) 3. Create cache in node_modules if it exists 4. Fall back to .wrangler/cache This approach is more robust and works with any package manager that doesn't use traditional node_modules directories.
Miniflare now only uses MINIFLARE_CACHE_DIR for env var override, keeping the two packages independent while still providing the same smart cache directory detection.
ascorbic
reviewed
Feb 16, 2026
Remove module-level caching of cache folder paths in both Wrangler and Miniflare. The caching was causing test isolation issues where the cached path from one test would leak into subsequent tests running in different temp directories. The performance impact is negligible (2-3 extra filesystem lookups per command, ~10ms total) and removing the caching: - Fixes test isolation issues naturally - Simplifies the code - Removes the need for dynamic imports in tests Also renamed config-cache-without-cache-dir.test.ts to config-cache-wrangler-fallback.test.ts and updated tests to verify the new .wrangler/cache fallback behavior.
c021c5a to
5920dc4
Compare
The .wrangler directory contains local cache and state files that should never be deployed. This aligns Pages upload behavior with Workers Assets, which already excludes .wrangler via .assetsignore.
ascorbic
reviewed
Feb 16, 2026
| * 5. .wrangler/cache as final fallback | ||
| */ | ||
| function getDefaultCfPath(): string { | ||
| // Priority 1: MINIFLARE_CACHE_DIR (miniflare-specific override) |
Contributor
There was a problem hiding this comment.
Numbered comments are such an LLM tell 😀
ascorbic
approved these changes
Feb 16, 2026
Contributor
Author
|
Thanks @ascorbic |
Merged
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4299.
This PR improves how Wrangler and Miniflare determine where to store cache files, making them compatible with Yarn PnP (Plug'n'Play) and other package managers that don't use traditional
node_modulesdirectories.Wrangler Cache Directory Resolution
Wrangler now uses the following priority to determine the cache directory:
WRANGLER_CACHE_DIRnode_modules/.cache/wrangleror.wrangler/cacheif foundnode_modules/.cache/wrangler.wrangler/cacheMiniflare Cache Directory Resolution
Miniflare now uses the following priority to determine where to store its cf.json cache:
MINIFLARE_CACHE_DIRnode_modules/.mfor.wrangler/cacheif foundnode_modules/.mf.wrangler/cacheThis approach:
Environment Variables
WRANGLER_CACHE_DIR- Override wrangler's cache directoryMINIFLARE_CACHE_DIR- Override miniflare's cf.json cache directoryImplementation Notes
The cache folder path is computed fresh on each call (no in-memory caching). This design choice:
A picture of a cute animal (not mandatory, but encouraged)
🦔