Skip to content

Commit b083f77

Browse files
fix: extend modify event handling to include metadata changes (#11519)
1 parent fffd2f8 commit b083f77

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

crates/rspack_fs/src/watcher/disk_watcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ impl DiskWatcher {
4040

4141
let kind = match event.kind {
4242
EventKind::Create(_) => FsEventKind::Create,
43-
EventKind::Modify(ModifyKind::Data(_) | ModifyKind::Any | ModifyKind::Name(_)) => {
44-
FsEventKind::Change
45-
}
43+
EventKind::Modify(
44+
ModifyKind::Data(_) | ModifyKind::Any | ModifyKind::Name(_) | ModifyKind::Metadata(_),
45+
) => FsEventKind::Change,
4646
EventKind::Remove(_) => FsEventKind::Remove,
4747
// TODO: handle this case /path/to/index.js -> /path/to/index.js.map
4848
// path/to/index.js should be removed, and path/to/index.js.map should be changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const a = 1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// should not trigger rebuild
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require("node:path");
2+
const fs = require("node:fs");
3+
4+
class ShouldRebuildPlugin {
5+
constructor() {
6+
this.compileCount = 0;
7+
}
8+
apply(compiler) {
9+
const targetFile = path.resolve(compiler.context, "./index.js");
10+
11+
compiler.hooks.done.tap(ShouldRebuildPlugin.name, _ => {
12+
// After first compilation, touch the file to trigger a rebuild
13+
if (this.compileCount === 0) {
14+
setTimeout(() => {
15+
const now = new Date();
16+
fs.utimes(targetFile, now, now, err => {
17+
if (err) {
18+
console.error("Error updating file timestamps:", err);
19+
return;
20+
}
21+
// Touch file to trigger rebuild
22+
});
23+
}, 1000);
24+
}
25+
this.compileCount++;
26+
});
27+
}
28+
}
29+
30+
/**
31+
* @type {import('@rspack/core').Configuration}
32+
*/
33+
const config = {
34+
plugins: [new ShouldRebuildPlugin()],
35+
watchOptions: {
36+
aggregateTimeout: 1000
37+
}
38+
};
39+
40+
module.exports = config;

0 commit comments

Comments
 (0)