Skip to content

Fix monorepo build args split and add test for getBuildOptions #376

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 7 commits into from
Aug 9, 2025
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
51 changes: 50 additions & 1 deletion packages/@apphosting/common/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,56 @@ import assert from "assert";
import fs from "fs";
import path from "path";
import os from "os";
import { updateOrCreateGitignore } from "./index";
import { getBuildOptions, updateOrCreateGitignore } from "./index";

const originalCwd = process.cwd.bind(process);

describe("get a set of build options", () => {
const mockCwd = "/fake/project/";
beforeEach(() => {
process.cwd = () => mockCwd;
});

afterEach(() => {
process.cwd = originalCwd;
delete process.env.MONOREPO_COMMAND;
delete process.env.MONOREPO_BUILD_ARGS;
delete process.env.GOOGLE_BUILDABLE;
delete process.env.MONOREPO_PROJECT;
});

it("returns monorepo build options when MONOREPO_COMMAND is set", () => {
process.env.MONOREPO_COMMAND = "turbo";
process.env.MONOREPO_BUILD_ARGS = "--filter=web,--env-mode=strict";
process.env.GOOGLE_BUILDABLE = "/workspace/apps/web";
process.env.MONOREPO_PROJECT = "web";

const expectedOptions = {
buildCommand: "turbo",
buildArgs: ["run", "build", "--filter=web", "--env-mode=strict"],
projectDirectory: "/workspace/apps/web",
projectName: "web",
};
assert.deepStrictEqual(
getBuildOptions(),
expectedOptions,
"Monorepo build options are incorrect",
);
});

it("returns standard build options when MONOREPO_COMMAND is not set", () => {
const expectedOptions = {
buildCommand: "npm",
buildArgs: ["run", "build"],
projectDirectory: process.cwd(),
};
assert.deepStrictEqual(
getBuildOptions(),
expectedOptions,
"Standard build options are incorrect",
);
});
});

describe("update or create .gitignore", () => {
let tmpDir: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/@apphosting/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function getBuildOptions(): BuildOptions {
if (process.env.MONOREPO_COMMAND) {
return {
buildCommand: process.env.MONOREPO_COMMAND,
buildArgs: ["run", "build"].concat(process.env.MONOREPO_BUILD_ARGS?.split(".") || []),
buildArgs: ["run", "build"].concat(process.env.MONOREPO_BUILD_ARGS?.split(",") || []),
projectDirectory: process.env.GOOGLE_BUILDABLE || "",
projectName: process.env.MONOREPO_PROJECT,
};
Expand Down