Skip to content

Commit b621c32

Browse files
committed
run build from root for monorepos
1 parent 2aa4116 commit b621c32

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/@apphosting/adapter-nextjs/src/bin/build.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ if (process.env.FIREBASE_APP_DIRECTORY) {
1616
projectRoot = projectRoot.concat("/", process.env.FIREBASE_APP_DIRECTORY);
1717
}
1818

19-
// Determine which build runner to use
20-
let cmd = DEFAULT_COMMAND;
21-
if (process.env.MONOREPO_COMMAND) {
22-
cmd = process.env.MONOREPO_COMMAND;
19+
// Determine which command to run the build
20+
const cmd = process.env.MONOREPO_COMMAND || DEFAULT_COMMAND;
21+
22+
// Parse args to pass to the build command
23+
let cmdArgs: string[] = [];
24+
if (process.env.MONOREPO_BUILD_ARGS) {
25+
cmdArgs = process.env.MONOREPO_BUILD_ARGS.split(",");
2326
}
2427

25-
build(projectRoot, cmd);
28+
// Run build command from the subdirectory if specified.
29+
// N.B. We run the build command from the root for monorepo builds, so that the build process can
30+
// locate necessary files outside the project directory.
31+
build(process.env.MONOREPO_CMD ? root : projectRoot, cmd, ...cmdArgs);
2632

2733
const outputBundleOptions = populateOutputBundleOptions(root, projectRoot);
2834
const { distDir } = await loadConfig(root, projectRoot);

packages/@apphosting/adapter-nextjs/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ export function populateOutputBundleOptions(rootDir: string, appDir: string): Ou
7070
}
7171

7272
// Run build command
73-
export function build(cwd: string, cmd = DEFAULT_COMMAND): void {
73+
export function build(cwd: string, cmd = DEFAULT_COMMAND, ...argv: string[]): void {
7474
// Set standalone mode
7575
process.env.NEXT_PRIVATE_STANDALONE = "true";
7676
// Opt-out sending telemetry to Vercel
7777
process.env.NEXT_TELEMETRY_DISABLED = "1";
78-
spawnSync(cmd, ["run", "build"], { cwd, shell: true, stdio: "inherit" });
78+
spawnSync(cmd, ["run", "build", ...argv], { cwd, shell: true, stdio: "inherit" });
7979
}
8080

8181
/**

0 commit comments

Comments
 (0)