diff options
| -rw-r--r-- | src/bun.js/javascript.zig | 2 | ||||
| -rw-r--r-- | src/bun.js/module_loader.zig | 17 | 
2 files changed, 18 insertions, 1 deletions
| diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index 572b66716..b696c6cf2 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -2065,7 +2065,7 @@ pub const VirtualMachine = struct {          )) |mapping| {              var log = logger.Log.init(default_allocator);              var errorable: ErrorableResolvedSource = undefined; -            var original_source = fetchWithoutOnLoadPlugins(this, this.global, bun.String.init(top.source_url), bun.String.empty, &log, &errorable, .print_source) catch return; +            var original_source = fetchWithoutOnLoadPlugins(this, this.global, top.source_url, bun.String.empty, &log, &errorable, .print_source) catch return;              const code = original_source.source_code.toUTF8(bun.default_allocator);              defer code.deinit(); diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index 6fd4fef99..e7e4d700e 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -982,6 +982,14 @@ pub const ModuleLoader = struct {                      jsc_vm.bundler.options.macro_remap;                  var fallback_source: logger.Source = undefined; + +                // Usually, we want to close the input file automatically. +                // +                // If we're re-using the file descriptor from the fs watcher +                // Do not close it because that will break the kqueue-based watcher +                // +                var should_close_input_file_fd = fd == null; +                  var input_file_fd: StoredFileDescriptorType = 0;                  var parse_options = Bundler.ParseOptions{                      .allocator = allocator, @@ -1002,6 +1010,13 @@ pub const ModuleLoader = struct {                          jsc_vm.main_hash == hash and                          strings.eqlLong(jsc_vm.main, path.text, false),                  }; +                defer { +                    if (should_close_input_file_fd and input_file_fd != 0) { +                        _ = bun.JSC.Node.Syscall.close(input_file_fd); +                        input_file_fd = 0; +                    } +                } +                  if (is_node_override) {                      if (NodeFallbackModules.contentsFromPath(specifier)) |code| {                          const fallback_path = Fs.Path.initWithNamespace(specifier, "node"); @@ -1019,6 +1034,7 @@ pub const ModuleLoader = struct {                          if (jsc_vm.isWatcherEnabled()) {                              if (input_file_fd != 0) {                                  if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) { +                                    should_close_input_file_fd = false;                                      jsc_vm.bun_watcher.?.addFile(                                          input_file_fd,                                          path.text, @@ -1059,6 +1075,7 @@ pub const ModuleLoader = struct {                      if (jsc_vm.isWatcherEnabled()) {                          if (input_file_fd != 0) {                              if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) { +                                should_close_input_file_fd = false;                                  jsc_vm.bun_watcher.?.addFile(                                      input_file_fd,                                      path.text, | 
