fix(cli): remove undocumented 'bun' alias for build command

Remove the 'bun' alias that mapped to 'bun build'. This caused
confusion when users accidentally passed 'bun' as the first argument
(e.g., in Docker setups with Chainguard images where the entrypoint
is '/usr/bin/bun').

Now 'bun bun <file>' will attempt to run a package.json script named
'bun' instead of silently invoking the bundler.

Fixes #25925

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-12 09:49:52 +00:00
parent beccd01647
commit 853744b0ca
2 changed files with 50 additions and 2 deletions

View File

@@ -567,7 +567,7 @@ pub const Command = struct {
return switch (RootCommandMatcher.match(first_arg_name)) {
RootCommandMatcher.case("init") => .InitCommand,
RootCommandMatcher.case("build"), RootCommandMatcher.case("bun") => .BuildCommand,
RootCommandMatcher.case("build") => .BuildCommand,
RootCommandMatcher.case("discord") => .DiscordCommand,
RootCommandMatcher.case("upgrade") => .UpgradeCommand,
RootCommandMatcher.case("completions") => .InstallCompletionsCommand,
@@ -652,7 +652,6 @@ pub const Command = struct {
"unlink",
"remove",
"create",
"bun",
"upgrade",
"discord",
"test",

View File

@@ -0,0 +1,49 @@
import { describe, expect, it } from "bun:test";
import { bunEnv, bunExe } from "../../harness.js";
// https://github.com/oven-sh/bun/issues/25925
// `bun bun` was incorrectly aliased to `bun build`, which caused confusion
// when users accidentally passed "bun" as the first argument (e.g., in Docker setups)
describe("issue/25925", () => {
it("'bun bun' should not trigger build command", async () => {
await using proc = Bun.spawn({
cmd: [bunExe(), "bun", "index.js"],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]);
// The old behavior would run `bun build index.js` and produce errors like:
// "ModuleNotFound resolving "index.js" (entry point)"
// The new behavior should try to run a script named "bun" from package.json
// and fail with: "Script not found "bun""
// Verify it's NOT treating "bun" as an alias for "build"
// Build command errors would mention "entry point" or "resolving"
expect(stderr).not.toContain("entry point");
expect(stderr).not.toContain("ModuleNotFound");
// It should look for a script named "bun" instead
expect(stderr).toContain('Script not found "bun"');
// It should fail since there's no "bun" script
expect(exitCode).not.toBe(0);
});
it("'bun build' should still work", async () => {
await using proc = Bun.spawn({
cmd: [bunExe(), "build", "--help"],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]);
// The build command help should still work
expect(stdout).toContain("bun build");
expect(exitCode).toBe(0);
});
});