Skip to content
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

Preserve -- in process.argv #14003

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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
7 changes: 1 addition & 6 deletions src/deps/zig-clap/clap/comptime.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/cli/install/bun-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,35 @@ it("--ignore-dce-annotations ignores DCE annotations", () => {
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");

it("$npm_command is accurate", async () => {
await writeFile(
join(run_dir, "package.json"),
Expand Down