From b585099551912cb0104cf314cf2009c00e01e977 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Sep 2023 20:43:02 +0100 Subject: [PATCH] only use the Vercel config hack for versions that don't support bun (#462) --- .changeset/lazy-toys-march.md | 5 +++++ packages/next-on-pages/package.json | 2 +- .../src/buildApplication/buildVercelOutput.ts | 22 +++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .changeset/lazy-toys-march.md diff --git a/.changeset/lazy-toys-march.md b/.changeset/lazy-toys-march.md new file mode 100644 index 000000000..f546ac91d --- /dev/null +++ b/.changeset/lazy-toys-march.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/next-on-pages': patch +--- + +Avoid using the Vercel custom config hack for Bun package manager support when a version of the Vercel CLI that supports Bun is used. diff --git a/packages/next-on-pages/package.json b/packages/next-on-pages/package.json index 01cb86d62..a738eb58e 100644 --- a/packages/next-on-pages/package.json +++ b/packages/next-on-pages/package.json @@ -44,7 +44,7 @@ "zodcli": "^0.0.4" }, "peerDependencies": { - "vercel": "^30.0.0 || ^31.0.0 || ^32.0.0", + "vercel": ">=30.0.0", "wrangler": "^3.0.0" }, "devDependencies": { diff --git a/packages/next-on-pages/src/buildApplication/buildVercelOutput.ts b/packages/next-on-pages/src/buildApplication/buildVercelOutput.ts index b4d27ab6e..8558bf0e4 100644 --- a/packages/next-on-pages/src/buildApplication/buildVercelOutput.ts +++ b/packages/next-on-pages/src/buildApplication/buildVercelOutput.ts @@ -1,7 +1,7 @@ import { writeFile, mkdir, rm, rmdir } from 'fs/promises'; import { spawn, type ChildProcessWithoutNullStreams } from 'child_process'; import { join, resolve } from 'path'; -import { cliLog } from '../cli'; +import { cliLog, cliWarn } from '../cli'; import { readJsonFile, validateDir, validateFile } from '../utils'; import type { PackageManager } from './packageManagerUtils'; import { @@ -34,13 +34,21 @@ export async function buildVercelOutput(): Promise { await generateProjectJsonFileIfNeeded(); let tempVercelConfig: TempVercelConfigInfo | undefined; - // When using the Bun package manager, we need to ensure the Vercel CLI has a config file that - // tells it to use Bun, since Vercel doesn't support auto-detecting Bun yet. + if (pm === 'bun') { - tempVercelConfig = await createTempVercelConfig({ - buildCommand: 'bun run build', - installCommand: 'bun install', - }); + // Vercel introduced proper Bun support in 32.2.1 and 32.2.4 (for monorepos), therefore we should + // ensure the Vercel CLI has a config file telling it to use Bun for older versions. This is done + // to prevent a breaking change for users who are using an older version of the Vercel CLI. + const vercelVersion = await getPackageVersion('vercel', pm); + if (vercelVersion && vercelVersion < '32.2.4') { + cliWarn( + 'Vercel CLI version is < 32.2.4, creating temporary config for Bun support...', + ); + tempVercelConfig = await createTempVercelConfig({ + buildCommand: 'bun run build', + installCommand: 'bun install', + }); + } } cliLog('Project is ready');