diff options
-rw-r--r-- | src/bun.js/javascript.zig | 3 | ||||
-rw-r--r-- | src/bun_js.zig | 11 | ||||
-rw-r--r-- | src/cli/test_command.zig | 18 | ||||
-rw-r--r-- | src/http.zig | 1 | ||||
-rw-r--r-- | src/js_ast.zig | 9 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 4 |
6 files changed, 36 insertions, 10 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 06f833e3b..9f0e1841d 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -729,6 +729,7 @@ pub const VirtualMachine = struct { existing_bundle: ?*NodeModuleBundle, _log: ?*logger.Log, env_loader: ?*DotEnv.Loader, + store_fd: bool, ) !*VirtualMachine { var log: *logger.Log = undefined; if (_log) |__log| { @@ -748,7 +749,6 @@ pub const VirtualMachine = struct { existing_bundle, env_loader, ); - var vm = VMHolder.vm.?; vm.* = VirtualMachine{ @@ -781,6 +781,7 @@ pub const VirtualMachine = struct { vm.event_loop = &vm.regular_event_loop; vm.bundler.macro_context = null; + vm.bundler.resolver.store_fd = store_fd; vm.bundler.resolver.onWakePackageManager = .{ .context = &vm.modules, diff --git a/src/bun_js.zig b/src/bun_js.zig index af1dda3d9..5b1f73386 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -58,7 +58,14 @@ pub const Run = struct { } run = .{ - .vm = try VirtualMachine.init(arena.allocator(), ctx.args, null, ctx.log, null), + .vm = try VirtualMachine.init( + arena.allocator(), + ctx.args, + null, + ctx.log, + null, + ctx.debug.hot_reload != .none, + ), .file = file, .arena = arena, .ctx = ctx, @@ -93,8 +100,6 @@ pub const Run = struct { b.options.macro_remap = macros; } - b.resolver.store_fd = ctx.debug.hot_reload != .none; - b.configureRouter(false) catch { if (Output.enable_ansi_colors_stderr) { vm.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), true) catch {}; diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index b5ab42672..4ae14dd26 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -252,6 +252,7 @@ const Scanner = struct { if (@as(FileSystem.RealFS.EntriesOption.Tag, root.*) == .entries) { var iter = root.entries.data.iterator(); const fd = root.entries.fd; + std.debug.assert(fd != 0); while (iter.next()) |entry| { this.next(entry.value_ptr.*, fd); } @@ -260,6 +261,8 @@ const Scanner = struct { while (this.dirs_to_scan.readItem()) |entry| { var dir = std.fs.Dir{ .fd = entry.relative_dir }; + std.debug.assert(dir.fd != 0); + var parts2 = &[_]string{ entry.dir_path, entry.name.slice() }; var path2 = this.fs.absBuf(parts2, &this.open_dir_buf); this.open_dir_buf[path2.len] = 0; @@ -400,10 +403,21 @@ pub const TestCommand = struct { js_ast.Expr.Data.Store.create(default_allocator); js_ast.Stmt.Data.Store.create(default_allocator); - var vm = try JSC.VirtualMachine.init(ctx.allocator, ctx.args, null, ctx.log, env_loader); + var vm = try JSC.VirtualMachine.init( + ctx.allocator, + ctx.args, + null, + ctx.log, + env_loader, + // we must store file descriptors because we reuse them for + // iterating through the directory tree recursively + // + // in the future we should investigate if refactoring this to not + // rely on the dir fd yields a performance improvement + true, + ); vm.argv = ctx.passthrough; vm.preload = ctx.preloads; - vm.bundler.resolver.store_fd = true; try vm.bundler.configureDefines(); vm.bundler.options.rewrite_jest_for_tests = true; diff --git a/src/http.zig b/src/http.zig index cf58e5941..a01fd3e1a 100644 --- a/src/http.zig +++ b/src/http.zig @@ -1470,6 +1470,7 @@ pub const RequestContext = struct { null, handler.log, handler.env_loader, + true, ) catch |err| { handler.handleJSError(.create_vm, err) catch {}; javascript_disabled = true; diff --git a/src/js_ast.zig b/src/js_ast.zig index cf432e9f2..224971a5c 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -9519,7 +9519,14 @@ pub const Macro = struct { resolver.opts.transform_options.node_modules_bundle_path = null; resolver.opts.transform_options.node_modules_bundle_path_server = null; defer resolver.opts.transform_options = old_transform_options; - var _vm = try JavaScript.VirtualMachine.init(default_allocator, resolver.opts.transform_options, null, log, env); + var _vm = try JavaScript.VirtualMachine.init( + default_allocator, + resolver.opts.transform_options, + null, + log, + env, + false, + ); _vm.enableMacroMode(); _vm.eventLoop().ensureWaker(); diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index bbbaec81d..01c37c632 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -2612,9 +2612,7 @@ pub const Resolver = struct { if (in_place) |existing| { existing.data.clearAndFree(allocator); } - if (!r.store_fd) { - new_entry.fd = 0; - } + new_entry.fd = if (r.store_fd) open_dir.dir.fd else 0; var dir_entries_ptr = in_place orelse allocator.create(Fs.FileSystem.DirEntry) catch unreachable; dir_entries_ptr.* = new_entry; dir_entries_option = try rfs.entries.put(&cached_dir_entry_result, .{ |