Skip to content

Commit 7c97b3d

Browse files
authored
perf: when removed files we donot need rebuild the original module (#10648)
1 parent 1c39fb0 commit 7c97b3d

File tree

8 files changed

+55
-4
lines changed

8 files changed

+55
-4
lines changed

crates/rspack_core/src/compiler/make/cutout/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ impl Cutout {
7373
if module.depends_on(&files) {
7474
// add module id
7575
force_build_modules.insert(module.identifier());
76-
// process parent module id
76+
// process module dependencies
7777
for connect in module_graph.get_incoming_connections(&module.identifier()) {
78-
if let Some(original_module_identifier) = connect.original_module_identifier {
79-
force_build_modules.insert(original_module_identifier);
80-
}
78+
force_build_deps.insert(connect.dependency_id);
8179
}
8280
}
8381
}

packages/rspack-test-tools/src/processor/watch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ export class WatchStepProcessor<
340340
resolve(stats);
341341
});
342342
});
343+
// wait compiler to ready watch the files and diretories
344+
await new Promise(resolve => setTimeout(resolve, 100));
343345
copyDiff(
344346
path.join(context.getSource(), this._watchOptions.stepName),
345347
this._watchOptions.tempDir,

packages/rspack-test-tools/tests/watchCases/compilation/remove-module/0/foo.js

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import("./foo.js").catch(() => {
2+
3+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = [
2+
/Module not found: Can't resolve/
3+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DELETE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function (source) {
2+
this._module.buildInfo.timestamp = Date.now();
3+
return source;
4+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require("path");
2+
3+
class Plugin {
4+
apply(compiler) {
5+
const moduleMap = new Map();
6+
7+
compiler.hooks.compilation.tap("PLUGIN", compilation => {
8+
compilation.hooks.finishModules.tap("PLUGIN", modules => {
9+
for (const module of modules) {
10+
if (moduleMap.has(module.resource)) {
11+
const timestamp = moduleMap.get(module.resource);
12+
// index.js only run loader by once.
13+
expect(module.buildInfo.timestamp).toBe(timestamp);
14+
} else {
15+
moduleMap.set(module.resource, module.buildInfo.timestamp);
16+
}
17+
}
18+
});
19+
});
20+
}
21+
}
22+
23+
module.exports = {
24+
plugins: [
25+
new Plugin()
26+
],
27+
module: {
28+
rules: [
29+
{
30+
test: /\.js$/,
31+
use: [
32+
{
33+
loader: path.join(__dirname, "loader.js"),
34+
}
35+
]
36+
}
37+
]
38+
}
39+
};
40+

0 commit comments

Comments
 (0)