aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-27 03:53:01 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-27 03:53:01 -0800
commitddca89f425e72dfdd8afa75a3a1d5b473cc2cc65 (patch)
treec9906ab93d7a1b4f6221fea76ac5d723134ae1b1
parent805e87eeb6a2c77a35c779f6d50cdbf49291f988 (diff)
downloadbun-ddca89f425e72dfdd8afa75a3a1d5b473cc2cc65.tar.gz
bun-ddca89f425e72dfdd8afa75a3a1d5b473cc2cc65.tar.zst
bun-ddca89f425e72dfdd8afa75a3a1d5b473cc2cc65.zip
🪦
-rw-r--r--src/bun.js/javascript.zig25
-rw-r--r--src/watcher.zig7
2 files changed, 29 insertions, 3 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 7ff935f0b..af8f9c501 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -2635,6 +2635,8 @@ pub const HotReloader = struct {
vm: *JSC.VirtualMachine,
verbose: bool = false,
+ tombstones: std.StringHashMapUnmanaged(*bun.fs.FileSystem.RealFS.EntriesOption) = .{},
+
pub const HotReloadTask = struct {
reloader: *HotReloader,
count: u8 = 0,
@@ -2719,6 +2721,14 @@ pub const HotReloader = struct {
}
}
+ fn putTombstone(this: *HotReloader, key: []const u8, value: *bun.fs.FileSystem.RealFS.EntriesOption) void {
+ this.tombstones.put(bun.default_allocator, key, value) catch unreachable;
+ }
+
+ fn getTombstone(this: *HotReloader, key: []const u8) ?*bun.fs.FileSystem.RealFS.EntriesOption {
+ return this.tombstones.get(key);
+ }
+
pub fn onFileUpdate(
this: *HotReloader,
events: []watcher.WatchEvent,
@@ -2786,7 +2796,13 @@ pub const HotReloader = struct {
const affected = brk: {
if (comptime Environment.isMac) {
- entries_option = rfs.entries.get(file_path);
+ if (rfs.entries.get(file_path)) |existing| {
+ this.putTombstone(file_path, existing);
+ entries_option = existing;
+ } else if (this.getTombstone(file_path)) |existing| {
+ entries_option = existing;
+ }
+
var affected_i: usize = 0;
// if a file descriptor is stale, we need to close it
@@ -2814,7 +2830,12 @@ pub const HotReloader = struct {
};
if (affected.len > 0 and !Environment.isMac) {
- entries_option = rfs.entries.get(file_path);
+ if (rfs.entries.get(file_path)) |existing| {
+ this.putTombstone(file_path, existing);
+ entries_option = existing;
+ } else if (this.getTombstone(file_path)) |existing| {
+ entries_option = existing;
+ }
}
resolver.bustDirCache(file_path);
diff --git a/src/watcher.zig b/src/watcher.zig
index 5f02652d2..954bd0aa3 100644
--- a/src/watcher.zig
+++ b/src/watcher.zig
@@ -108,10 +108,15 @@ pub const INotify = struct {
std.os.inotify_rm_watch(inotify_fd, wd);
}
+ var coalesce_interval: usize = 100_000;
pub fn init() !void {
std.debug.assert(!loaded_inotify);
loaded_inotify = true;
+ if (std.os.getenvZ("BUN_INOTIFY_COALESCE_INTERVAL")) |env| {
+ coalesce_interval = std.fmt.parseInt(usize, env, 10) catch 100_000;
+ }
+
inotify_fd = try std.os.inotify_init1(IN_CLOEXEC);
}
@@ -140,7 +145,7 @@ pub const INotify = struct {
.events = std.os.POLL.IN | std.os.POLL.ERR,
.revents = 0,
}};
- var timespec = std.os.timespec{ .tv_sec = 0, .tv_nsec = 100_000 };
+ var timespec = std.os.timespec{ .tv_sec = 0, .tv_nsec = coalesce_interval };
if ((std.os.ppoll(&fds, &timespec, null) catch 0) > 0) {
while (true) {
const new_rc = std.os.system.read(