Skip to content

Commit 9988cc9

Browse files
authored
Support Nuxt in autoconfig (#11477)
* Support Nuxt in autoconfig * Lint * Lint * Update changeset to match others * Snap
1 parent 94c67e8 commit 9988cc9

File tree

7 files changed

+130
-9
lines changed

7 files changed

+130
-9
lines changed

‎.changeset/breezy-apes-lose.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": minor
3+
---
4+
5+
Support Nuxt in autoconfig `--experimental` flow

‎.changeset/cruel-chairs-train.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Support Nuxt in autoconfig

‎packages/create-cloudflare/e2e/tests/cli/cli.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ describe("Create Cloudflare CLI", () => {
524524

525525
describe("help text", () => {
526526
test("--help", async ({ logStream }) => {
527-
if (!isExperimental) {
527+
if (isExperimental) {
528528
const { output } = await runC3(
529529
["--help", "--experimental"],
530530
[],
@@ -555,7 +555,7 @@ describe("Create Cloudflare CLI", () => {
555555
npm create cloudflare -- --framework next -- --ts
556556
pnpm create cloudflare --framework next -- --ts
557557
Allowed Values:
558-
gatsby, svelte, docusaurus, astro, tanstack-start, angular, solid, qwik, vue, react, react-router
558+
angular, astro, docusaurus, gatsby, nuxt, qwik, react, react-router, solid, svelte, tanstack-start, vue
559559
--platform=<value>
560560
Whether the application should be deployed to Pages or Workers. This is only applicable for Frameworks templates that support both Pages and Workers.
561561
Allowed Values:

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,30 @@ function getExperimentalFrameworkTestConfig(
786786
flags: ["--style", "sass"],
787787
verifyTypes: false,
788788
},
789+
{
790+
name: "nuxt:workers",
791+
promptHandlers: [
792+
{
793+
matcher: /Would you like to install any of the official modules\?/,
794+
input: [keys.enter],
795+
},
796+
],
797+
argv: ["--platform", "workers"],
798+
testCommitMessage: true,
799+
timeout: LONG_TIMEOUT,
800+
unsupportedOSs: ["win32"],
801+
verifyDeploy: {
802+
route: "/",
803+
expectedText: "Welcome to Nuxt!",
804+
},
805+
verifyPreview: {
806+
previewArgs: ["--inspector-port=0"],
807+
route: "/test",
808+
expectedText: "C3_TEST",
809+
},
810+
nodeCompat: false,
811+
verifyTypes: false,
812+
},
789813
{
790814
name: "solid",
791815
promptHandlers: [

‎packages/create-cloudflare/src/templates.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,18 @@ export type TemplateMap = Record<
237237
export function getFrameworkMap({ experimental = false }): TemplateMap {
238238
if (experimental) {
239239
return {
240-
gatsby: gatsbyTemplate,
241-
svelte: svelteTemplate,
242-
docusaurus: docusaurusTemplate,
243-
astro: astroTemplate,
244-
"tanstack-start": tanStackStartTemplate,
245240
angular: angularTemplate,
246-
solid: solidTemplate,
241+
astro: astroTemplate,
242+
docusaurus: docusaurusTemplate,
243+
gatsby: gatsbyTemplate,
244+
nuxt: nuxtTemplate,
247245
qwik: qwikTemplate,
248-
vue: vueTemplate,
249246
react: reactTemplate,
250247
"react-router": reactRouterTemplate,
248+
solid: solidTemplate,
249+
svelte: svelteTemplate,
250+
"tanstack-start": tanStackStartTemplate,
251+
vue: vueTemplate,
251252
};
252253
} else {
253254
return {

‎packages/wrangler/src/autoconfig/frameworks/get-framework.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Angular } from "./angular";
22
import { Astro } from "./astro";
3+
import { Nuxt } from "./nuxt";
34
import { Qwik } from "./qwik";
45
import { ReactRouter } from "./react-router";
56
import { SolidStart } from "./solid-start";
@@ -23,6 +24,8 @@ export function getFramework(detectedFramework?: {
2324
return new ReactRouter(detectedFramework.name);
2425
case "angular":
2526
return new Angular(detectedFramework.name);
27+
case "nuxt":
28+
return new Nuxt(detectedFramework.name);
2629
case "solid-start":
2730
return new SolidStart(detectedFramework.name);
2831
case "qwik":
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import path from "node:path";
2+
import { brandColor, dim } from "@cloudflare/cli/colors";
3+
import * as recast from "recast";
4+
import { mergeObjectProperties, transformFile } from "../c3-vendor/codemod";
5+
import { installPackages } from "../c3-vendor/packages";
6+
import { Framework } from ".";
7+
import type { ConfigurationOptions, ConfigurationResults } from ".";
8+
9+
const updateNuxtConfig = (projectPath: string) => {
10+
const configFile = path.join(projectPath, "nuxt.config.ts");
11+
12+
const b = recast.types.builders;
13+
14+
const presetDef = b.objectProperty(
15+
b.identifier("nitro"),
16+
b.objectExpression([
17+
b.objectProperty(
18+
b.identifier("preset"),
19+
b.stringLiteral("cloudflare_module")
20+
),
21+
b.objectProperty(
22+
b.identifier("cloudflare"),
23+
b.objectExpression([
24+
b.objectProperty(
25+
b.identifier("deployConfig"),
26+
b.booleanLiteral(true)
27+
),
28+
b.objectProperty(b.identifier("nodeCompat"), b.booleanLiteral(true)),
29+
])
30+
),
31+
])
32+
);
33+
34+
const moduleDef = b.objectProperty(
35+
b.identifier("modules"),
36+
b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")])
37+
);
38+
39+
transformFile(configFile, {
40+
visitCallExpression: function (n) {
41+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
42+
if (callee.name === "defineNuxtConfig") {
43+
mergeObjectProperties(
44+
n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
45+
[presetDef, moduleDef]
46+
);
47+
}
48+
49+
return this.traverse(n);
50+
},
51+
});
52+
};
53+
54+
export class Nuxt extends Framework {
55+
async configure({
56+
dryRun,
57+
projectPath,
58+
}: ConfigurationOptions): Promise<ConfigurationResults> {
59+
if (!dryRun) {
60+
await installPackages(["nitro-cloudflare-dev"], {
61+
dev: true,
62+
startText: "Installing the Cloudflare dev module",
63+
doneText: `${brandColor(`installed`)} ${dim("nitro-cloudflare-dev")}`,
64+
});
65+
updateNuxtConfig(projectPath);
66+
}
67+
68+
return {
69+
wranglerConfig: {
70+
main: "./.output/server/index.mjs",
71+
assets: {
72+
binding: "ASSETS",
73+
directory: "./.output/public/",
74+
},
75+
observability: {
76+
enabled: true,
77+
},
78+
},
79+
};
80+
}
81+
82+
configurationDescription = "Configuring project for Nuxt";
83+
}

0 commit comments

Comments
 (0)