Skip to content

[wrangler] add validation to redirected configs in regards to environments#8596

Merged
petebacondarwin merged 6 commits intomainfrom
dario/8359/wrangler/redirected-config-env
Apr 7, 2025
Merged

[wrangler] add validation to redirected configs in regards to environments#8596
petebacondarwin merged 6 commits intomainfrom
dario/8359/wrangler/redirected-config-env

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Mar 20, 2025

Fixes #8359

This PR adds the following validation behaviors to wrangler deploy commands, that relate
to redirected configs (i.e. config files specified by .wrangler/deploy/config.json files):

  • redirected configs are supposed to be already flattened configurations without any
    environment (i.e. a build tool should generate redirected configs already targeting specific
    environments), so if wrangler encounters a redirected config with some environments defined
    it should error
  • given the point above, specifying an environment (--env=my-env) when using redirected
    configs is incorrect, so these environments should be ignored and a warning should be
    presented to the user

@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner March 20, 2025 16:35
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 20, 2025

🦋 Changeset detected

Latest commit: eabdbf7

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

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 20, 2025

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-wrangler-8596

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8596/npm-package-wrangler-8596

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-wrangler-8596 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-workers-bindings-extension-8596 -O ./cloudflare-workers-bindings-extension.0.0.0-vd08c4fc84.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-vd08c4fc84.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-create-cloudflare-8596 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-kv-asset-handler-8596

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-miniflare-8596

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-pages-shared-8596

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-unenv-preset-8596

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-vite-plugin-8596

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-vitest-pool-workers-8596

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-workers-editor-shared-8596

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-workers-shared-8596

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14271950047/npm-package-cloudflare-workflows-shared-8596

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 4.20250321.2
workerd 1.20250404.0 1.20250404.0
workerd --version 1.20250404.0 2025-04-04

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@dario-piotrowicz
Copy link
Copy Markdown
Member Author

Pages doesn't really support environments and even shows errors when they are used:

"Pages does not support targeting an environment with the --env flag. Use the --branch flag to target your production or preview branch",

So I don't think that adding tests for this for the pages commands is necessary here 🤔

@dario-piotrowicz dario-piotrowicz added the e2e Run wrangler + vite-plugin e2e tests on a PR label Mar 20, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/8359/wrangler/redirected-config-env branch 3 times, most recently from 0c2b095 to 4a1748a Compare March 21, 2025 11:00
@dario-piotrowicz dario-piotrowicz requested a review from a team March 21, 2025 11:05
@dario-piotrowicz dario-piotrowicz force-pushed the dario/8359/wrangler/redirected-config-env branch 3 times, most recently from 8caffe9 to cca92dc Compare March 25, 2025 10:47
@dario-piotrowicz dario-piotrowicz force-pushed the dario/8359/wrangler/redirected-config-env branch from cca92dc to 8cbe58d Compare March 25, 2025 11:44
Copy link
Copy Markdown
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

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

this would be great to get in!

const definedEnvironments = Object.keys(rawConfig.env ?? {});

if (isRedirectedConfig && definedEnvironments.length > 0) {
diagnostics.errors.push(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there any way for the user to resolve this? or is this a build tool problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

is it a build tool problem, build tools should not generate configs containing environments 😕

yeah if a user were to get this there wouldn't be much they could do about it 😕

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we should ask them to contact the maker of the tool that generated the redirected file?

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Apr 4, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/8359/wrangler/redirected-config-env branch from 8cbe58d to 66f711a Compare April 4, 2025 12:01
Copy link
Copy Markdown
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

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

lock file seems to be broken though

@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Apr 4, 2025
@dario-piotrowicz dario-piotrowicz requested a review from a team April 4, 2025 16:07
@dario-piotrowicz dario-piotrowicz force-pushed the dario/8359/wrangler/redirected-config-env branch from d010e40 to bb5fa7d Compare April 4, 2025 16:08
@dario-piotrowicz
Copy link
Copy Markdown
Member Author

lock file seems to be broken though

lock file fixed 🫡

expect(text).toMatchInlineSnapshot(`"Generated: true"`);
});

it("specifying an environment cause an error since they are supported in redirected configs", async ({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
it("specifying an environment cause an error since they are supported in redirected configs", async ({
it("specifying an environment causes an error since they are not supported in redirected configs", async ({

const definedEnvironments = Object.keys(rawConfig.env ?? {});

if (isRedirectedConfig && definedEnvironments.length > 0) {
diagnostics.errors.push(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we should ask them to contact the maker of the tool that generated the redirected file?

@petebacondarwin petebacondarwin merged commit 75b454c into main Apr 7, 2025
25 of 27 checks passed
@petebacondarwin petebacondarwin deleted the dario/8359/wrangler/redirected-config-env branch April 7, 2025 08:53
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Apr 7, 2025
@workers-devprod workers-devprod mentioned this pull request Apr 7, 2025
edmundhung pushed a commit that referenced this pull request Apr 9, 2025
…onments #8596) (#8600)

* [wrangler] add validation to redirected configs in regards to environments

* error instead of warning on specified environments

* Update packages/wrangler/src/config/validation.ts

Co-authored-by: emily-shen <[email protected]>

* Update packages/wrangler/src/config/validation.ts

Co-authored-by: James Opstad <[email protected]>

* update lock file

* update fixture tests

* update lock file

---------

Co-authored-by: Dario Piotrowicz <[email protected]>
Co-authored-by: emily-shen <[email protected]>
Co-authored-by: James Opstad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e Run wrangler + vite-plugin e2e tests on a PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

🐛 BUG: env in redirected configs

5 participants