Skip to content

[miniflare] Add environment variables to control cf.json fetching#12469

Merged
petebacondarwin merged 1 commit intomainfrom
fix/3659-cf-fetch-env-var
Feb 8, 2026
Merged

[miniflare] Add environment variables to control cf.json fetching#12469
petebacondarwin merged 1 commit intomainfrom
fix/3659-cf-fetch-env-var

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Feb 7, 2026

Fixes #3659.

Adds two new environment variables that allow users to control the cf.json caching behavior in Miniflare:

  • CLOUDFLARE_CF_FETCH_ENABLED: Set to "false" to disable fetching entirely and use fallback Request.cf data. No files are created in node_modules/.mf/. Defaults to "true".
  • CLOUDFLARE_CF_FETCH_PATH: Set to a custom path to use a different location for caching the cf.json file instead of the default node_modules/.mf/cf.json. An empty value uses the default path.

The explicit cf option in Miniflare takes precedence over both environment variables.

This is particularly useful for:

  1. Non-JavaScript projects (e.g., Rust, C++, Go Workers) that don't want a node_modules directory created automatically
  2. Multi-project setups where users want consistent global configuration
  3. Projects wanting custom cache locations

Example usage:

# Disable cf fetching for all projects
export CLOUDFLARE_CF_FETCH_ENABLED=false
npx wrangler dev

# Or use a custom cache location
export CLOUDFLARE_CF_FETCH_PATH=/tmp/.cf-cache.json
npx wrangler dev

  • 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: The environment variables are self-documenting and the changeset provides usage examples.

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

🦊

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 7, 2026

🦋 Changeset detected

Latest commit: 814d321

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

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 7, 2026

Claude finished @petebacondarwin's task —— View job


Changeset Review

  • Read changeset guidelines
  • Read changeset file
  • Validate changeset
  • Check for cute animals

All changesets look good

The changeset .changeset/add-wrangler-cf-fetch-env.md passes all validation criteria:

  1. Version Type: minor is appropriate for new configuration options
  2. Changelog Quality: Clear description with helpful usage examples showing how to use the new environment variables
  3. Markdown Headers: No h1/h2/h3 headers used
  4. Analytics: No new analytics collection
  5. Dependabot: Not a dependency update
  6. Experimental Features: These are stable features, properly documented

The changeset follows best practices with a clear title, detailed explanation of the new environment variables, and practical examples showing real-world usage scenarios.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 7, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 814d321

@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from 9abc10d to 9a9e66d Compare February 7, 2026 15:00
@petebacondarwin petebacondarwin changed the title [miniflare] Add WRANGLER_CF_FETCH environment variable to control cf.json fetching [miniflare] Add CLOUDFLARE_CF_FETCH environment variable to control cf.json fetching Feb 7, 2026
@petebacondarwin petebacondarwin marked this pull request as ready for review February 7, 2026 15:12
@petebacondarwin petebacondarwin requested a review from a team as a code owner February 7, 2026 15:12
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Member

@NuroDev NuroDev left a comment

Choose a reason for hiding this comment

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

Overall looks good. One question though:

Explicit cf option in Miniflare: Takes precedence over the environment variable.

Is this normal? I have always assumed that if an environment variable exists to modify how a feature functions that that will always be the highest level of override, no? The same as if there is an experimental feature hard coded to now be enabled by default and there was an env var to disable it, enabling / using that env var would disable it and override the hard coded default.

@petebacondarwin
Copy link
Copy Markdown
Contributor Author

I have always assumed that if an environment variable exists to modify how a feature functions that that will always be the highest level of override, no?

I think we normally go with: CLI arg -> env var -> config file -> default

In this case the "explicit cf option" is part of the Miniflare programmatic API, which I think equates to the CLI args when in programmatic usage.

@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from 9a9e66d to aba7873 Compare February 7, 2026 17:05
@petebacondarwin petebacondarwin changed the title [miniflare] Add CLOUDFLARE_CF_FETCH environment variable to control cf.json fetching [miniflare] Add environment variables to control cf.json fetching Feb 7, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 6 additional findings in Devin Review.

Open in Devin Review

@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from aba7873 to 3f613d6 Compare February 7, 2026 17:13
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

@NuroDev - implementation changed PTAL

devin-ai-integration bot added a commit to cloudflare/cloudflare-docs that referenced this pull request Feb 7, 2026
…ironment variables

Add documentation for two new environment variables that control cf.json
fetching behavior in Miniflare:

- CLOUDFLARE_CF_FETCH_ENABLED: disable cf.json fetching entirely
- CLOUDFLARE_CF_FETCH_PATH: use a custom cache location for cf.json

Updates both the system environment variables reference page and the
Miniflare get-started guide.

Related: cloudflare/workers-sdk#12469
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Feb 7, 2026
@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from 3f613d6 to 84af6d4 Compare February 8, 2026 14:11
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from 84af6d4 to 5f7234d Compare February 8, 2026 14:34
Adds two new environment variables that allow users to control the cf.json
caching behavior in Miniflare:

- CLOUDFLARE_CF_FETCH_ENABLED: Set to "false" or "0" to disable fetching
  entirely (uses fallback data). Defaults to "true".
- CLOUDFLARE_CF_FETCH_PATH: Set to a custom path to use a different location
  for caching the cf.json file. Empty string is treated as unset.

This is useful for non-JavaScript projects (like Rust or Go Workers)
that don't want a node_modules directory created automatically.

Fixes #3659
@petebacondarwin petebacondarwin force-pushed the fix/3659-cf-fetch-env-var branch from 5f7234d to 814d321 Compare February 8, 2026 14:36
@petebacondarwin petebacondarwin merged commit 2d90127 into main Feb 8, 2026
35 of 36 checks passed
@petebacondarwin petebacondarwin deleted the fix/3659-cf-fetch-env-var branch February 8, 2026 15:08
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Feb 8, 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.

🚀 Feature Request: Add environment variable for --cf-fetch / --no-cf-fetch

3 participants