Skip to content

Generate runtime types when using the new config in vite dev and wrangler dev#14652

Draft
jamesopstad wants to merge 4 commits into
mainfrom
james/new-config-runtime-types
Draft

Generate runtime types when using the new config in vite dev and wrangler dev#14652
jamesopstad wants to merge 4 commits into
mainfrom
james/new-config-runtime-types

Conversation

@jamesopstad

Copy link
Copy Markdown
Contributor

  • 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: experimental feature

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

@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c487d37

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

This PR includes changesets to release 3 packages
Name Type
@cloudflare/vite-plugin Minor
wrangler Minor
@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

✅ All changesets look good

@ask-bonk

ask-bonk Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

All correct. Let me do a final review of the assembled content ordering in new-config.ts to check for a subtle bug: the config content from generateTypes ends with a trailing blank line (\n\n). Then runtime is appended. Let me verify this doesn't create a double blank that breaks the RUNTIME_HEADER line detection — but the header detection uses startsWith(prefix) on split lines, so leading blank lines are fine.

I've completed a thorough review. Let me summarize my findings:

Summary of the PR:

  • Refactors generateRuntimeTypes to accept existingContent instead of outFile (caller reads the file once)
  • Changes @cloudflare/config generateTypes to emit a global script (inline import(...) types, no top-level imports/declare global) so appended ambient runtime types stay global
  • Adds includeRuntime option to both vite plugin and wrangler experimental new-config paths, appending runtime types to worker-configuration.d.ts during dev
  • Makes vite plugin type generation dev-only (command === "serve")

Assessment:

  • The core design decision (global-script form to allow appended ambient globals) is sound and well-tested
  • The single-read refactor is clean, well-documented, and removes redundant file reads
  • Field mapping (compatibilityDate/compatibilityFlags → snake_case) is correct against the schema
  • The runtime-types cache logic correctly scans the full file for header/marker
  • workerd correctly added as external dependency; @cloudflare/runtime-types as bundled devDependency, consistent with @cloudflare/config
  • Tests are comprehensive: cover defaults, includeRuntime: false, build-vs-serve, global-script form
  • Changesets are correct (minor for both, documenting the dev-only behavior change)

The only minor behavioral change I noticed — wrangler's index.ts now swallows all file-read errors (not just ENOENT) — is defensive and non-user-facing for a cache read, so it's not actionable.

No logic bugs, security issues, backward-compat violations, or incorrect API behavior found.

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@14652

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14652

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14652

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 08b5881

@jamesopstad jamesopstad force-pushed the james/new-config-runtime-types branch from df4327c to c487d37 Compare July 10, 2026 20:20
@jamesopstad jamesopstad force-pushed the james/new-config-runtime-types branch from c487d37 to 06a5835 Compare July 10, 2026 20:23
@jamesopstad jamesopstad force-pushed the james/new-config-runtime-types branch from 06a5835 to 08b5881 Compare July 10, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

2 participants