Skip to content
Open
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
1 change: 1 addition & 0 deletions src/runtime/cli/Arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,7 @@ fn parse_build_command_options(
)
),
);
Global::exit(1);
}
}
}
Expand Down
48 changes: 47 additions & 1 deletion test/bundler/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { bunEnv, bunExe, isWindows, tempDir, tmpdirSync } from "harness";
import { bunEnv, bunExe, isWindows, normalizeBunSnapshot, tempDir, tmpdirSync } from "harness";
import fs, { mkdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import path, { join } from "node:path";

Expand Down Expand Up @@ -516,6 +516,52 @@ describe("CLI argument error messages", () => {
expect(stderr).toContain("key=value");
expect(exitCode).toBe(1);
});

// bunEnv sets BUN_FEATURE_FLAG_EXPERIMENTAL_BAKE, so --app is accepted by
// release builds too.
describe.concurrent("--app --target", () => {
const files = {
// `bun build --app` evaluates this file first, so the marker on stdout
// tells whether the build started at all.
"bun.app.ts": `console.log("config evaluated");\nexport default {};`,
};

test.each([
["node", "Node"],
["browser", "Browser"],
])("--target=%s is rejected before the build starts", async (target, received) => {
using dir = tempDir("build-app-target-err", files);
await using proc = Bun.spawn({
cmd: [bunExe(), "build", "--app", `--target=${target}`, "bun.app.ts"],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({ stdout, stderr: normalizeBunSnapshot(stderr) }).toEqual({
stdout: "",
stderr: `error: target must be 'bun' when using --app. Received: ${received}`,
});
expect(exitCode).toBe(1);
});

test("--target=bun is accepted", async () => {
using dir = tempDir("build-app-target-bun", files);
await using proc = Bun.spawn({
cmd: [bunExe(), "build", "--app", "--target=bun", "bun.app.ts"],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
// The config above has no `app` section, so the build itself fails
// later on; this only checks that the target check let it start.
const [stdout, stderr] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stderr).not.toContain("target must be 'bun'");
expect(stdout).toBe("config evaluated\n");
});
});
});

describe.concurrent("modules that fail to print", () => {
Expand Down