From eac9921996b68ef9f566f299f6e65b7a7d230e2e Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Mon, 30 Sep 2024 11:53:46 +0100 Subject: [PATCH] run `next build` command using the correct package manager --- packages/cloudflare/package.json | 1 + packages/cloudflare/src/cli/build/build-next-app.ts | 11 +++++++---- pnpm-lock.yaml | 11 +++++++++++ pnpm-workspace.yaml | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/cloudflare/package.json b/packages/cloudflare/package.json index 39a45531..5cc2245d 100644 --- a/packages/cloudflare/package.json +++ b/packages/cloudflare/package.json @@ -48,6 +48,7 @@ "glob": "catalog:", "globals": "catalog:", "next": "catalog:", + "package-manager-detector": "catalog:", "tsup": "catalog:", "typescript": "catalog:", "typescript-eslint": "catalog:", diff --git a/packages/cloudflare/src/cli/build/build-next-app.ts b/packages/cloudflare/src/cli/build/build-next-app.ts index 3097e83e..02f8a81a 100644 --- a/packages/cloudflare/src/cli/build/build-next-app.ts +++ b/packages/cloudflare/src/cli/build/build-next-app.ts @@ -1,3 +1,4 @@ +import { detect } from "package-manager-detector"; import { execSync } from "node:child_process"; /** @@ -7,17 +8,19 @@ import { execSync } from "node:child_process"; * * @param nextAppDir the directory of the app to build */ -export function buildNextjsApp(nextAppDir: string): void { - runNextBuildCommand("pnpm", nextAppDir); +export async function buildNextjsApp(nextAppDir: string): Promise { + const pm = await detect(); + + runNextBuildCommand(pm?.name ?? "npm", nextAppDir); } // equivalent to: https://github.com/sst/open-next/blob/f61b0e94/packages/open-next/src/build.ts#L175-L186 function runNextBuildCommand( // let's keep things simple and just support only pnpm for now - packager: "pnpm" /*"npm" | "yarn" | "pnpm" | "bun"*/, + packager: "npm" | "pnpm" | "yarn" | "bun", nextAppDir: string ) { - const command = ["bun", "npm"].includes(packager) ? `${packager} next build` : `${packager} next build`; + const command = `${packager === "npm" ? "npx" : packager} next build`; execSync(command, { stdio: "inherit", cwd: nextAppDir, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b79ccbf0..405faf9b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,6 +45,9 @@ catalogs: next: specifier: 14.2.11 version: 14.2.11 + package-manager-detector: + specifier: ^0.2.0 + version: 0.2.0 react: specifier: ^18 version: 18.3.1 @@ -188,6 +191,9 @@ importers: next: specifier: 'catalog:' version: 14.2.11(@playwright/test@1.47.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + package-manager-detector: + specifier: 'catalog:' + version: 0.2.0 tsup: specifier: 'catalog:' version: 8.2.4(jiti@1.21.6)(postcss@8.4.47)(tsx@4.17.0)(typescript@5.5.4)(yaml@2.5.1) @@ -2288,6 +2294,9 @@ packages: package-json-from-dist@1.0.0: resolution: {integrity: sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==} + package-manager-detector@0.2.0: + resolution: {integrity: sha512-E385OSk9qDcXhcM9LNSe4sdhx8a9mAPrZ4sMLW+tmxl5ZuGtPUcdFu+MPP2jbgiWAZ6Pfe5soGFMd+0Db5Vrog==} + parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} @@ -5174,6 +5183,8 @@ snapshots: package-json-from-dist@1.0.0: {} + package-manager-detector@0.2.0: {} + parent-module@1.0.1: dependencies: callsites: 3.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b18267ee..fa513fa4 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -24,3 +24,4 @@ catalog: "globals": ^15.9.0 "typescript-eslint": ^8.7.0 "eslint-plugin-unicorn": ^55.0.0 + "package-manager-detector": ^0.2.0