feat(nx-cloudflare): add configuration generator for existing apps (#135)#193
Open
NachoVazquez wants to merge 7 commits into
Open
feat(nx-cloudflare): add configuration generator for existing apps (#135)#193NachoVazquez wants to merge 7 commits into
NachoVazquez wants to merge 7 commits into
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
nx-cloudflare | c6c53ac | Commit Preview URL Branch Preview URL |
Jun 28 2026, 08:36 PM |
|
View your CI Pipeline Execution ↗ for commit c6c53ac
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit a1b16e7
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gonx-docs | c6c53ac | Commit Preview URL Branch Preview URL |
Jun 28 2026, 08:36 PM |
a1b16e7 to
581cc99
Compare
581cc99 to
c447024
Compare
c447024 to
c6c53ac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
There was no first-class way to put an existing Nx app on Cloudflare —
create-cloudflare(C3) only scaffolds brand-new apps andbindingonly edits a Worker that already has awrangler.jsonc. This adds aconfigurationgenerator that authors awrangler.jsonc, installswrangler+@cloudflare/workers-types, and registers the inference plugin onto a project you already have, so the serve/deploy/typegen/version/tail targets light up.Files to review (20):
packages/nx-cloudflare/src/generators/configuration/generator.ts(start here)packages/nx-cloudflare/src/generators/configuration/schema.jsonproject,template,name,main,assetsDir,compatibilityDate,nodejsCompat).packages/nx-cloudflare/src/generators/configuration/files/{worker,spa,fullstack}/wrangler.jsonc.templatepackages/nx-cloudflare/src/utils/{project,gitignore,wrangler-config}.tsresolveProjectRootOrThrow,ensureGitignored+WORKER_CONFIGURATION_DTS,wranglerSchemaPath) now reused bybindingandcreate-cloudflare.packages/nx-cloudflare/src/generators/{binding,create-cloudflare}/generator.tspackages/nx-cloudflare/src/generators/configuration/generator.spec.ts(new)nodejsCompatfor all three templates, entry-missing warning, both guards.packages/nx-cloudflare/generators.json/src/index.tsconfig) + programmatic export.packages/gonx/generators.jsoninitgenerator (see Reviewer notes).docs/{nx-cloudflare-docs,gonx-docs}/...Why
Most frameworks (Astro, React Router, SvelteKit, Nuxt, Angular) deploy to Workers via their own adapters and already ship Nx generators. The plugin's durable value is the Cloudflare deploy/serve/types layer — the
createNodesinference plugin keyed offwrangler.{toml,jsonc,json}— not re-scaffolding frameworks. This generator wires exactly that layer onto an app that already exists, and stays deliberately framework-agnostic: you bring your framework's Cloudflare adapter, it brings the config and targets.Closes #135 (part of the #115 modernization epic).
How
The generator resolves the target project (Tree first, project-graph fallback so inference-only Workers resolve — the shared
resolveProjectRootOrThrow), then:wrangler.{toml,jsonc,json}and throws loudly rather than clobbering hand-tuned config.wrangler+@cloudflare/workers-typesand registers@naxodev/nx-cloudflare/plugininnx.json— directly, not via theinitgenerator, which would also forcevitest+@cloudflare/vitest-pool-workersonto an app that owns its own test setup.wrangler.jsoncfrom one of three templates, with the$schemawritten as anoffsetFromRoot-relative path so editors validate it. The default Workernameis sanitized to Cloudflare's lowercase-alphanumeric-plus-hyphens rule, so a scoped/cased Nx project name (@org/My_App→org-my-app) still yields a valid config.worker-configuration.d.ts(thetypegenoutput).mainentry doesn't exist, or the project root has noproject.json/package.jsonfor the inference plugin to attach targets to.worker(default)mainpoints at your entry, no assetsspaassets.directory+not_found_handling: "single-page-application", nomainfullstackmainandassetswith anASSETSbindingReviewer notes
mainjust points at whatever the app already builds. This matches nx-cloudflare: add an "add Cloudflare to an existing app" generator #135's premise and keeps the generator from rotting against per-framework adapter churn.resolveProjectRootOrThrow,ensureGitignored/WORKER_CONFIGURATION_DTS, andwranglerSchemaPathare extracted tosrc/utilsand now consumed bybindingandcreate-cloudflaretoo, replacing the previously duplicated blocks.initgenerator; this only removes"hidden": trueand sharpens the description sonx g/Nx Console surface it. It's intentionally minor and introduces no new gonx behavior — hence the singlefeat(nx-cloudflare)scope rather than a separate gonx release. Flag if you'd prefer it split out for its own changelog entry.assetsDirdefault is a starting point, not a guarantee. wrangler resolves it relative to the project root; Nx's default build output lives at the workspace root, so the schema/doc call out overriding it (e.g.../../dist/apps/web) unless your framework builds into the project.configuration(aliasconfig) mirrors@nx/vite:configuration— theconfigurationform is used when the plugin is the tool being configured;setup-*is for when the noun differs.!change, nothing for existing consumers to migrate.Tests
14
bun:testcases ingenerator.spec.tscovering all three templates, Worker-name sanitization, thenodejsCompatflag on each template (proving the JSONC stays valid with the conditional comma), plugin + dependency wiring, gitignore presence and idempotency, the missing-entry warning, and both the already-configured and unknown-project guards. Run withbunx nx test nx-cloudflare. Lint, build, and both docs-site builds pass.Links