Skip to content

[autoconfig] Keep existing files when setting up a migrated project - #17238

Merged
edmundhung merged 21 commits into
mainfrom
autoconfig-setup-after-migration
Nov 30, 2026
Merged

edmundhung merged 21 commits into
mainfrom
autoconfig-setup-after-migration

Conversation

@edmundhung

@edmundhung edmundhung commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Part of RM-31810. Stacked on #17222.

Gets setup ready to run on a project whose Wrangler config was just migrated to cloudflare.config.ts:

  • On cf, runAutoConfig keeps an existing cloudflare.config.ts instead of overwriting it, and its summary reports the build tool the framework set up. Astro now reports vite, since its adapter builds with the Cloudflare Vite plugin.
  • getDetailsForAutoConfig reports the project's Wrangler config as wranglerConfig: the one the caller passes, or else the one in the project folder. Setup passes it to the framework. When it names a Worker entry, React Router leaves workers/app.ts, app/entry.server.tsx and isbot alone.
  • cf now detects a Pages project from its Wrangler config's pages_build_output_dir, so setup stops on it instead of setting it up as a new Worker.

  • 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, and the React Router change is a fix

Devin Review

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 917feaa

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

This PR includes changesets to release 2 packages
Name Type
@cloudflare/autoconfig Minor
@cloudflare/codemods 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

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Keeps migrated config and React Router files while reporting Astro's Vite build tool.

  1. P1: Submitted two inline suggestion comments for projectPath-scoped React Router file preservation.

github run

devin-ai-integration[bot]

This comment was marked as resolved.

@edmundhung
edmundhung added this pull request to stack #17239 November 27, 2026 16:15
@pkg-pr-new

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

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@17238

@cloudflare/cli-shared-helpers

npm i https://pkg.pr.new/@cloudflare/cli-shared-helpers@17238

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@17238

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@17238

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@17238

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@17238

@cloudflare/pages-shared

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

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@17238

@cloudflare/test-server

npm i https://pkg.pr.new/@cloudflare/test-server@17238

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@17238

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 917feaa

@edmundhung
edmundhung force-pushed the autoconfig-setup-after-migration branch 2 times, most recently from fba6bb9 to ba456dc Compare November 27, 2026 16:52
devin-ai-integration[bot]

This comment was marked as resolved.

@edmundhung
edmundhung force-pushed the autoconfig-setup-after-migration branch from 0d33269 to 1202002 Compare November 27, 2026 17:10
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 27, 2026
Bumps the workers-sdk previews to cloudflare/workers-sdk#17238 at 284d481, which
reads a named Wrangler config itself.
edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 27, 2026
Bumps the workers-sdk previews to cloudflare/workers-sdk#17238 at 284d481, which
reads a named Wrangler config itself.
devin-ai-integration[bot]

This comment was marked as resolved.

edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 27, 2026
Bumps the workers-sdk previews to cloudflare/workers-sdk#17238 at 098e110,
which only asks about a Wrangler assets directory that Vite won't deploy.
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 27, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@edmundhung
edmundhung marked this pull request as ready for review November 27, 2026 22:23
@workers-devprod
workers-devprod requested review from a team and removed request for a team November 27, 2026 22:23
The summary now only lists the Worker configuration setup writes, and the
changeset is split into the fixes and the new buildTool field.
Check for an existing cloudflare.config.ts when saving it, instead of
adjusting the setup summary.
…ngler config

Detection now reports the project's own Wrangler config, and setup passes it to
the framework. React Router skips workers/app.ts, app/entry.server.tsx and the
isbot install when it's set, instead of keeping an existing workers/app.ts.
…etup

React Router skips its own Worker entry only when the Wrangler config names
one, and points the generated config at it. Detection also reports the
Wrangler config for projects already configured for Wrangler.
getDetailsForAutoConfig takes the Wrangler config the caller passes, or reads
the one in the project folder, and reports it as wranglerConfig. Setup passes
it to the framework, so React Router reads main from it instead of a path.
Use workers-utils' isPagesConfig, which checks that the field is set, as
Wrangler does, rather than that it's non-empty.
Setup keeps the cloudflare.config.ts that the migration writes first, so
pointing the result at the Wrangler config's main had no effect.
Both Pages checks in detection now agree on an empty pages_build_output_dir.
getDetailsForAutoConfig takes a wranglerConfigPath. Without a wranglerConfig,
detection reads that file, or else the one in the project folder, so a caller
like cf migrate no longer has to read the config itself.
…ploy

Vite deploys its build output and public folder, so a Wrangler assets
directory there, or inside the build output folder that detection reports,
needs no TODO. migrateBundler takes that folder as outputDir.
A folder inside the build output would be deployed under a URL prefix, so only
the build output folder itself needs no TODO.
The Cloudflare Vite plugin writes client assets to the client folder inside the
build output by default, so a Wrangler assets directory there keeps its URLs.
Detection reports each framework's default folder rather than reading the
project's config, so the docs for outputDir and the assets check say so.
Only Vite's default public folder and the build output folder that detection
reports skip the TODO, as agreed.
@edmundhung
edmundhung force-pushed the autoconfig-setup-after-migration branch from 8350b3d to 7c49a9f Compare November 30, 2026 14:20

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of 917feaae.

This review, of 7c49a9fc

💬 Approved with comments — One WARNING carries over from the last review: React Router setup can write a cloudflare.config.ts whose entrypoint is ./workers/app.ts, a file it skipped creating. The changes since that review (the assets TODO check, outputDir, resolving wranglerConfigPath, and the guard that keeps an existing config) need no fixes.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #17238.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] React Router skips writing `workers/app.ts` when the Wrangler config sets `main`, but still returns `entrypoint: "./workers/app.ts"`, so setup can write a `cloudflare.config.ts` pointing at a missing file. Kept: @edmundhung [author] deferred the fix, and the returned entrypoint at lines 529-532 is unchanged.
- **File:** packages/autoconfig/src/frameworks/react-router.ts:499

📋 Code Quality: ⚠️ 1 warning

One earlier WARNING is still open: React Router returns an entrypoint for a file it skipped writing.

Recommendation: 📝 Minor Comments

  • [WARNING] React Router skips writing workers/app.ts when the Wrangler config sets main, but still returns entrypoint: "./workers/app.ts", so setup can write a cloudflare.config.ts pointing at a missing file. Kept: @​edmundhung [author] deferred the fix, and the returned entrypoint at lines 529-532 is unchanged. (packages/autoconfig/src/frameworks/react-router.ts:499)
View full review

React Router returns an entrypoint it no longer writes (packages/autoconfig/src/frameworks/react-router.ts:498-533)

  • When wranglerConfig?.main is set, configure skips creating workers/app.ts and app/entry.server.tsx, and skips installing isbot.
  • It still always returns workerConfig: { entrypoint: "./workers/app.ts" } (lines 529-532).
  • Detection now reads any wrangler.json, wrangler.jsonc or wrangler.toml in the project folder. That means main can reach configure in a project that has no cloudflare.config.ts yet.
  • In that case saveCloudflareConfig finds no existing file and writes a new one that points at a file that doesn't exist.

The author replied that a project with a Wrangler config is treated as already set up and that this will be improved later. That explains why the files are skipped, but the returned entrypoint is unchanged, so this stays at WARNING. Possible fixes: return entrypoint: wranglerConfig.main when main is set, or leave the entrypoint out in that case.

The other changes since the last review need no fixes: the isDeployedByVite assets check, outputDir in migrateBundler, resolving wranglerConfigPath in detection, and the existsSync guard in saveCloudflareConfig.


✅ All other checks passed

🚀 Release: ✅ LGTM

The changesets cover the detection, setup and migration changes. The React Router entrypoint concern is tracked in the Code Quality section. The patch bump on .changeset/vite-assets-directory-follow-up.md was raised before and the author acknowledged it, so it is not repeated.


🔒 Security: ✅ LGTM

The new inputs (the Wrangler config's main and assets.directory, plus the outputDir and wranglerConfigPath options) come from the project's own files or from the caller. They only reach path comparisons and message text, never a shell command. saveCloudflareConfig now leaves an existing cloudflare.config.ts in place instead of overwriting it.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

Each detection run adds one small config read and a few existsSync checks, and none of them are on a hot path.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 7c49a9fc

@clanky-the-clanker clanky-the-clanker Bot left a comment

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.

💬 Approved with comments — One WARNING carries over: when the Wrangler config sets main, React Router setup still returns ./workers/app.ts as the entrypoint even though it skipped writing that file. The changes since the last review need no fixes.

Findings: 1 warning

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.

🔧 Fix with your agent

Paste the following into your coding agent to investigate and fix these issues.

Fix the following code review issues found in pull request #17238.

Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
  for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

## WARNING (1)

### [Code Quality] React Router skips writing `workers/app.ts` when the Wrangler config sets `main`, but still returns `entrypoint: "./workers/app.ts"`. Setup can then write a `cloudflare.config.ts` that points at a missing file. Kept: @edmundhung [author] deferred the fix, and the returned entrypoint at lines 528-533 is unchanged.
- **File:** packages/autoconfig/src/frameworks/react-router.ts:499

📋 Code Quality: ⚠️ 1 warning

One WARNING carries over: React Router returns an entrypoint it skipped writing.

Recommendation: 📝 Minor Comments

  • [WARNING] React Router skips writing workers/app.ts when the Wrangler config sets main, but still returns entrypoint: "./workers/app.ts". Setup can then write a cloudflare.config.ts that points at a missing file. Kept: @​edmundhung [author] deferred the fix, and the returned entrypoint at lines 528-533 is unchanged. (packages/autoconfig/src/frameworks/react-router.ts:499)
View full review

React Router returns an entrypoint it did not write (packages/autoconfig/src/frameworks/react-router.ts:498-533)

  • When wranglerConfig?.main is set, configure skips three things: creating workers/app.ts, writing app/entry.server.tsx and installing isbot.
  • It still always returns workerConfig: { entrypoint: "./workers/app.ts" } (lines 530-532).
  • Detection now reads a wrangler.json, wrangler.jsonc or wrangler.toml from the project folder, so main can be set in a project that has no cloudflare.config.ts yet.
  • In that case saveCloudflareConfig finds no existing file and writes a new one whose entrypoint does not exist.

Kept at WARNING: @​edmundhung [author] said a project with a Wrangler config is treated as already set up and that this will be improved later. That explains why the files are skipped. It does not explain returning a path that was never written, and lines 528-533 are unchanged at this commit.

Possible fixes: return entrypoint: wranglerConfig.main when main is set, or leave the entrypoint out in that case.

The changes since the last review need no fixes: the isDeployedByVite assets check, passing outputDir through migrateBundler and convertWranglerBuild, and the existsSync guard in saveCloudflareConfig.


✅ All other checks passed

🚀 Release: ✅ LGTM

The changesets cover the detection, setup, Pages detection and assets-directory changes. The patch bump on .changeset/vite-assets-directory-follow-up.md was raised before and the author acknowledged it, so it is not repeated here.


🔒 Security: ✅ LGTM

The new inputs come from the project's own files or from the caller: the Wrangler config, the wranglerConfigPath option and outputDir. They are used only in path comparisons, file reads and message text, and none of them reaches a shell command. Setup now leaves an existing cloudflare.config.ts in place instead of overwriting it.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md issues found.


⚡ Performance: ✅ LGTM

Each detection run adds one small config read and a few existence checks. None of them runs on a hot path.


📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 917feaae

@edmundhung
edmundhung merged commit 8ffd9b3 into main Nov 30, 2026
89 checks passed
@edmundhung
edmundhung deleted the autoconfig-setup-after-migration branch November 30, 2026 15:08
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Nov 30, 2026
edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 30, 2026
Bumps the workers-sdk previews to cloudflare/workers-sdk#17238 at 284d481, which
reads a named Wrangler config itself.
edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 30, 2026
Bumps the workers-sdk previews to cloudflare/workers-sdk#17238 at 098e110,
which only asks about a Wrangler assets directory that Vite won't deploy.
edmundhung added a commit to cloudflare/cf that referenced this pull request Nov 30, 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.

3 participants