Skip to content

[autoconfig] Move the Wrangler migration from codemods into runAutoConfig - #16993

Closed
edmundhung wants to merge 29 commits into
mainfrom
autoconfig-project-setup-engine
Closed

edmundhung wants to merge 29 commits into
mainfrom
autoconfig-project-setup-engine

Conversation

@edmundhung

@edmundhung edmundhung commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Part of RM-31810.

Moves the Wrangler-to-cf migration from @cloudflare/codemods into @cloudflare/autoconfig and makes it part of autoconfig's setup. getDetailsForAutoConfig() reports a project's Wrangler config, and runAutoConfig() runs the framework's setup, which sees the Wrangler config and decides what to do, then migrates the Wrangler config as the project's Worker config, in one pass. A cloudflare.config.ts stays the signal that a project is set up. cf can call autoconfig instead of codemods, and the codemods wrangler-to-cf command runs the same pass. convertWranglerConfig moves to @cloudflare/autoconfig/wrangler-to-cf.

Setting up the framework of projects that already have a cloudflare.config.ts follows in #17177. The migration's files are moved as renames (36), most edited only for their new import paths.

Examples

The codemod and cf build on two projects, using this branch's build:

A plain Worker: wrangler.jsonc with a KV namespace, a var and a cron
$ npx @cloudflare/codemods wrangler-to-cf

Detected Project Settings:
 - Worker Name: my-worker
 - Framework: Static

📦 Install packages:
 - cf (devDependency)

📝 Update package.json scripts:
 - "deploy": "cf deploy"

📄 Migrate wrangler.jsonc to cloudflare.config.ts

├ Adding Wrangler files to the .gitignore file
│ created .gitignore file
│
wrangler-to-cf: 1 file(s)
  cloudflare.config.ts
Updated 1 file(s).
// cloudflare.config.ts
import { bindings, defineConfig, triggers } from "cf/config";

export default defineConfig({
	worker: {
		name: "my-worker",
		compatibilityDate: "2026-09-24",
		compatibilityFlags: [
			"nodejs_compat",
		],
		entrypoint: "src/index.ts",
		triggers: [
			triggers.scheduled({
				schedule: "0 * * * *",
			}),
		],
		env: {
			GREETING: bindings.text("Hello"),
			CACHE: bindings.kv({
				id: "0f2ac74b498b48028cb68387c421e279",
			}),
		},
	},
});
$ npx cf build
├  Build
│  Delegating to Wrangler
📝 Regenerated .cloudflare/types/index.d.ts from cloudflare.config.ts.
◆  Build complete
A React Router app from npm create cloudflare -- --framework=react-router
$ npx @cloudflare/codemods wrangler-to-cf

Detected Project Settings:
 - Worker Name: rr-app
 - Framework: React Router
 - Build Command: react-router build
 - Output Directory: build/client

📦 Install packages:
 - cf (devDependency)
 - @cloudflare/vite-plugin@^2.0.0-rc.0 (devDependency)

📝 Update package.json scripts:
 - "deploy": "cf deploy"

tsconfig.json uses project references, which TypeScript checks separately. Add this project's ".cloudflare/types" folder to the `include` array of the referenced tsconfig that covers your Worker code, as a path relative to that tsconfig, so that TypeScript can find the types that `cf workers types` generates.

📄 Migrate wrangler.jsonc to cloudflare.config.ts

🛠️  Configuring project for React Router

wrangler-to-cf: 1 file(s)
  cloudflare.config.ts

Follow-up work:
  - [info] upload_source_maps: Wrangler `upload_source_maps: true` was not migrated because the Vite bundler is selected. To keep uploading Worker source maps, enable `build.sourcemap` for the Worker's Vite environment. `cf deploy` uploads source maps included in the build output.
    https://developers.cloudflare.com/workers/observability/source-maps/
Updated 1 file(s).
// cloudflare.config.ts: the Wrangler config's entrypoint is kept
import { bindings, defineConfig } from "cf/config";

export default defineConfig({
	worker: {
		name: "rr-app",
		compatibilityDate: "2026-11-23",
		entrypoint: "./workers/app.ts",
		observability: {
			enabled: true,
		},
		env: {
			VALUE_FROM_CLOUDFLARE: bindings.text("Hello from Cloudflare"),
		},
	},
});

package.json gets cf, @cloudflare/vite-plugin goes from ^1.70.2 to ^2.0.0-rc.0, and "deploy" becomes "cf deploy".

$ npx cf build
├  Build
│  Delegating to react-router build
vite v8.4.0 building client environment for production...
✓ built in 104ms
vite v8.4.0 building ssr environment for production...
✓ built in 59ms
◆  Build complete

  • 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: the Cloudflare docs don't cover autoconfig's API or the removed migrateWranglerToCf export, and the changeset describes the change

@ask-bonk

ask-bonk Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/autoconfig@16993

@cloudflare/build-output-utils

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/build-output-utils@16993

@cloudflare/cli-shared-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/cli-shared-helpers@16993

@cloudflare/codemods

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/codemods@16993

@cloudflare/config

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/config@16993

@cloudflare/containers-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/containers-shared@16993

create-cloudflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/create-cloudflare@16993

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/deploy-helpers@16993

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/kv-asset-handler@16993

miniflare

npm i https://pkg.pr.new/cloudflare/workers-sdk/miniflare@16993

@cloudflare/pages-functions

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-functions@16993

@cloudflare/pages-shared

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/pages-shared@16993

@cloudflare/runtime-types

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/runtime-types@16993

@cloudflare/test-server

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/test-server@16993

@cloudflare/unenv-preset

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/unenv-preset@16993

@cloudflare/vite-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vite-plugin@16993

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/cloudflare/workers-sdk/@cloudflare/vitest-plugin@16993

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

npm i https://pkg.pr.new/cloudflare/workers-sdk/wrangler@16993

commit: 53d65b9

@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 8eeb174 to 38a98a5 Compare November 17, 2026 22:30
@changeset-bot

changeset-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 53d65b9

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

This PR includes changesets to release 7 packages
Name Type
@cloudflare/autoconfig Minor
@cloudflare/cli-shared-helpers Minor
@cloudflare/codemods Minor
@cloudflare/containers-shared Patch
@cloudflare/deploy-helpers Patch
@cloudflare/dev-helpers Patch
@cloudflare/remote-bindings 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

@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 38a98a5 to fd664f2 Compare November 17, 2026 22:41
@edmundhung
edmundhung changed the base branch from main to edmundhung/autoconfig-config-edits-warn November 17, 2026 22:42
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from fd664f2 to 637d3a4 Compare November 17, 2026 23:52
@edmundhung
edmundhung added this pull request to stack #16996 November 17, 2026 23:56
@edmundhung
edmundhung removed this pull request from stack #16996 November 18, 2026 10:35
@edmundhung
edmundhung added this pull request to stack #17007 November 18, 2026 10:35
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 637d3a4 to 03f4805 Compare November 18, 2026 11:24
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 03f4805 to 5452247 Compare November 18, 2026 11:59
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 5452247 to a4022cd Compare November 18, 2026 12:03
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from a4022cd to 3e87ed1 Compare November 18, 2026 12:21
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch 2 times, most recently from 0daffca to 701b126 Compare November 18, 2026 16:10
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 701b126 to 15d55fd Compare November 19, 2026 13:15
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch 2 times, most recently from 478d982 to caa1dbd Compare November 19, 2026 14:29
For the cf target, a root wrangler.jsonc, wrangler.toml or wrangler.json now makes the project one that setup migrates, and the Worker keeps the Wrangler config's name. Several configs are an error rather than a guess, and an existing cloudflare.config.ts takes precedence. The wrangler-to-cf codemod uses this instead of its own lookup.
@edmundhung
edmundhung force-pushed the autoconfig-project-setup-engine branch from 963e459 to eb40651 Compare November 26, 2026 00:48
…ework's

A Wrangler project is already set up for its framework, so migrating it keeps its entrypoint, compatibility flags and bindings. The framework's settings only fill in what the Wrangler config doesn't set.
A Wrangler Astro project already has the settings its migrated config needs, and without a Wrangler config `astro add` still writes cloudflare.config.ts.
Drops the React Router changeset and the converter's import note, which are too detailed for the release notes.
…ts own Worker config

runAutoConfig now always runs the detected framework's setup. Setup gets the project's existing Worker config, which for now is a Wrangler config that setup migrates, and decides what to do with it:
- Static and Next.js set up nothing (vinext init refuses Wrangler projects).
- React Router and TanStack Start keep the project's entrypoint.
- SolidStart replaces Nitro's output entry, which the Vite plugin no longer builds.
- Astro removes only the cloudflare.config.ts that `astro add` scaffolds.
The framework's entrypoint replaces the one it was shown; its other settings only fill in what the Wrangler config doesn't set.

The migration's bundler is the one the framework builds with, and otherwise the project's. A conflicting bundler option is an error. Frameworks that autoconfig can't set up leave a project with its own Worker config as it is. Pages projects are refused, including ones whose Wrangler config sets pages_build_output_dir.

installDependencies: false makes setup install nothing: the migration lists the packages it needs, and frameworks that need packages do nothing. enableTargetCliInstallation goes back to covering only the target CLI.

A given Wrangler config is migrated in its own project, which must be the config's directory. The Git check moves to the codemod, which words its own bypass hint. The converter no longer imports node:path. A framework that isn't installed reports that the project's dependencies need installing.
…their own Worker config

The rework removed run.ts's output directory check along with the Wrangler special cases, so a project with neither an output directory nor a Wrangler config reached the setup prompt instead of failing as on main.
…as written

Detection decides whether a project is a Pages one from its Wrangler config, which is the caller's parsed config or the one setup migrates, read as written.
Detection reads the Wrangler config that setup migrates and carries it on the details, so runAutoConfig and the migration use that copy instead of reading the file again. Detection types the config as RawConfig, which Wrangler's parsed config already satisfies.
…nfig

Detection no longer looks for the project above a given Wrangler config. The caller's projectPath is the project, and a Wrangler config outside its folder isn't migrated yet, since the migration keeps the config's relative paths. The codemod migrates an exact --config in that config's folder, as before.
No caller passes one yet: the codemod uses the folder of an exact --config as the project. Supporting that case properly, by writing at the project root and rebasing the config's paths, follows separately.
It now says which bundler isn't supported and to use the framework's default instead.
Detection now reads the Wrangler config in one call, getting undefined when the project has none. Also restores a blank line in getDetailsForAutoConfig that an earlier change dropped.
Detection keeps its output directory check for the Wrangler target only. For cf, runAutoConfig reports it, and only for a project without a Worker config of its own: a project with no framework, Wrangler config or index.html now hears that nothing could be found to deploy, and how to fix that.
Detection keeps main's check, now for the Wrangler target only, and runAutoConfig keeps main's assert for Wrangler. For cf it reports a missing output directory itself, inline, for projects without a Worker config of their own.
outputDir is passed as string | undefined rather than being optional, and the new options don't get JSDoc that the existing ones don't have.
A framework's setup returns null when it does nothing for a project. The no-op framework refuses Pages and, for projects without a Worker config of their own, the frameworks autoconfig can't set up; the frameworks cf can't set up yet refuse through validateFrameworkTargetSupport, unchanged from main. runAutoConfig no longer checks support itself, and no framework version is checked for a framework the target can't set up.
…frameworks

They passed hand-made framework objects to runAutoConfig, which no longer refuses by id: the no-op framework that detection creates refuses them now, and autoconfig's own tests cover both messages.
runAutoConfig only migrates projects without a cloudflare.config.ts, so any file the migration finds was written by this run's framework setup, as `astro add` does. The migration no longer refuses existing files, and Astro's setup no longer removes the config it scaffolds.
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.

1 participant