mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
🪦
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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, ×pec, null) catch 0) > 0) {
|
||||
while (true) {
|
||||
const new_rc = std.os.system.read(
|
||||
|
||||
Reference in New Issue
Block a user