diff --git a/packages/@apphosting/adapter-nextjs/src/bin/build.ts b/packages/@apphosting/adapter-nextjs/src/bin/build.ts index cf5bc0d6..cc4beddc 100644 --- a/packages/@apphosting/adapter-nextjs/src/bin/build.ts +++ b/packages/@apphosting/adapter-nextjs/src/bin/build.ts @@ -16,13 +16,19 @@ if (process.env.FIREBASE_APP_DIRECTORY) { projectRoot = projectRoot.concat("/", process.env.FIREBASE_APP_DIRECTORY); } -// Determine which build runner to use -let cmd = DEFAULT_COMMAND; -if (process.env.MONOREPO_COMMAND) { - cmd = process.env.MONOREPO_COMMAND; +// Parse args to pass to the build command +let cmdArgs: string[] = []; +if (process.env.MONOREPO_BUILD_ARGS) { + cmdArgs = process.env.MONOREPO_BUILD_ARGS.split(","); } -build(projectRoot, cmd); +// Determine which command to run the build +const cmd = process.env.MONOREPO_COMMAND || DEFAULT_COMMAND; + +// Run build command from the subdirectory if specified. +// N.B. We run the build command from the root for monorepo builds, so that the build process can +// locate necessary files outside the project directory. +build(process.env.MONOREPO_CMD ? root : projectRoot, cmd, ...cmdArgs); const outputBundleOptions = populateOutputBundleOptions(root, projectRoot); const { distDir } = await loadConfig(root, projectRoot); diff --git a/packages/@apphosting/adapter-nextjs/src/utils.ts b/packages/@apphosting/adapter-nextjs/src/utils.ts index fe6c5edb..20bcef0c 100644 --- a/packages/@apphosting/adapter-nextjs/src/utils.ts +++ b/packages/@apphosting/adapter-nextjs/src/utils.ts @@ -71,12 +71,12 @@ export function populateOutputBundleOptions(rootDir: string, appDir: string): Ou } // Run build command -export function build(cwd: string, cmd = DEFAULT_COMMAND): void { +export function build(cwd: string, cmd = DEFAULT_COMMAND, ...argv: string[]): void { // Set standalone mode process.env.NEXT_PRIVATE_STANDALONE = "true"; // Opt-out sending telemetry to Vercel process.env.NEXT_TELEMETRY_DISABLED = "1"; - spawnSync(cmd, ["run", "build"], { cwd, shell: true, stdio: "inherit" }); + spawnSync(cmd, ["run", "build", ...argv], { cwd, shell: true, stdio: "inherit" }); } /**