From 773e2a8cc07a6ff55a5a12edd103751eafcc9468 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Mon, 23 Oct 2023 23:37:01 +0100 Subject: [PATCH] fix the generation of invalid/incorrect scripts for Next.js applications (#4200) --- .changeset/tasty-teachers-lick.md | 5 +++++ .../src/frameworks/next/index.ts | 20 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .changeset/tasty-teachers-lick.md diff --git a/.changeset/tasty-teachers-lick.md b/.changeset/tasty-teachers-lick.md new file mode 100644 index 000000000000..06d478c33886 --- /dev/null +++ b/.changeset/tasty-teachers-lick.md @@ -0,0 +1,5 @@ +--- +"create-cloudflare": patch +--- + +fix the generation of invalid/incorrect scripts for Next.js applications diff --git a/packages/create-cloudflare/src/frameworks/next/index.ts b/packages/create-cloudflare/src/frameworks/next/index.ts index ca56f7231fbe..e5594d1bf281 100644 --- a/packages/create-cloudflare/src/frameworks/next/index.ts +++ b/packages/create-cloudflare/src/frameworks/next/index.ts @@ -141,12 +141,20 @@ const config: FrameworkConfig = { generate, configure, displayName: "Next", - getPackageScripts: async () => ({ - "pages:build": `${dlx} @cloudflare/next-on-pages@1`, - "pages:deploy": `${npm} run pages:build && wrangler pages deploy .vercel/output/static`, - "pages:watch": `${npx} @cloudflare/next-on-pages@1 --watch`, - "pages:dev": `${npx} wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`, - }), + getPackageScripts: async () => { + const isNpmOrBun = ["npm", "bun"].includes(npm); + const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : ""; + const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`; + const pmCommand = isNpmOrBun ? npx : npm; + return { + "pages:build": `${pmCommand} ${nextOnPagesCommand}`, + "pages:deploy": `${ + npm === "npm" ? "npm run" : pmCommand + } pages:build && wrangler pages deploy .vercel/output/static`, + "pages:watch": `${pmCommand} ${nextOnPagesCommand} --watch`, + "pages:dev": `${pmCommand} wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`, + }; + }, testFlags: [ "--typescript", "--no-install",