Skip to content

Commit 361f2b7

Browse files
run the next build command using the correct package manager (#49)
1 parent 28d3ca1 commit 361f2b7

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

packages/cloudflare/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"glob": "catalog:",
4949
"globals": "catalog:",
5050
"next": "catalog:",
51+
"package-manager-detector": "catalog:",
5152
"tsup": "catalog:",
5253
"typescript": "catalog:",
5354
"typescript-eslint": "catalog:",

packages/cloudflare/src/cli/build/build-next-app.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type AgentName as PackageManager, detect } from "package-manager-detector";
12
import { execSync } from "node:child_process";
23

34
/**
@@ -7,17 +8,19 @@ import { execSync } from "node:child_process";
78
*
89
* @param nextAppDir the directory of the app to build
910
*/
10-
export function buildNextjsApp(nextAppDir: string): void {
11-
runNextBuildCommand("pnpm", nextAppDir);
11+
export async function buildNextjsApp(nextAppDir: string): Promise<void> {
12+
const pm = await detect();
13+
14+
if (!pm) {
15+
throw new Error("Fatal Error: package manager detection failed, aborting");
16+
}
17+
18+
runNextBuildCommand(pm.name, nextAppDir);
1219
}
1320

1421
// equivalent to: https://github.com/sst/open-next/blob/f61b0e94/packages/open-next/src/build.ts#L175-L186
15-
function runNextBuildCommand(
16-
// let's keep things simple and just support only pnpm for now
17-
packager: "pnpm" /*"npm" | "yarn" | "pnpm" | "bun"*/,
18-
nextAppDir: string
19-
) {
20-
const command = ["bun", "npm"].includes(packager) ? `${packager} next build` : `${packager} next build`;
22+
function runNextBuildCommand(packager: PackageManager, nextAppDir: string) {
23+
const command = `${packager === "npm" ? "npx" : packager} next build`;
2124
execSync(command, {
2225
stdio: "inherit",
2326
cwd: nextAppDir,

packages/cloudflare/src/cli/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { rm } from "node:fs/promises";
1717
export async function build(appDir: string, opts: BuildOptions): Promise<void> {
1818
if (!opts.skipBuild) {
1919
// Build the next app
20-
buildNextjsApp(appDir);
20+
await buildNextjsApp(appDir);
2121
}
2222

2323
if (!containsDotNextDir(appDir)) {

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ catalog:
2424
"globals": ^15.9.0
2525
"typescript-eslint": ^8.7.0
2626
"eslint-plugin-unicorn": ^55.0.0
27+
"package-manager-detector": ^0.2.0

0 commit comments

Comments
 (0)