diff options
author | 2021-12-28 02:46:50 -0800 | |
---|---|---|
committer | 2021-12-28 02:46:50 -0800 | |
commit | 471f9aec1966ef1fd73d2b71e29a020910c87d88 (patch) | |
tree | 1b6ad2df2b0d4af8c5de1bf23f37e85acfa4fa74 /src | |
parent | b5beb20e0828a6d6995df8c43af24f7b02ab402c (diff) | |
download | bun-471f9aec1966ef1fd73d2b71e29a020910c87d88.tar.gz bun-471f9aec1966ef1fd73d2b71e29a020910c87d88.tar.zst bun-471f9aec1966ef1fd73d2b71e29a020910c87d88.zip |
[bun run] Fix bug with absolute paths to js-like files
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/run_command.zig | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index ce4b9fcc7..9dd1570c5 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -560,20 +560,28 @@ pub const RunCommand = struct { possibly_open_with_bun_js: { if (options.defaultLoaders.get(std.fs.path.extension(script_name_to_search))) |loader| { if (loader.isJavaScriptLike()) { - const cwd = std.os.getcwd(&path_buf) catch break :possibly_open_with_bun_js; - path_buf[cwd.len] = std.fs.path.sep; - var parts = [_]string{script_name_to_search}; - var file_path = resolve_path.joinAbsStringBuf( - path_buf[0 .. cwd.len + 1], - &path_buf2, - &parts, - .auto, - ); - if (file_path.len == 0) break :possibly_open_with_bun_js; - path_buf2[file_path.len] = 0; - var file_pathZ = path_buf2[0..file_path.len :0]; - - var file = std.fs.openFileAbsoluteZ(file_pathZ, .{ .read = true }) catch break :possibly_open_with_bun_js; + var file_path = script_name_to_search; + const file_: std.fs.File.OpenError!std.fs.File = brk: { + if (script_name_to_search[0] == std.fs.path.sep) { + break :brk std.fs.openFileAbsolute(script_name_to_search, .{ .read = true }); + } else { + const cwd = std.os.getcwd(&path_buf) catch break :possibly_open_with_bun_js; + path_buf[cwd.len] = std.fs.path.sep; + var parts = [_]string{script_name_to_search}; + file_path = resolve_path.joinAbsStringBuf( + path_buf[0 .. cwd.len + 1], + &path_buf2, + &parts, + .auto, + ); + if (file_path.len == 0) break :possibly_open_with_bun_js; + path_buf2[file_path.len] = 0; + var file_pathZ = path_buf2[0..file_path.len :0]; + break :brk std.fs.openFileAbsoluteZ(file_pathZ, .{ .read = true }); + } + }; + + const file = file_ catch break :possibly_open_with_bun_js; // "White space after #! is optional." var shebang_buf: [64]u8 = undefined; const shebang_size = file.pread(&shebang_buf, 0) catch |err| { |