Skip to content

[wrangler] fix: ensure types --check --env-file does not falsely report stale when .dev.vars exists#13751

Merged
NuroDev merged 6 commits intocloudflare:mainfrom
matingathani:fix/wrangler-types-check-envfile
May 7, 2026
Merged

[wrangler] fix: ensure types --check --env-file does not falsely report stale when .dev.vars exists#13751
NuroDev merged 6 commits intocloudflare:mainfrom
matingathani:fix/wrangler-types-check-envfile

Conversation

@matingathani
Copy link
Copy Markdown
Contributor

@matingathani matingathani commented Apr 30, 2026

Fixes #13679.

wrangler types --check --env-file /dev/null falsely reported types as stale whenever a local .dev.vars existed, even when the on-disk file was generated with the matching wrangler types --env-file /dev/null command.

The --check codepath in checkTypesUpToDate dropped envFile when re-running env-type generation internally. This caused .dev.vars to be loaded unconditionally, producing a hash mismatch.

Fix:

  • checkTypesUpToDate now accepts an optional cliEnvFile parameter
  • The --check handler passes the active CLI's envFile to checkTypesUpToDate
  • checkTypesUpToDate uses the CLI-provided envFile as the primary source of truth, falling back to parsing from the types file header comment
  • Added test verifying --check --env-file /dev/null reports types up-to-date even when .dev.vars exists

  • 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: fixes an existing feature to work as documented

Open in Devin Review

Copilot AI review requested due to automatic review settings April 30, 2026 01:23
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: 03c25ec

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

@workers-devprod workers-devprod requested review from a team and jamesopstad and removed request for a team and Copilot April 30, 2026 01:24
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 30, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

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 3 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 this change looks good to me, thanks @matingathani!
Just a few file conflicts that need to be fixed up and should be good to merge

Comment thread packages/wrangler/src/type-generation/helpers.ts Outdated
Comment thread packages/wrangler/src/__tests__/type-generation.test.ts
@jamesopstad jamesopstad removed their request for review April 30, 2026 09:40
@matingathani
Copy link
Copy Markdown
Contributor Author

Regarding the .env question — yes, the fix applies to .env files as well. When --env-file is explicitly provided, it takes precedence over both .dev.vars and .env. The .env file is the fallback when no .dev.vars exists (see the existing test "should include secret keys from .env, if there is no .dev.vars"). The key fix here is that --check now passes the CLI envFile through to checkTypesUpToDate instead of dropping it, so the same flag used for initial generation is also used for the stale check.

Also moved the envFile extraction chunk up and added a comment explaining why the CLI-provided value takes priority over the one parsed from the header comment.

Copilot AI review requested due to automatic review settings May 1, 2026 01:08
@matingathani matingathani force-pushed the fix/wrangler-types-check-envfile branch from 720ea61 to ebef732 Compare May 1, 2026 01:08
Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Wrangler types --check regression where specifying --env-file was not respected during the internal regeneration step, causing .dev.vars to be loaded and the generated hash to mismatch.

Changes:

  • Pass the active CLI --env-file through the types --check flow into checkTypesUpToDate.
  • Teach checkTypesUpToDate to prefer the CLI-provided envFile, falling back to parsing it from the generated header command.
  • Add a regression test covering types --check --env-file ... when .dev.vars exists, plus a changeset for a patch release.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/wrangler/src/type-generation/index.ts Threads args.envFile into checkTypesUpToDate for --check.
packages/wrangler/src/type-generation/helpers.ts Extends checkTypesUpToDate to carry envFile into generateEnvTypes during re-check.
packages/wrangler/src/tests/type-generation.test.ts Adds regression coverage for --check --env-file when .dev.vars is present.
.changeset/fix-wrangler-types-check-env-file.md Declares a patch changeset for the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/wrangler/src/type-generation/helpers.ts
Comment thread packages/wrangler/src/__tests__/type-generation.test.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an issue in Wrangler’s types --check flow where providing --env-file was not respected during the internal regeneration step, causing false “stale types” reports when a local .dev.vars file exists.

Changes:

  • Pass the active CLI invocation’s envFile/env values into checkTypesUpToDate from the types --check handler.
  • Teach checkTypesUpToDate to prefer CLI-provided envFile/env, falling back to parsing them from the types file’s “Generated by Wrangler…” header.
  • Add a regression test ensuring types --check --env-file=<empty file> is considered up-to-date even when .dev.vars exists.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/wrangler/src/type-generation/index.ts Forwards envFile/env into the --check comparison path so regeneration matches the user’s flags.
packages/wrangler/src/type-generation/helpers.ts Uses CLI-provided envFile/env when recomputing the env hash during --check, preventing .dev.vars from being implicitly loaded when --env-file was intended.
packages/wrangler/src/tests/type-generation.test.ts Adds regression coverage for the .dev.vars + --env-file + --check scenario.
.changeset/fix-wrangler-types-check-env-file.md Ships the fix as a patch changeset for wrangler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/wrangler/src/type-generation/helpers.ts
Comment thread packages/wrangler/src/__tests__/type-generation.test.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes wrangler types --check --env-file … incorrectly reporting generated types as stale when a local .dev.vars exists, by ensuring the --check regeneration path uses the same --env-file/--env context as the active CLI invocation.

Changes:

  • Pass the active CLI invocation’s envFile and env values into checkTypesUpToDate().
  • Update checkTypesUpToDate() to prefer CLI-provided envFile/env, falling back to values parsed from the generated types header.
  • Add a regression test covering types --check --env-file behavior when .dev.vars exists.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/wrangler/src/type-generation/index.ts Wires args.envFile/args.env through to the --check staleness check so regen uses the correct environment inputs.
packages/wrangler/src/type-generation/helpers.ts Extends checkTypesUpToDate() to carry envFile/env into generateEnvTypes() during --check comparisons.
packages/wrangler/src/tests/type-generation.test.ts Adds regression test ensuring --check --env-file does not become stale due to .dev.vars.
.changeset/fix-wrangler-types-check-env-file.md Adds patch changeset entry documenting the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matingathani matingathani requested a review from NuroDev May 1, 2026 20:33
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 5, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 5, 2026
@NuroDev
Copy link
Copy Markdown
Member

NuroDev commented May 5, 2026

There seems to be some formatting issues that need fixing @matingathani:

packages/wrangler/src/__tests__/type-generation.test.ts (16ms)
packages/wrangler/src/type-generation/helpers.ts (1ms)

Running pnpm run prettify should fix them.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 03c25ec

…rt stale when .dev.vars exists

In checkTypesUpToDate, envFile was not extracted from the header comment nor forwarded from the active CLI invocation. This caused --check to always load .dev.vars, producing a hash mismatch when types were generated with --env-file /dev/null.

The fix: accept cliEnvFile parameter from the --check handler and use it as the primary source of truth for env file loading during hash comparison.

Fixes cloudflare#13679
… for cross-platform compatibility

- Add cliEnv parameter to checkTypesUpToDate and thread through to generateEnvTypes
  to prevent hash mismatches when configs have named environments
- Replace /dev/null with an empty temp file in the regression test for Windows compat
@matingathani matingathani force-pushed the fix/wrangler-types-check-envfile branch from 8c0678f to 45b22cd Compare May 6, 2026 21:47
@matingathani
Copy link
Copy Markdown
Contributor Author

Rebased on main and ran pnpm run prettify to fix the formatting. The Windows CI failure in the previous run was in miniflare/test/plugins/browser/index.spec.ts and workflows-shared — neither is touched by this PR and both fail on unrelated PRs as well (pre-existing flakiness). Should be good to merge now!

@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@matingathani
Copy link
Copy Markdown
Contributor Author

@NuroDev @penalosa @dario-piotrowicz — all Copilot review comments have been addressed. This PR is ready for review.

@NuroDev NuroDev merged commit b6cea17 into cloudflare:main May 7, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk May 7, 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.

wrangler types --check falsely reports stale when .dev.vars exists (drops --env-file on internal regen)

4 participants