aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/module_loader.zig19
-rw-r--r--src/watcher.zig1
-rw-r--r--test/cli/hot/hot-runner-root.js1
-rw-r--r--test/cli/hot/hot.test.ts13
4 files changed, 29 insertions, 5 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index 0e4cb5ba2..4763ed1bc 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -450,6 +450,25 @@ pub const RuntimeTranspilerStore = struct {
return;
};
+ if (vm.isWatcherEnabled()) {
+ if (input_file_fd != 0) {
+ if (vm.bun_watcher != null and !is_node_override and
+ std.fs.path.isAbsolute(path.text) and !strings.contains(path.text, "node_modules"))
+ {
+ should_close_input_file_fd = false;
+ vm.bun_watcher.?.addFile(
+ input_file_fd,
+ path.text,
+ hash,
+ loader,
+ 0,
+ package_json,
+ true,
+ ) catch {};
+ }
+ }
+ }
+
for (parse_result.ast.import_records.slice()) |*import_record_| {
var import_record: *bun.ImportRecord = import_record_;
diff --git a/src/watcher.zig b/src/watcher.zig
index 9bc61b3af..a31267c5f 100644
--- a/src/watcher.zig
+++ b/src/watcher.zig
@@ -693,6 +693,7 @@ pub fn NewWatcher(comptime ContextType: type) type {
package_json: ?*PackageJSON,
comptime copy_file_path: bool,
) !void {
+ // This must lock due to concurrent transpiler
this.mutex.lock();
defer this.mutex.unlock();
diff --git a/test/cli/hot/hot-runner-root.js b/test/cli/hot/hot-runner-root.js
new file mode 100644
index 000000000..351ef5a65
--- /dev/null
+++ b/test/cli/hot/hot-runner-root.js
@@ -0,0 +1 @@
+import "./hot-runner";
diff --git a/test/cli/hot/hot.test.ts b/test/cli/hot/hot.test.ts
index 63cc3b064..50a38ac68 100644
--- a/test/cli/hot/hot.test.ts
+++ b/test/cli/hot/hot.test.ts
@@ -2,9 +2,12 @@ import { spawn } from "bun";
import { expect, it } from "bun:test";
import { bunExe, bunEnv } from "harness";
import { readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "fs";
+import { join } from "path";
+
+const hotRunnerRoot = join(import.meta.dir, "/hot-runner-root.js");
it("should hot reload when file is overwritten", async () => {
- const root = import.meta.dir + "/hot-runner.js";
+ const root = hotRunnerRoot;
const runner = spawn({
cmd: [bunExe(), "--hot", "run", root],
env: bunEnv,
@@ -43,7 +46,7 @@ it("should hot reload when file is overwritten", async () => {
});
it("should recover from errors", async () => {
- const root = import.meta.dir + "/hot-runner.js";
+ const root = hotRunnerRoot;
const runner = spawn({
cmd: [bunExe(), "--hot", "run", root],
env: bunEnv,
@@ -111,7 +114,7 @@ it("should recover from errors", async () => {
});
it("should not hot reload when a random file is written", async () => {
- const root = import.meta.dir + "/hot-runner.js";
+ const root = hotRunnerRoot;
const runner = spawn({
cmd: [bunExe(), "--hot", "run", root],
env: bunEnv,
@@ -165,7 +168,7 @@ it("should not hot reload when a random file is written", async () => {
});
it("should hot reload when a file is deleted and rewritten", async () => {
- const root = import.meta.dir + "/hot-runner.js";
+ const root = hotRunnerRoot;
const runner = spawn({
cmd: [bunExe(), "--hot", "run", root],
env: bunEnv,
@@ -206,7 +209,7 @@ it("should hot reload when a file is deleted and rewritten", async () => {
});
it("should hot reload when a file is renamed() into place", async () => {
- const root = import.meta.dir + "/hot-runner.js";
+ const root = hotRunnerRoot;
const runner = spawn({
cmd: [bunExe(), "--hot", "run", root],
env: bunEnv,