Skip to content

fix(wrangler): hide multi-env warning when env is set via CLOUDFLARE_ENV#13827

Open
greyvugrin wants to merge 30 commits intocloudflare:mainfrom
greyvugrin:fix-workers-deploy-warning-cloudflare-env
Open

fix(wrangler): hide multi-env warning when env is set via CLOUDFLARE_ENV#13827
greyvugrin wants to merge 30 commits intocloudflare:mainfrom
greyvugrin:fix-workers-deploy-warning-cloudflare-env

Conversation

@greyvugrin
Copy link
Copy Markdown

@greyvugrin greyvugrin commented May 5, 2026

Changes:

  • Updated tests for wrangler commands to account for this use case (env specified through CLOUDFLARE_ENV)
  • Added fix that leverages computed targetEnvironment
  • Updated warning message to mention CLOUDFLARE_ENV
  • Updated tests to use a helper for the warning message text to check against

Example of failures prior to adjusting the source code:
Screenshot 2026-05-05 at 3 36 11 PM


  • 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: this updates behavior to match existing docs
sierra-nicole-narvaeth-aM7r5lqKhiY-unsplash

Photo by Sierra NiCole Narvaeth on Unsplash

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

🦋 Changeset detected

Latest commit: 4dd4a0b

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

@greyvugrin greyvugrin marked this pull request as ready for review May 6, 2026 00:03
@workers-devprod workers-devprod requested review from a team and edmundhung and removed request for a team May 6, 2026 00:03
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented May 6, 2026

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/mighty-planes-give.md: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/config-helpers.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/environments.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/secret.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/versions/secrets/bulk.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/versions/secrets/delete.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/versions/secrets/put.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/versions/versions.deploy.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/versions/versions.upload.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/register-yargs-command.ts: [@cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread packages/wrangler/src/__tests__/deploy/environments.test.ts Outdated
Comment thread packages/wrangler/src/__tests__/helpers/multi-env-warning.ts Outdated
Comment thread packages/wrangler/src/__tests__/versions/secrets/bulk.test.ts Outdated
Comment thread packages/wrangler/src/__tests__/versions/secrets/delete.test.ts Outdated
const availableEnvs = Object.keys(rawConfig.env ?? {});
if (availableEnvs.length > 0) {
// The targetEnvironment will contain the resolved result of the env flag and the env var, if passed
if (config.targetEnvironment === undefined) {
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 this quite right?

If we are processing a redirected config, then this value is the one environment used when generating the redirected config. It's purpose is so that we can ensure that any --env or CLOUDFLARE_ENV (i.e. the current selected environment) matches the original target.

So this code might work where there is no redirected config, which I think is the case for all the tests above. But will fail otherwise...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah gotcha, yep I see the issue. Added a test to cover that case (it failed) and then updated the code to fix it.
Added a helper to detect if it's a redirected config to not duplicate the logic there.

Also, added tests for the expected --env="" behavior to ensure that's preserved moving forward.

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 6, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk May 6, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 4dd4a0b

@greyvugrin greyvugrin requested a review from petebacondarwin May 7, 2026 17:52
@petebacondarwin petebacondarwin force-pushed the fix-workers-deploy-warning-cloudflare-env branch from 3ae1d5e to 26e6134 Compare May 7, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants