Fix process.argv with standalone

This commit is contained in:
Jarred Sumner
2023-05-14 23:09:19 -07:00
parent c367408233
commit a425376c3d
2 changed files with 20 additions and 7 deletions

View File

@@ -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());

View File

@@ -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,