make bun ci work as alias of --frozen-lockfile (like npm ci) (#20590)

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
Michael H
2025-07-17 22:41:06 +10:00
committed by GitHub
parent 664506474a
commit be03a537df
3 changed files with 62 additions and 3 deletions

View File

@@ -578,6 +578,7 @@ pub const Command = struct {
break :brk .InstallCommand;
},
RootCommandMatcher.case("ci") => .InstallCommand,
RootCommandMatcher.case("c"), RootCommandMatcher.case("create") => .CreateCommand,
RootCommandMatcher.case("test") => .TestCommand,

View File

@@ -712,9 +712,10 @@ pub fn parse(allocator: std.mem.Allocator, comptime subcommand: Subcommand) !Com
}
var cli = CommandLineArguments{};
cli.positionals = args.positionals();
cli.yarn = args.flag("--yarn");
cli.production = args.flag("--production");
cli.frozen_lockfile = args.flag("--frozen-lockfile");
cli.frozen_lockfile = args.flag("--frozen-lockfile") or (cli.positionals.len > 0 and strings.eqlComptime(cli.positionals[0], "ci"));
cli.no_progress = args.flag("--no-progress");
cli.dry_run = args.flag("--dry-run");
cli.global = args.flag("--global");
@@ -920,8 +921,6 @@ pub fn parse(allocator: std.mem.Allocator, comptime subcommand: Subcommand) !Com
cli.registry = registry;
}
cli.positionals = args.positionals();
if (subcommand == .patch and cli.positionals.len < 2) {
Output.errGeneric("Missing pkg to patch\n", .{});
Global.crash();

View File

@@ -6198,6 +6198,65 @@ it("should handle --frozen-lockfile", async () => {
expect(await exited).toBe(1);
});
it("should handle bun ci alias (to --frozen-lockfile)", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" }, "0.0.5": { as: "0.0.5" } }));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({ name: "foo", version: "0.0.1", dependencies: { baz: "0.0.3" } }),
);
// save the lockfile once
expect(
await spawn({
cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: "ignore",
stdin: "ignore",
stderr: "ignore",
env,
}).exited,
).toBe(0);
// change version of baz in package.json
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
version: "0.0.1",
dependencies: { baz: "0.0.5" },
}),
);
const { stderr: stderr1, exited: exited1 } = spawn({
cmd: [bunExe(), "ci"],
cwd: package_dir,
stdout: "pipe",
stdin: "pipe",
stderr: "pipe",
env,
});
const err1 = await new Response(stderr1).text();
expect(err1).toContain("error: lockfile had changes, but lockfile is frozen");
expect(await exited1).toBe(1);
// test that it works even if ci isn't first "arg"
const { stderr: stderr2, exited: exited2 } = spawn({
cmd: [bunExe(), "--save", "ci"],
cwd: package_dir,
stdout: "pipe",
stdin: "pipe",
stderr: "pipe",
env,
});
const err2 = await new Response(stderr2).text();
expect(err2).toContain("error: lockfile had changes, but lockfile is frozen");
expect(await exited2).toBe(1);
});
it("should handle frozenLockfile in config file", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" }, "0.0.5": { as: "0.0.5" } }));