Skip to content

Commit abd3263

Browse files
Support Next.js in autoconfig
1 parent 1d685cb commit abd3263

File tree

18 files changed

+347
-51
lines changed

18 files changed

+347
-51
lines changed

.changeset/fair-words-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
Support Next.js in `--experimental` mode

.changeset/yellow-taxes-spend.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 Next.js projects in autoconfig

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
558+
gatsby, svelte, docusaurus, astro, tanstack-start, next
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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,25 @@ function getExperimentalFrameworkTestConfig(
745745
nodeCompat: true,
746746
verifyTypes: false,
747747
},
748+
{
749+
name: "next",
750+
argv: ["--platform", "workers"],
751+
flags: ["--yes"],
752+
testCommitMessage: true,
753+
unsupportedOSs: ["win32"],
754+
unsupportedPms: ["npm", "yarn"],
755+
verifyDeploy: {
756+
route: "/",
757+
expectedText: "Generated by create next app",
758+
},
759+
verifyPreview: {
760+
previewArgs: ["--inspector-port=0"],
761+
route: "/",
762+
expectedText: "Generated by create next app",
763+
},
764+
nodeCompat: true,
765+
verifyTypes: false,
766+
},
748767
];
749768
}
750769

packages/create-cloudflare/src/templates.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import workflowsTemplate from "templates/hello-world-workflows/c3";
3232
import helloWorldWorkerTemplate from "templates/hello-world/c3";
3333
import honoTemplate from "templates/hono/c3";
3434
import nextTemplate from "templates/next/c3";
35+
import nextExperimentalTemplate from "templates/next/experimental_c3";
3536
import nuxtTemplate from "templates/nuxt/c3";
3637
import openapiTemplate from "templates/openapi/c3";
3738
import preExistingTemplate from "templates/pre-existing/c3";
@@ -241,6 +242,7 @@ export function getFrameworkMap({ experimental = false }): TemplateMap {
241242
docusaurus: docusaurusTemplate,
242243
astro: astroTemplate,
243244
"tanstack-start": tanStackStartTemplate,
245+
next: nextExperimentalTemplate,
244246
};
245247
} else {
246248
return {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { runFrameworkGenerator } from "frameworks/index";
2+
import type { TemplateConfig } from "../../src/templates";
3+
import type { C3Context } from "types";
4+
5+
const generate = async (ctx: C3Context) => {
6+
await runFrameworkGenerator(ctx, [
7+
ctx.project.name,
8+
"--skip-install",
9+
]);
10+
};
11+
12+
const envInterfaceName = "CloudflareEnv";
13+
const typesPath = "./cloudflare-env.d.ts";
14+
export default {
15+
configVersion: 1,
16+
id: "next",
17+
frameworkCli: "create-next-app",
18+
platform: "workers",
19+
displayName: "Next.js",
20+
generate,
21+
devScript: "dev",
22+
previewScript: "preview",
23+
deployScript: "deploy",
24+
typesPath,
25+
envInterfaceName,
26+
} as TemplateConfig;

packages/wrangler/src/__tests__/autoconfig/details/confirm-auto-config-details.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("autoconfig details - confirmAutoConfigDetails()", () => {
103103
buildCommand: "astro build",
104104
framework: {
105105
configured: false,
106-
configure: () => ({}),
106+
configure: () => ({ wranglerConfig: {} }),
107107
name: "astro",
108108
},
109109
outputDir: "<OUTPUT_DIR>",

packages/wrangler/src/__tests__/autoconfig/details/display-auto-config-details.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ describe("autoconfig details - displayAutoConfigDetails()", () => {
3535
configured: false,
3636
projectPath: process.cwd(),
3737
workerName: "my-astro-app",
38-
framework: { name: "Astro", configured: false, configure: () => ({}) },
38+
framework: {
39+
name: "Astro",
40+
configured: false,
41+
configure: () => ({ wranglerConfig: {} }),
42+
},
3943
buildCommand: "astro build",
4044
outputDir: "dist",
4145
});

packages/wrangler/src/__tests__/autoconfig/run.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ describe("autoconfig (deploy)", () => {
150150
});
151151
await writeFile(".gitignore", "");
152152
const configureSpy = vi.fn(async ({ outputDir }) => ({
153-
assets: { directory: outputDir },
153+
wranglerConfig: {
154+
assets: { directory: outputDir },
155+
},
154156
}));
155157
await run.runAutoConfig({
156158
projectPath: process.cwd(),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* This is used to provide telemetry with a sanitised error
3+
* message that could not have any user-identifying information.
4+
* Set to `true` to duplicate `message`.
5+
* */
6+
type TelemetryMessage = {
7+
telemetryMessage?: string | true;
8+
};
9+
10+
/**
11+
* Base class for errors where something in a autoconfig frameworks' configuration goes
12+
* something wrong. These are not reported to Sentry.
13+
*/
14+
export class AutoConfigFrameworkConfigurationError extends Error {
15+
telemetryMessage: string | undefined;
16+
constructor(
17+
message?: string | undefined,
18+
options?:
19+
| ({
20+
cause?: unknown;
21+
} & TelemetryMessage)
22+
| undefined
23+
) {
24+
super(message, options);
25+
// Restore prototype chain:
26+
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
27+
Object.setPrototypeOf(this, new.target.prototype);
28+
this.telemetryMessage =
29+
options?.telemetryMessage === true ? message : options?.telemetryMessage;
30+
}
31+
}

0 commit comments

Comments
 (0)