Skip to content

Commit d6ac6bc

Browse files
committed
feat: travse module graph
1 parent af6e4bc commit d6ac6bc

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

bench.config.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
export default {
22
jobs: [
3-
"10000_development-mode",
4-
"10000_development-mode_hmr",
3+
// "10000_development-mode",
4+
// "10000_development-mode_hmr",
55
"10000_production-mode",
6-
"10000_big_production-mode_disable-minimize",
7-
"arco-pro_development-mode",
8-
"arco-pro_development-mode_hmr",
9-
"arco-pro_production-mode",
10-
"arco-pro_production-mode_generate-package-json-webpack-plugin",
11-
"threejs_development-mode_10x",
12-
"threejs_development-mode_10x_hmr",
13-
"threejs_production-mode_10x"
6+
"10000_production-mode_traverse-module-graph",
7+
// "arco-pro_development-mode",
8+
// "arco-pro_development-mode_hmr",
9+
// "arco-pro_production-mode",
10+
// "arco-pro_production-mode_generate-package-json-webpack-plugin",
11+
// "threejs_development-mode_10x",
12+
// "threejs_development-mode_10x_hmr",
13+
// "threejs_production-mode_10x",
14+
// "10000_big_production-mode",
1415
],
1516
rspackDirectory: process.env.RSPACK_DIR
1617
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import path from "path";
2+
import { Addon } from "../common.js";
3+
4+
export default class extends Addon {
5+
options = {
6+
times: 10
7+
};
8+
async afterSetup(ctx) {
9+
ctx.config =
10+
ctx.config +
11+
`
12+
module.exports.plugins = module.exports.plugins || [];
13+
const TraverseModuleGraphPlugin = require("${path.join(__dirname, 'plugin.js')}");
14+
module.exports.plugins.push(new TraverseModuleGraphPlugin());
15+
`;
16+
}
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const PLUGIN_NAME = "TraverseModuleGraphPlugin";
2+
3+
class TraverseModuleGraphPlugin {
4+
apply(compiler) {
5+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
6+
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
7+
const entries = compilation.entries.values();
8+
9+
const visitedModules = new Set();
10+
11+
function traverse(dependency) {
12+
const module = compilation.moduleGraph.getModule(dependency);
13+
if (module) {
14+
visitedModules.add(module);
15+
for (const dep of module.dependencies) {
16+
traverse(dep)
17+
}
18+
}
19+
}
20+
21+
for (const entry of entries) {
22+
for (const dependency of entry.dependencies) {
23+
traverse(dependency)
24+
}
25+
}
26+
27+
console.log("Visited module number: ", visitedModules.size);
28+
});
29+
});
30+
}
31+
}
32+
33+
module.exports = TraverseModuleGraphPlugin;

0 commit comments

Comments
 (0)