-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[wrangler] Add CF_PAGES environment variables to pages dev #12473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: e8e6928 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 finished @petebacondarwin's task —— View job Changeset Review✅ All changesets look good The changeset
The changeset provides excellent detail about what variables are added, their default values, and how they can be overridden. The description is clear and will be helpful in the changelog. Cuteness Report: This is Claude's Spinner. They're a tiny orange dot doing their very best to rotate. Barely visible but full of determination. Would be 14/10 if they were an actual animal, but alas, just a loading indicator. Still deserves recognition for their hard work. |
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e139f06 to
b77b98f
Compare
| * Default vars that can be overridden by config vars. | ||
| * Useful for injecting environment-specific defaults like CF_PAGES variables. | ||
| */ | ||
| defaultVars?: Record<string, string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry quick review and I don't have time to dig too much into the details right now - also this is probably something to add the PR desc.
Why would StartDevWorkerInput received defaults?
Shoudn't the values be resolved by the caller instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good question. The problem is that if we merged them at the caller (say into the vars) they would then take priority over the other possible sources such as the config file and the .env file. These values are fallbacks for when they are not specified in any other case.
b77b98f to
b3a3849
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4d46c12 to
8b40db4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
47cc491 to
8f5b47d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
73a8278 to
fad1071
Compare
d479f67 to
0030379
Compare
Injects Pages-specific environment variables (CF_PAGES, CF_PAGES_BRANCH, CF_PAGES_COMMIT_SHA, CF_PAGES_URL) during local development with wrangler pages dev. This enables frameworks like SvelteKit to auto-detect the Pages environment during local development, improving dev/prod parity. The variables can be overridden by user-defined vars in wrangler.toml, .dev.vars, or via CLI flags. Fixes #1440
Update maskVars to accept defaultVars parameter so that CF_PAGES environment variables are not incorrectly masked as '(hidden)'. These are non-secret defaults that should be visible to users.
CF_PAGES_URL should be the deployment URL (e.g., https://<sha>.<project>.pages.dev), not the local dev server URL. - Update getPagesEnvironmentVariables to generate commit preview URL format - Determine project name from config.name, configCache, or directory name - Update changeset and e2e test expectations
…nges in formatting
0030379 to
e8e6928
Compare
Fixes #1440.
This PR adds Pages-specific environment variables to
wrangler pages devfor improved dev/prod parity. These variables are normally injected by Cloudflare Pages CI during builds/deployments.Environment Variables Added
CF_PAGES"1"- Indicates running in Pages environmentCF_PAGES_BRANCH"local"if not in a git repoCF_PAGES_COMMIT_SHACF_PAGES_URLhttps://<sha>.<project-name>.pages.dev)Project Name Resolution
The project name used in
CF_PAGES_URLis determined using the same priority aswrangler pages deploy:namefield fromwrangler.tomlproject_namefrom config cache (from previous deployments)Benefits
adapter-auto)wrangler.toml,.dev.vars, or via CLI flagsImplementation
The CF_PAGES variables are passed as
defaultVarswhich get merged before config vars. This ensures users can override any of these values in their configuration if needed.A picture of a cute animal (not mandatory, but encouraged)
🦊