From ee0af66e4a332e622ff45bacea5663f1b08d5627 Mon Sep 17 00:00:00 2001 From: RiskyMH Date: Fri, 25 Jul 2025 04:46:30 +1000 Subject: [PATCH] i dont like windows anymore --- src/cli/node_command.zig | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/cli/node_command.zig b/src/cli/node_command.zig index 99d7977bfa..de13ec06f0 100644 --- a/src/cli/node_command.zig +++ b/src/cli/node_command.zig @@ -522,7 +522,13 @@ pub const NodeCommand = struct { const version_binary = try std.fmt.allocPrintZ(allocator, "{s}/" ++ node_binary_name, .{version_dir}); defer allocator.free(version_binary); - if (bun.sys.access(version_binary, 0) == .result) { + const access_result = if (Env.isWindows) blk: { + var buf: bun.OSPathBuffer = undefined; + const path = bun.strings.toWPathNormalized(&buf, version_binary); + break :blk bun.sys.access(path, 0); + } else bun.sys.access(version_binary, 0); + + if (access_result == .result) { if (set_as_default) { Output.prettyln(" Node.js v{s} is already installed", .{version}); } @@ -567,7 +573,13 @@ pub const NodeCommand = struct { const version_binary = try std.fmt.allocPrintZ(allocator, "{s}/node-{s}/" ++ node_binary_name, .{ cache_dir, version }); defer allocator.free(version_binary); - if (bun.sys.access(version_binary, 0) != .result) { + const access_result2 = if (Env.isWindows) blk: { + var buf: bun.OSPathBuffer = undefined; + const path = bun.strings.toWPathNormalized(&buf, version_binary); + break :blk bun.sys.access(path, 0); + } else bun.sys.access(version_binary, 0); + + if (access_result2 != .result) { const version_dir = try std.fmt.allocPrint(allocator, "{s}/node-{s}", .{ cache_dir, version }); defer allocator.free(version_dir); @@ -720,7 +732,13 @@ pub const NodeCommand = struct { const version_binaryZ3 = try allocator.dupeZ(u8, version_binary); defer allocator.free(version_binaryZ3); - if (bun.sys.access(version_binaryZ3, 0) == .result) { + const access_result3 = if (Env.isWindows) blk: { + var buf: bun.OSPathBuffer = undefined; + const path = bun.strings.toWPathNormalized(&buf, version_binary); + break :blk bun.sys.access(path, 0); + } else bun.sys.access(version_binaryZ3, 0); + + if (access_result3 == .result) { try runNode(allocator, version_binary, args); } else { try installNodeVersion(ctx, version_spec, false); @@ -737,7 +755,13 @@ pub const NodeCommand = struct { const node_symlink = try std.fs.path.joinZ(allocator, &.{ bin_dir, node_binary_name }); defer allocator.free(node_symlink); - if (bun.sys.access(node_symlink, 0) == .result) { + const access_result4 = if (Env.isWindows) blk: { + var buf: bun.OSPathBuffer = undefined; + const path = bun.strings.toWPathNormalized(&buf, node_symlink); + break :blk bun.sys.access(path, 0); + } else bun.sys.access(node_symlink, 0); + + if (access_result4 == .result) { try runNode(allocator, node_symlink, args); return; } @@ -896,7 +920,13 @@ pub const NodeCommand = struct { } else if (entry.len > 0) { const test_node = try std.fs.path.joinZ(allocator, &.{ entry, "node" }); defer allocator.free(test_node); - if (bun.sys.access(test_node, 0) == .result) { + const access_result5 = if (Env.isWindows) blk: { + var buf: bun.OSPathBuffer = undefined; + const path = bun.strings.toWPathNormalized(&buf, test_node); + break :blk bun.sys.access(path, 0); + } else bun.sys.access(test_node, 0); + + if (access_result5 == .result) { found_other_dir = true; } }