Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/clear-next-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/autoconfig": minor
---

Remove the experimental `cf:build` script override

Autoconfig no longer selects `cf:build` for Next.js projects. OpenNext applications that want to use `cf` should migrate to vinext. Wrangler's OpenNext support and the existing Next.js static export path are unchanged.
11 changes: 2 additions & 9 deletions packages/autoconfig/src/details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ export async function getDetailsForAutoConfig({
getViteConfigPath(projectPath).endsWith(".js") &&
usesNativeJsViteConfig(projectPath);
const { type: packageManagerName } = packageManager;
const buildScript =
nextBuild === "custom"
? "cf:build"
: useNativeLoaderScripts
? "build"
: undefined;
const packageBuild = packageJson?.scripts?.build;
const baseDetails = {
projectPath,
Expand All @@ -324,7 +318,6 @@ export async function getDetailsForAutoConfig({
...(nextBuild === "unsupported" || nextBuild === "static-capable"
? { cfBuildError: OPENNEXT_BUILD_ERROR }
: {}),
...(nextBuild === "custom" ? { usesCustomCfBuild: true } : {}),
devCommand: useStaticAssets
? undefined
: nextExport
Expand All @@ -339,8 +332,8 @@ export async function getDetailsForAutoConfig({
),
buildCommand: useStaticAssets
? undefined
: buildScript
? `${packageManagerName} run ${buildScript}${packageManagerName === "npm" ? " --" : ""}`
: useNativeLoaderScripts
? `${packageManagerName} run build${packageManagerName === "npm" ? " --" : ""}`
: nextExport
? typeof packageBuild === "string" &&
packageBuild.trim() === "next build"
Expand Down
10 changes: 3 additions & 7 deletions packages/autoconfig/src/frameworks/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ const VINEXT_CONFIGURATION_DESCRIPTION =
"Configuring project for Next.js with vinext by running `vinext init`";

export const OPENNEXT_BUILD_ERROR =
"OpenNext builds are not supported by cf. Use Wrangler with OpenNext to set up and deploy this project: https://developers.cloudflare.com/workers/framework-guides/web-apps/opennext/";
"OpenNext builds are not supported by cf. To use cf, migrate this project to vinext: https://vinext.dev/docs/getting-started/migrating-from-opennext";

function supportsVinext(nextVersion: string): boolean {
return semiver(nextVersion, VINEXT_MINIMUM_NEXT_VERSION) >= 0;
}

/**
* Chooses the cf build route for a Next.js project.
* @returns A custom build or the OpenNext route, with or without static export support.
* @returns The OpenNext route, with or without static export support.
* Returns undefined when normal framework routing should continue.
*/
export function getCfNextBuild(
projectPath: string,
packageJson: PackageJSON | undefined,
configured: boolean
): "unsupported" | "custom" | "static-capable" | undefined {
): "unsupported" | "static-capable" | undefined {
const dependencies = {
...packageJson?.devDependencies,
...packageJson?.dependencies,
Expand All @@ -61,10 +61,6 @@ export function getCfNextBuild(
!intersects(declaredRange, `>=${VINEXT_MINIMUM_NEXT_VERSION}`, {
includePrerelease: true,
});
const customBuild = packageJson?.scripts?.["cf:build"];
if (configured && typeof customBuild === "string" && customBuild.trim()) {
return "custom";
}
const buildScript = packageJson?.scripts?.build;
const configuredForOpenNext =
(typeof buildScript === "string" && invokesOpenNext(buildScript)) ||
Expand Down
2 changes: 0 additions & 2 deletions packages/autoconfig/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type AutoConfigDetailsBase = {
commandError?: AutoConfigCommandError;
/** Why the detected build path cannot produce Build Output for cf. */
cfBuildError?: string;
/** Whether the build command comes from the project's explicit `cf:build` script. */
usesCustomCfBuild?: boolean;
/** Application and enclosing workspace node_modules directories, nearest first. */
nodeModulesPaths?: readonly string[];
/** Root of the validated enclosing workspace, if any. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
next: "^15.5.0",
build: "opennextjs-cloudflare build",
customBuild: "npm run build && node scripts/emit-build-output.mjs",
rejected: false,
rejected: true,
},
{
configured: true,
Expand Down Expand Up @@ -185,15 +185,15 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
expect(project.configured).toBe(configured);
if (rejected) {
expect(() => details.assertCfBuildSupported(project)).toThrow(
"Use Wrangler with OpenNext"
"migrate this project to vinext"
);
} else {
expect(project.cfBuildError).toBeUndefined();
if (customBuild) {
expect(project.usesCustomCfBuild).toBe(true);
expect(project.buildCommand).toBe("npm run cf:build --");
expect(project.buildCommand).toBe("next build");
}
}
expect(project.buildCommand ?? "").not.toContain("cf:build");
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved
}
);

Expand Down Expand Up @@ -233,6 +233,7 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
next: "^15.0.0",
configured: true,
customBuild: "node custom-build.js",
directory: "out",
},
{
config: "next.config.js",
Expand Down Expand Up @@ -379,12 +380,6 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
} else {
expect(project.staticSite).toBeUndefined();
}
if (fixture.customBuild) {
expect(project).toMatchObject({
usesCustomCfBuild: true,
buildCommand: "npm run cf:build --",
});
}
}
);

Expand Down
4 changes: 2 additions & 2 deletions packages/autoconfig/tests/frameworks/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe("Next.js framework configure()", () => {
const framework = createNextJs("15.5.4");

await expect(framework.configure(getOptions("cf"))).rejects.toThrow(
"Use Wrangler with OpenNext"
"migrate this project to vinext"
);
expect(runCommand).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -225,7 +225,7 @@ describe("Next.js framework configure()", () => {
const framework = createNextJs("16.0.0-canary.1");

await expect(framework.configure(getOptions("cf"))).rejects.toThrow(
"Use Wrangler with OpenNext"
"migrate this project to vinext"
);
expect(runCommand).not.toHaveBeenCalled();
});
Expand Down
Loading