Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run the next build command using the correct package manager #49

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"glob": "catalog:",
"globals": "catalog:",
"next": "catalog:",
"package-manager-detector": "catalog:",
"tsup": "catalog:",
"typescript": "catalog:",
"typescript-eslint": "catalog:",
Expand Down
15 changes: 7 additions & 8 deletions packages/cloudflare/src/cli/build/build-next-app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { detect } from "package-manager-detector";
import { execSync } from "node:child_process";

/**
Expand All @@ -7,17 +8,15 @@ 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<void> {
const pm = await detect();

runNextBuildCommand(pm?.name ?? "npm", nextAppDir);
dario-piotrowicz marked this conversation as resolved.
Show resolved Hide resolved
}

// 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"*/,
nextAppDir: string
) {
const command = ["bun", "npm"].includes(packager) ? `${packager} next build` : `${packager} next build`;
function runNextBuildCommand(packager: "npm" | "pnpm" | "yarn" | "bun", nextAppDir: string) {
vicb marked this conversation as resolved.
Show resolved Hide resolved
const command = `${packager === "npm" ? "npx" : packager} next build`;
execSync(command, {
stdio: "inherit",
cwd: nextAppDir,
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/cli/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { rm } from "node:fs/promises";
export async function build(appDir: string, opts: BuildOptions): Promise<void> {
if (!opts.skipBuild) {
// Build the next app
buildNextjsApp(appDir);
await buildNextjsApp(appDir);
}

if (!containsDotNextDir(appDir)) {
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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