aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/event_loop.zig29
-rw-r--r--src/bun.js/javascript.zig7
-rw-r--r--src/bun.js/module_loader.zig69
3 files changed, 74 insertions, 31 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index 8dbf5abfd..6928cd2b8 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -363,6 +363,7 @@ pub const EventLoop = struct {
waker: ?AsyncIO.Waker = null,
start_server_on_next_tick: bool = false,
defer_count: std.atomic.Atomic(usize) = std.atomic.Atomic(usize).init(0),
+ forever_timer: ?*uws.Timer = null,
pub const Queue = std.fifo.LinearFifo(Task, .Dynamic);
@@ -498,6 +499,34 @@ pub const EventLoop = struct {
}
}
+ pub fn tickPossiblyForever(this: *EventLoop) void {
+ var ctx = this.virtual_machine;
+ var loop = ctx.uws_event_loop.?;
+
+ const pending_unref = ctx.pending_unref_counter;
+ if (pending_unref > 0) {
+ ctx.pending_unref_counter = 0;
+ loop.unrefCount(pending_unref);
+ }
+
+ if (loop.num_polls == 0 or loop.active == 0) {
+ if (this.forever_timer == null) {
+ var t = uws.Timer.create(loop, this);
+ t.set(this, &noopForeverTimer, 1000 * 60 * 4, 1000 * 60 * 4);
+ this.forever_timer = t;
+ }
+ }
+
+ loop.tick();
+ this.processGCTimer();
+ this.tickConcurrent();
+ this.tick();
+ }
+
+ fn noopForeverTimer(_: *uws.Timer) callconv(.C) void {
+ // do nothing
+ }
+
pub fn autoTickActive(this: *EventLoop) void {
var loop = this.virtual_machine.uws_event_loop.?;
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 3841a07e2..39cead99f 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -364,6 +364,8 @@ pub const VirtualMachine = struct {
preload: []const string = &[_][]const u8{},
unhandled_pending_rejection_to_capture: ?*JSC.JSValue = null,
+ hot_reload: bun.CLI.Command.HotReload = .none,
+
/// hide bun:wrap from stack traces
/// bun:wrap is very noisy
hide_bun_stackframes: bool = true,
@@ -552,6 +554,11 @@ pub const VirtualMachine = struct {
pub fn reload(this: *VirtualMachine) void {
Output.debug("Reloading...", .{});
+ if (this.hot_reload == .watch) {
+ Output.flush();
+ bun.reloadProcess(bun.default_allocator, !strings.eqlComptime(this.bundler.env.map.get("BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD") orelse "0", "true"));
+ }
+
this.global.reload();
this.pending_internal_promise = this.reloadEntryPoint(this.main) catch @panic("Failed to reload");
}
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index adfa88cb1..e9a4bb2c2 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -931,13 +931,14 @@ pub const ModuleLoader = struct {
jsc_vm.bundler.options.macro_remap;
var fallback_source: logger.Source = undefined;
-
+ var input_file_fd: StoredFileDescriptorType = 0;
var parse_options = Bundler.ParseOptions{
.allocator = allocator,
.path = path,
.loader = loader,
.dirname_fd = 0,
.file_descriptor = fd,
+ .file_fd_ptr = &input_file_fd,
.file_hash = hash,
.macro_remappings = macro_remappings,
.jsx = jsc_vm.bundler.options.jsx,
@@ -962,6 +963,24 @@ pub const ModuleLoader = struct {
null,
disable_transpilying,
) orelse {
+ if (comptime !disable_transpilying) {
+ 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")) {
+ jsc_vm.bun_watcher.?.addFile(
+ input_file_fd,
+ path.text,
+ hash,
+ loader,
+ 0,
+ package_json,
+ true,
+ ) catch {};
+ }
+ }
+ }
+ }
+
return error.ParseError;
};
@@ -984,6 +1003,24 @@ pub const ModuleLoader = struct {
return wasm_result;
}
+ if (comptime !disable_transpilying) {
+ 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")) {
+ jsc_vm.bun_watcher.?.addFile(
+ input_file_fd,
+ path.text,
+ hash,
+ loader,
+ 0,
+ package_json,
+ true,
+ ) catch {};
+ }
+ }
+ }
+ }
+
if (jsc_vm.bundler.log.errors > 0) {
return error.ParseError;
}
@@ -1026,22 +1063,6 @@ pub const ModuleLoader = struct {
return error.UnexpectedPendingResolution;
}
- if (jsc_vm.isWatcherEnabled()) {
- if (parse_result.input_fd) |fd_| {
- if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) {
- jsc_vm.bun_watcher.?.addFile(
- fd_,
- path.text,
- hash,
- loader,
- 0,
- package_json,
- true,
- ) catch {};
- }
- }
- }
-
if (parse_result.source.contents_is_recycled) {
// this shared buffer is about to become owned by the AsyncModule struct
jsc_vm.bundler.resolver.caches.fs.resetSharedBuffer(
@@ -1110,20 +1131,6 @@ pub const ModuleLoader = struct {
if (jsc_vm.isWatcherEnabled()) {
const resolved_source = jsc_vm.refCountedResolvedSource(printer.ctx.written, display_specifier, path.text, null);
- if (parse_result.input_fd) |fd_| {
- if (jsc_vm.bun_watcher != null and !is_node_override and std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules")) {
- jsc_vm.bun_watcher.?.addFile(
- fd_,
- path.text,
- hash,
- loader,
- 0,
- package_json,
- true,
- ) catch {};
- }
- }
-
return resolved_source;
}