From b6c2c2600b26a8bf314db8727e01c029afb1d69a Mon Sep 17 00:00:00 2001 From: Reilly O'Donnell Date: Tue, 17 Sep 2024 20:40:24 -0400 Subject: [PATCH 1/3] Preserve -- as an argument --- src/deps/zig-clap/clap/comptime.zig | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/deps/zig-clap/clap/comptime.zig b/src/deps/zig-clap/clap/comptime.zig index 62d007c43b8cd9..f457b3a567481a 100644 --- a/src/deps/zig-clap/clap/comptime.zig +++ b/src/deps/zig-clap/clap/comptime.zig @@ -78,12 +78,7 @@ pub fn ComptimeClap( if (param.names.long == null and param.names.short == null) { try pos.append(arg.value.?); if (opt.stop_after_positional_at > 0 and pos.items.len >= opt.stop_after_positional_at) { - var remaining_ = stream.iter.remain; - const first: []const u8 = if (remaining_.len > 0) bun.span(remaining_[0]) else ""; - if (first.len > 0 and std.mem.eql(u8, first, "--")) { - remaining_ = remaining_[1..]; - } - + const remaining_ = stream.iter.remain; try passthrough_positionals.ensureTotalCapacityPrecise(remaining_.len); for (remaining_) |arg_| { // use bun.span due to the optimization for long strings From 4412caced0c7d706208b7e0d0a353c05a2a400b6 Mon Sep 17 00:00:00 2001 From: Reilly O'Donnell Date: Wed, 18 Sep 2024 20:15:37 -0400 Subject: [PATCH 2/3] Added test --- test/cli/install/bun-run.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index e20c2efda2948c..8c01015889baa5 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -475,3 +475,34 @@ it("--ignore-dce-annotations ignores DCE annotations", () => { expect(stderr.toString()).toBe(""); expect(stdout.toString()).toBe("Hello, world!\n"); }); + +it("should preserve '--' in process.argv", async () => { + await mkdir(join(run_dir, "subdir")); + await writeFile( + join(run_dir, "subdir", "test.js"), + ` + console.log(process.argv); + `, + ); + + const {stdout} = spawn({ + cmd: [bunExe(), "run", "subdir/test.js", "--", "rest", "--foo=bar", ], + cwd: run_dir, + env: { + ...env, + BUN_INSTALL_CACHE_DIR: join(run_dir, ".cache"), + }, + }); + + const text = await Bun.readableStreamToText(stdout); + + const cleanedText = text.replace(/\n/g, ''); + const argv = JSON.parse(cleanedText); + + // the first argv is bun exe path + // the second argv is the script name + expect(argv[2]).toBe("--"); + expect(argv[3]).toBe("rest"); + expect(argv[4]).toBe("--foo=bar"); +}); + \ No newline at end of file From b47494004f822b6651ca6d6a8424bbb058a670a6 Mon Sep 17 00:00:00 2001 From: reillyjodonnell Date: Wed, 5 Feb 2025 21:57:38 -0500 Subject: [PATCH 3/3] Fixed formatting --- test/cli/install/bun-run.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index fcf88da4c07366..56328ccdac93de 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -513,6 +513,8 @@ it("should preserve '--' in process.argv", async () => { expect(argv[2]).toBe("--"); expect(argv[3]).toBe("rest"); expect(argv[4]).toBe("--foo=bar"); + +}); it("$npm_command is accurate", async () => { await writeFile(