Skip to content

Commit 168b03c

Browse files
authored
Run Nx + Next.js builds from root context (#180)
* run build from root for monorepos
1 parent 8229e65 commit 168b03c

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+
// Parse args to pass to the build command
20+
let cmdArgs: string[] = [];
21+
if (process.env.MONOREPO_BUILD_ARGS) {
22+
cmdArgs = process.env.MONOREPO_BUILD_ARGS.split(",");
2323
}
2424

25-
build(projectRoot, cmd);
25+
// Determine which command to run the build
26+
const cmd = process.env.MONOREPO_COMMAND || DEFAULT_COMMAND;
27+
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
@@ -71,12 +71,12 @@ export function populateOutputBundleOptions(rootDir: string, appDir: string): Ou
7171
}
7272

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

8282
/**

0 commit comments

Comments
 (0)