From 48ed1dfb65b77f29a4969a340f949f69ecfb9a64 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Mon, 5 Feb 2024 10:06:23 -0800 Subject: [PATCH] less (#8651) Co-authored-by: Jarred Sumner --- src/bun.zig | 2 ++ src/cli/bunx_command.zig | 9 ++++++++- src/cli/create_command.zig | 19 +++++++++++++++---- src/cli/run_command.zig | 10 ++++++++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/bun.zig b/src/bun.zig index 168f8cd9b5..4e3d48411b 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -2680,3 +2680,5 @@ pub fn getUserName(output_buffer: []u8) ?[]const u8 { pub var buffered_stdin = std.io.BufferedReader(4096, std.fs.File.Reader){ .unbuffered_reader = std.fs.File.Reader{ .context = .{ .handle = if (Environment.isWindows) undefined else 0 } }, }; + +pub const WindowsSpawnWorkaround = @import("./child_process_windows.zig"); diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig index 711277a8b2..7a37eb50ec 100644 --- a/src/cli/bunx_command.zig +++ b/src/cli/bunx_command.zig @@ -458,7 +458,14 @@ pub const BunxCommand = struct { child_process.stderr_behavior = .Inherit; child_process.stdin_behavior = .Inherit; child_process.stdout_behavior = .Inherit; - const term = try child_process.spawnAndWait(); + + if (Environment.isWindows) { + try bun.WindowsSpawnWorkaround.spawnWindows(&child_process); + } else { + try child_process.spawn(); + } + + const term = try child_process.wait(); switch (term) { .Exited => |exit_code| { diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index b44cdf8ce5..6e6a5cabcc 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -151,7 +151,14 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string, proc.stdout_behavior = .Inherit; proc.stderr_behavior = .Inherit; proc.cwd = cwd; - _ = proc.spawnAndWait() catch undefined; + + if (Environment.isWindows) { + bun.WindowsSpawnWorkaround.spawnWindows(&proc) catch return; + } else { + proc.spawn() catch return; + } + + _ = proc.wait() catch {}; } // We don't want to allocate memory each time @@ -1434,9 +1441,13 @@ pub const CreateCommand = struct { Output.flush(); } - _ = try process.spawnAndWait(); - - _ = process.kill() catch undefined; + if (Environment.isWindows) { + try bun.WindowsSpawnWorkaround.spawnWindows(&process); + } else { + try process.spawn(); + } + _ = try process.wait(); + _ = try process.kill(); } if (postinstall_tasks.items.len > 0) { diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 956a99dad9..3930edea39 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -348,7 +348,7 @@ pub const RunCommand = struct { child_process.stdout_behavior = .Inherit; if (Environment.isWindows) { - try @import("../child_process_windows.zig").spawnWindows(&child_process); + try bun.WindowsSpawnWorkaround.spawnWindows(&child_process); } else { try child_process.spawn(); } @@ -434,7 +434,13 @@ pub const RunCommand = struct { child_process.stdout_behavior = .Inherit; const silent = ctx.debug.silent; - const result = child_process.spawnAndWait() catch |err| { + if (Environment.isWindows) { + try bun.WindowsSpawnWorkaround.spawnWindows(&child_process); + } else { + try child_process.spawn(); + } + + const result = child_process.wait() catch |err| { if (err == error.AccessDenied) { if (comptime Environment.isPosix) { var stat = std.mem.zeroes(std.c.Stat);