diff --git a/.changeset/clear-next-routing.md b/.changeset/clear-next-routing.md new file mode 100644 index 0000000000..82986d50a4 --- /dev/null +++ b/.changeset/clear-next-routing.md @@ -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. diff --git a/packages/autoconfig/src/details/index.ts b/packages/autoconfig/src/details/index.ts index 781a86a347..a687af321d 100644 --- a/packages/autoconfig/src/details/index.ts +++ b/packages/autoconfig/src/details/index.ts @@ -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, @@ -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 @@ -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" diff --git a/packages/autoconfig/src/frameworks/next.ts b/packages/autoconfig/src/frameworks/next.ts index d31f65ce59..864fe7e116 100644 --- a/packages/autoconfig/src/frameworks/next.ts +++ b/packages/autoconfig/src/frameworks/next.ts @@ -29,7 +29,7 @@ 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; @@ -37,14 +37,14 @@ function supportsVinext(nextVersion: string): boolean { /** * 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, @@ -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)) || diff --git a/packages/autoconfig/src/types.ts b/packages/autoconfig/src/types.ts index 06b65d9142..5cc7a16487 100644 --- a/packages/autoconfig/src/types.ts +++ b/packages/autoconfig/src/types.ts @@ -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. */ diff --git a/packages/autoconfig/tests/details/get-details-for-auto-config.test.ts b/packages/autoconfig/tests/details/get-details-for-auto-config.test.ts index 6fdeca3dd2..984f5a35d1 100644 --- a/packages/autoconfig/tests/details/get-details-for-auto-config.test.ts +++ b/packages/autoconfig/tests/details/get-details-for-auto-config.test.ts @@ -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, @@ -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"); } ); @@ -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", @@ -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 --", - }); - } } ); diff --git a/packages/autoconfig/tests/frameworks/next.test.ts b/packages/autoconfig/tests/frameworks/next.test.ts index c93ffd5342..5583aad147 100644 --- a/packages/autoconfig/tests/frameworks/next.test.ts +++ b/packages/autoconfig/tests/frameworks/next.test.ts @@ -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(); }); @@ -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(); });