From a425376c3db49d4432e64b1cbf362cc91f39bfce Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 14 May 2023 23:09:19 -0700 Subject: [PATCH] Fix `process.argv` with standalone --- src/bun.js/node/types.zig | 20 +++++++++++++------- src/cli.zig | 7 +++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index dacb9540cb..97098391ee 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1988,13 +1988,19 @@ pub const Process = struct { var args_list = std.ArrayListUnmanaged(JSC.ZigString){ .items = args, .capacity = args.len }; args_list.items.len = 0; - // get the bun executable - // without paying the cost of a syscall to resolve the full path - args_list.appendAssumeCapacity( - JSC.ZigString.init( - std.fs.selfExePathAlloc(allocator) catch "bun", - ).withEncoding(), - ); + if (vm.standalone_module_graph != null) { + // Don't break user's code because they did process.argv.slice(2) + // Even if they didn't type "bun", we still want to add it + args_list.appendAssumeCapacity( + JSC.ZigString.init("bun"), + ); + } else { + args_list.appendAssumeCapacity( + JSC.ZigString.init( + std.fs.selfExePathAlloc(allocator) catch "bun", + ).withEncoding(), + ); + } if (vm.main.len > 0) args_list.appendAssumeCapacity(JSC.ZigString.init(vm.main).withEncoding()); diff --git a/src/cli.zig b/src/cli.zig index 621f54fd22..3b1f7e3058 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -1114,6 +1114,13 @@ pub const Command = struct { }; ctx.args.target = Api.Target.bun; + var argv = try bun.default_allocator.alloc(string, std.os.argv.len -| 1); + if (std.os.argv.len > 1) { + for (argv, std.os.argv[1..]) |*dest, src| { + dest.* = bun.span(src); + } + } + ctx.passthrough = argv; try @import("./bun_js.zig").Run.bootStandalone( ctx,