aboutsummaryrefslogtreecommitdiff
path: root/src/api/schema.zig
diff options
context:
space:
mode:
authorGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-01-01 01:53:50 -0800
committerGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-01-01 01:53:50 -0800
commita17088363f16fc72562994ed01555841c7c1b1ac (patch)
tree27cb1685eb1ce676476797f7076dd46e2bac5d9c /src/api/schema.zig
parent83004f0a0a51658a50499256a874558f26e09a24 (diff)
downloadbun-a17088363f16fc72562994ed01555841c7c1b1ac.tar.gz
bun-a17088363f16fc72562994ed01555841c7c1b1ac.tar.zst
bun-a17088363f16fc72562994ed01555841c7c1b1ac.zip
[bun dev] Improve filesystem watcher & HMR reliability (Linux + a little macOS)
Text editors like Replit save through atomic file updates. In an inotify filesystem watcher (Linux), that appears to be a delete followed by moving the file to the directory. Now when known files are moved into a directory, the watcher sends the file change notification to the browser(s). From there, the browser looks at it's files to determine whether or not Additionally, if an existing HMR connection does not know about a file ID passed to it, it asks the browser to reply with the file path and then starts watching that file. This improves HMR reliabiality if Bun had been restarted but the page hadn't been restarted.
Diffstat (limited to 'src/api/schema.zig')
-rw-r--r--src/api/schema.zig133
1 files changed, 19 insertions, 114 deletions
diff --git a/src/api/schema.zig b/src/api/schema.zig
index 2238ea3f0..8a850c8f1 100644
--- a/src/api/schema.zig
+++ b/src/api/schema.zig
@@ -2338,6 +2338,12 @@ pub const Api = struct {
/// manifest_fail
manifest_fail,
+ /// resolve_file
+ resolve_file,
+
+ /// file_change_notification_with_hint
+ file_change_notification_with_hint,
+
_,
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
@@ -2353,6 +2359,9 @@ pub const Api = struct {
/// manifest
manifest,
+ /// build_with_file_path
+ build_with_file_path,
+
_,
pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
@@ -2553,144 +2562,40 @@ pub const Api = struct {
}
};
- pub const DependencyManifest = struct {
- /// ids
- ids: []const u32,
-
- pub fn decode(reader: anytype) anyerror!DependencyManifest {
- var this = std.mem.zeroes(DependencyManifest);
-
- this.ids = try reader.readArray(u32);
- return this;
- }
-
- pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
- try writer.writeArray(u32, this.ids);
- }
- };
-
- pub const FileList = struct {
- /// ptrs
- ptrs: []const StringPointer,
-
- /// files
- files: []const u8,
-
- pub fn decode(reader: anytype) anyerror!FileList {
- var this = std.mem.zeroes(FileList);
-
- this.ptrs = try reader.readArray(StringPointer);
- this.files = try reader.readValue([]const u8);
- return this;
- }
-
- pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
- try writer.writeArray(StringPointer, this.ptrs);
- try writer.writeValue(@TypeOf(this.files), this.files);
- }
- };
-
- pub const WebsocketMessageResolveIDs = struct {
- /// id
- id: []const u32,
-
- /// list
- list: FileList,
-
- pub fn decode(reader: anytype) anyerror!WebsocketMessageResolveIDs {
- var this = std.mem.zeroes(WebsocketMessageResolveIDs);
-
- this.id = try reader.readArray(u32);
- this.list = try reader.readValue(FileList);
- return this;
- }
-
- pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
- try writer.writeArray(u32, this.id);
- try writer.writeValue(@TypeOf(this.list), this.list);
- }
- };
-
- pub const WebsocketCommandResolveIDs = struct {
- /// ptrs
- ptrs: []const StringPointer,
-
- /// files
- files: []const u8,
-
- pub fn decode(reader: anytype) anyerror!WebsocketCommandResolveIDs {
- var this = std.mem.zeroes(WebsocketCommandResolveIDs);
-
- this.ptrs = try reader.readArray(StringPointer);
- this.files = try reader.readValue([]const u8);
- return this;
- }
-
- pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
- try writer.writeArray(StringPointer, this.ptrs);
- try writer.writeValue(@TypeOf(this.files), this.files);
- }
- };
-
- pub const WebsocketMessageManifestSuccess = struct {
+ pub const WebsocketCommandBuildWithFilePath = struct {
/// id
id: u32 = 0,
- /// module_path
- module_path: []const u8,
+ /// file_path
+ file_path: []const u8,
- /// loader
- loader: Loader,
-
- /// manifest
- manifest: DependencyManifest,
-
- pub fn decode(reader: anytype) anyerror!WebsocketMessageManifestSuccess {
- var this = std.mem.zeroes(WebsocketMessageManifestSuccess);
+ pub fn decode(reader: anytype) anyerror!WebsocketCommandBuildWithFilePath {
+ var this = std.mem.zeroes(WebsocketCommandBuildWithFilePath);
this.id = try reader.readValue(u32);
- this.module_path = try reader.readValue([]const u8);
- this.loader = try reader.readValue(Loader);
- this.manifest = try reader.readValue(DependencyManifest);
+ this.file_path = try reader.readValue([]const u8);
return this;
}
pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
try writer.writeInt(this.id);
- try writer.writeValue(@TypeOf(this.module_path), this.module_path);
- try writer.writeEnum(this.loader);
- try writer.writeValue(@TypeOf(this.manifest), this.manifest);
+ try writer.writeValue(@TypeOf(this.file_path), this.file_path);
}
};
- pub const WebsocketMessageManifestFailure = struct {
+ pub const WebsocketMessageResolveId = packed struct {
/// id
id: u32 = 0,
- /// from_timestamp
- from_timestamp: u32 = 0,
-
- /// loader
- loader: Loader,
-
- /// log
- log: Log,
-
- pub fn decode(reader: anytype) anyerror!WebsocketMessageManifestFailure {
- var this = std.mem.zeroes(WebsocketMessageManifestFailure);
+ pub fn decode(reader: anytype) anyerror!WebsocketMessageResolveId {
+ var this = std.mem.zeroes(WebsocketMessageResolveId);
this.id = try reader.readValue(u32);
- this.from_timestamp = try reader.readValue(u32);
- this.loader = try reader.readValue(Loader);
- this.log = try reader.readValue(Log);
return this;
}
pub fn encode(this: *const @This(), writer: anytype) anyerror!void {
try writer.writeInt(this.id);
- try writer.writeInt(this.from_timestamp);
- try writer.writeEnum(this.loader);
- try writer.writeValue(@TypeOf(this.log), this.log);
}
};
};