Compare commits

...

1 Commits

Author SHA1 Message Date
Don Isaac
82dfec9c95 fix: invalid cwd when running bytecode 2025-04-20 19:37:04 -04:00
2 changed files with 12 additions and 6 deletions

View File

@@ -88,11 +88,11 @@ pub const FD = packed struct(backing_int) {
}
pub fn fromStdFile(file: std.fs.File) FD {
return .fromNative(file.handle);
return FD.fromNative(file.handle);
}
pub fn fromStdDir(dir: std.fs.Dir) FD {
return .fromNative(dir.fd);
return FD.fromNative(dir.fd);
}
pub fn stdFile(fd: FD) std.fs.File {
@@ -120,6 +120,7 @@ pub const FD = packed struct(backing_int) {
},
};
}
pub fn unwrapValid(fd: FD) ?FD {
return if (fd.isValid()) fd else null;
}
@@ -127,7 +128,7 @@ pub const FD = packed struct(backing_int) {
/// When calling fd function, you may not be able to close the returned fd.
/// To close the fd, you have to call `.close()` on the `bun.FD`.
pub fn native(fd: FD) fd_t {
if (Environment.isDebug and !@inComptime()) bun.assert(fd.isValid());
if (!@inComptime()) bun.assertf(fd.isValid(), "Cannot convert invalid fd to native", .{});
return switch (os) {
else => fd.value.as_system,
.windows => switch (fd.decodeWindows()) {
@@ -149,7 +150,7 @@ pub const FD = packed struct(backing_int) {
if (isStdioHandle(std.os.windows.STD_INPUT_HANDLE, handle)) return 0;
if (isStdioHandle(std.os.windows.STD_OUTPUT_HANDLE, handle)) return 1;
if (isStdioHandle(std.os.windows.STD_ERROR_HANDLE, handle)) return 2;
std.debug.panic(
bun.Output.panic(
\\Cast bun.FD.uv({}) makes closing impossible!
\\
\\The supplier of fd FD should call 'FD.makeLibUVOwned',

View File

@@ -1207,11 +1207,16 @@ pub const Transpiler = struct {
var path_buf2: bun.PathBuffer = undefined;
@memcpy(path_buf2[0..path.text.len], path.text);
path_buf2[path.text.len..][0..bun.bytecode_extension.len].* = bun.bytecode_extension.*;
const bytecode = bun.sys.File.toSourceAt(dirname_fd, path_buf2[0 .. path.text.len + bun.bytecode_extension.len], bun.default_allocator).asValue() orelse break :brk default_value;
const bytecode_path = path_buf2[0 .. path.text.len + bun.bytecode_extension.len];
const dir_fd = dirname_fd.unwrapValid() orelse bun.FD.cwd();
const bytecode = bun.sys.File.toSourceAt(dir_fd, bytecode_path, bun.default_allocator).asValue() orelse break :brk default_value;
if (bytecode.contents.len == 0) {
break :brk default_value;
}
break :brk if (already_bundled == .bytecode_cjs) .{ .bytecode_cjs = @constCast(bytecode.contents) } else .{ .bytecode = @constCast(bytecode.contents) };
break :brk if (already_bundled == .bytecode_cjs)
.{ .bytecode_cjs = @constCast(bytecode.contents) }
else
.{ .bytecode = @constCast(bytecode.contents) };
}
break :brk default_value;
},