aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bundler/bundle_v2.zig13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig
index 9cd7e3187..1ef06c94c 100644
--- a/src/bundler/bundle_v2.zig
+++ b/src/bundler/bundle_v2.zig
@@ -2014,7 +2014,7 @@ pub const BundleV2 = struct {
}
if (this.bun_watcher != null) {
- if (empty_result.watcher_data.fd > 0) {
+ if (empty_result.watcher_data.fd > 0 and empty_result.watcher_data.fd != bun.invalid_fd) {
this.bun_watcher.?.addFile(
empty_result.watcher_data.fd,
input_files.items(.source)[empty_result.source_index.get()].path.text,
@@ -2033,7 +2033,7 @@ pub const BundleV2 = struct {
{
// to minimize contention, we add watcher here
if (this.bun_watcher != null) {
- if (result.watcher_data.fd > 0) {
+ if (result.watcher_data.fd > 0 and result.watcher_data.fd != bun.invalid_fd) {
this.bun_watcher.?.addFile(
result.watcher_data.fd,
result.source.path.text,
@@ -2477,7 +2477,12 @@ pub const ParseTask = struct {
errdefer if (task.contents_or_fd == .fd) entry.deinit(allocator);
- if (entry.fd > 2) task.contents_or_fd = .{
+ const will_close_file_descriptor = task.contents_or_fd == .fd and entry.fd > 2 and this.ctx.bun_watcher == null;
+ if (will_close_file_descriptor) {
+ _ = JSC.Node.Syscall.close(entry.fd);
+ }
+
+ if (!will_close_file_descriptor and entry.fd > 2) task.contents_or_fd = .{
.fd = .{
.file = entry.fd,
.dir = bun.invalid_fd,
@@ -2566,7 +2571,7 @@ pub const ParseTask = struct {
0,
.watcher_data = .{
- .fd = if (task.contents_or_fd == .fd) task.contents_or_fd.fd.file else 0,
+ .fd = if (task.contents_or_fd == .fd and !will_close_file_descriptor) task.contents_or_fd.fd.file else 0,
.dir_fd = if (task.contents_or_fd == .fd) task.contents_or_fd.fd.dir else 0,
},
};