Skip to content

[create-cloudflare] Preserve existing Nuxt modules when adding Cloudflare configuration#14534

Merged
petebacondarwin merged 5 commits into
mainfrom
pbd/nuxt-preserve-modules
Jul 17, 2026
Merged

[create-cloudflare] Preserve existing Nuxt modules when adding Cloudflare configuration#14534
petebacondarwin merged 5 commits into
mainfrom
pbd/nuxt-preserve-modules

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #14513

C3 and @cloudflare/autoconfig overwrote a Nuxt project's existing modules array in nuxt.config.ts when adding nitro-cloudflare-dev. For starters that ship a modules array — such as nuxt/starter@ui, which registers @nuxt/ui and @nuxt/eslint — this dropped those modules, so @import "@nuxt/ui" in assets/css/main.css no longer resolved and the build failed.

The root cause is in the shared @cloudflare/codemod mergeObjectProperties helper: it deep-merged object properties but overwrote array properties. It now concatenates new elements onto the existing array, de-duplicating string entries, so existing modules are preserved and the Cloudflare module is appended.

What changed

  • @cloudflare/codemod: mergeObjectProperties now merges (concatenates + de-dupes) array properties instead of overwriting them, with unit tests covering concat, de-dupe, and mixed array+object merges.
  • create-cloudflare and @cloudflare/autoconfig both bundle the codemod, so both pick up the fix (a patch changeset is added for each).
  • The Nuxt framework e2e tests now use the ui template (which ships a modules array) so this regression is covered — the previous minimal template had no modules array and could not reproduce the bug.

Before / after

C3's exact transform run against the real ui starter nuxt.config.ts:

  • Before: modules: ["nitro-cloudflare-dev"]@nuxt/ui and @nuxt/eslint dropped
  • After: modules: ['@nuxt/ui', '@nuxt/eslint', "nitro-cloudflare-dev"]

  • 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 fixes incorrect scaffolding/configuration behaviour; there is no user-facing API or documented behaviour change.

Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eba23b6

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 Patch
create-cloudflare 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-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Jul 3, 2026
@workers-devprod
workers-devprod requested review from a team and james-elicx and removed request for a team July 3, 2026 11:33
@workers-devprod

workers-devprod commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/autoconfig-nuxt-preserve-modules.md: [@cloudflare/wrangler]
  • .changeset/create-cloudflare-nuxt-preserve-modules.md: [@cloudflare/wrangler]
  • packages/codemod/src/index.ts: [@cloudflare/wrangler]
  • packages/codemod/tests/index.test.ts: [@cloudflare/wrangler]
  • packages/create-cloudflare/e2e/tests/frameworks/frameworks.test.ts: [@cloudflare/wrangler]
  • packages/create-cloudflare/e2e/tests/frameworks/test-config.ts: [@cloudflare/wrangler]

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@ask-bonk

ask-bonk Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

The tests are well-structured and cover the main cases. Let me check the changeset descriptions against the repo rules — the changeset content mentions internal package @cloudflare/codemod which the AGENTS.md says to reference the public-facing package. Both changesets correctly reference the user-facing behavior. That's fine.

Let me verify one potential concern — the changeset bot warning mentioned in the PR comment referenced @cloudflare/codemod in its "add another changeset" link, but the actual changesets target the right packages. Let me confirm the changeset files are valid frontmatter.

The changesets look correct. Now let me assess the overall correctness. The core logic is sound. Let me consider one real edge case: de-duplication uses existingStringValues but is populated only from string literals in the existing array. If the new array itself contains duplicate strings not in existing, the .add() prevents pushing dupes from new — good. Logic is correct.

One remaining concern worth noting: mergeArrayElements de-dups only StringLiteral. In Nuxt configs, modules can also be arrays like ['@nuxtjs/tailwindcss', { ... }] or bare identifiers/imports. These won't be de-duped, but since Cloudflare only adds a string, there's no duplication risk in practice. This is a minor robustness note, not an actionable bug.

Let me double check there isn't a subtle issue with the false return in mergeObjectProperties (line 91) — that's pre-existing behavior, not introduced by this PR.

The change is focused, correct, well-tested, and the changesets and e2e updates are appropriate. The logic properly:

  • Merges arrays by concatenation instead of overwriting
  • De-duplicates string entries
  • Handles mixed array+object merges
  • Preserves the deep-merge for objects

I found no actionable logic bugs, security issues, backward-compat violations, or incorrect API behavior. The de-dup-only-for-strings limitation is acceptable given actual usage and not worth flagging as it would be a nitpick on hypothetical scenarios.

LGTM

github run

@petebacondarwin petebacondarwin added the run-c3-frameworks-tests Run all the C3 frameworks tests on this PR label Jul 3, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/config

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: eba23b6

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 potential issue.

Open in Devin Review

Comment thread packages/create-cloudflare/e2e/tests/frameworks/test-config.ts

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 new potential issue.

Open in Devin Review

Comment thread packages/create-cloudflare/e2e/tests/frameworks/test-config.ts
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@petebacondarwin
petebacondarwin requested review from dario-piotrowicz and removed request for james-elicx July 16, 2026 16:56

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me 🙂

Comment thread packages/codemod/src/index.ts Outdated
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jul 17, 2026
…dflare configuration

The shared codemod's `mergeObjectProperties` overwrote array properties instead of
merging them. Scaffolding (C3) or configuring (`@cloudflare/autoconfig`) a Nuxt app
whose `nuxt.config.ts` already declared a `modules` array (e.g. the `ui` starter,
which registers `@nuxt/ui` and `@nuxt/eslint`) therefore dropped those modules when
adding `nitro-cloudflare-dev`, breaking the build.

Array properties are now concatenated onto the existing array, de-duplicating string
entries, so existing modules are preserved and the Cloudflare module is appended. The
Nuxt e2e tests now use the `ui` template (which ships a `modules` array) so this
regression is covered.
The nuxi ui template pins packageManager pnpm@11.9.0. Under pnpm 10 the cross-version self-provisioning recurses and fails with ENAMETOOLONG (nested .pnpm/.tools/pnpm/11.9.0_tmp_* paths), so restrict the Nuxt framework e2e tests to pnpm 11+.
… coverage

The Nuxt tests use the `ui` template (to exercise the modules-merge fix),
gated to pnpm 11+ because `ui` pins packageManager pnpm@11.9.0 and pnpm 10
self-provisions into an ENAMETOOLONG recursion. That left Nuxt with no
pnpm 10 coverage.

Add `nuxt:pages:minimal` / `nuxt:workers:minimal` variants (default
template, gated to pnpm <11) so the pre-pnpm-11 install path stays tested,
and disambiguate duplicate vitest titles via a third `:`-segment variant
label. npm is skipped on the minimal variants since the ui variant already
covers npm.
- Add `unsupportedPms: ["yarn"]` to the experimental nuxt:workers (ui)
  entry to match its non-experimental counterpart (nitro/youch needs
  Node 20+; yarn runs on Node 18).
- Add `unsupportedPms: ["yarn", "npm"]` to the experimental
  nuxt:workers:minimal entry for consistency with the non-experimental
  minimal variants.
- Broaden the colon-form test filter from exact-match to a
  "name:platform" prefix match so filtering by e.g. `nuxt:pages` also
  selects variant tests like `nuxt:pages:minimal`.
@petebacondarwin
petebacondarwin force-pushed the pbd/nuxt-preserve-modules branch from d46a60e to db2f5f2 Compare July 17, 2026 13:07
@petebacondarwin
petebacondarwin merged commit a330170 into main Jul 17, 2026
60 checks passed
@petebacondarwin
petebacondarwin deleted the pbd/nuxt-preserve-modules branch July 17, 2026 16:30
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-c3-frameworks-tests Run all the C3 frameworks tests on this PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[C3] Nuxt UI starter modules are overwritten when configuring nitro-cloudflare-dev

3 participants