Skip to content

Run Nx + Next.js builds from root context #180

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

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 11 additions & 5 deletions packages/@apphosting/adapter-nextjs/src/bin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is MONOREPO build args set? I dont see it anywhere in the buildpacks code either

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MONOREPO_BUILD_ARGS is a new environment variable added in cl/631875763

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but I can't seem to find MONOREPO_BUILD_ARGS in that cl. Could you help point me to it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops sorry, just uploaded the changes - should be in line 95 of firebasenx/main.go now

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);
Expand Down
4 changes: 2 additions & 2 deletions packages/@apphosting/adapter-nextjs/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
}

/**
Expand Down
Loading