@zohodesk/client_build_tool 0.0.16-exp.6 → 0.0.16-exp.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,68 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
// plugins/ChunkHierarchyPlugin.js
|
|
4
|
-
const fs = require(
|
|
4
|
+
const fs = require("fs");
|
|
5
5
|
|
|
6
|
-
const path = require(
|
|
6
|
+
const path = require("path");
|
|
7
7
|
|
|
8
8
|
class ChunkHierarchyPlugin {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(outputFileName) {
|
|
10
|
+
this.outputFileName = outputFileName || "chunk-hierarchy-report.json";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
apply(compiler) {
|
|
14
|
-
compiler.hooks.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
compiler.hooks.afterEmit.tap("ChunkHierarchyPlugin", compilation => {
|
|
15
|
+
try {
|
|
16
|
+
const {
|
|
17
|
+
chunkGraph,
|
|
18
|
+
moduleGraph
|
|
19
|
+
} = compilation;
|
|
20
|
+
const hierarchy = {};
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
for (const chunk of compilation.chunks) {
|
|
23
|
+
// skip unnamed or runtime chunks
|
|
24
|
+
if (chunk.name && chunk.name.includes("runtime")) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
28
|
+
;
|
|
29
|
+
const modules = chunkGraph.getChunkModulesIterable(chunk);
|
|
30
|
+
const deps = new Set();
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
for (const module of modules) {
|
|
33
|
+
for (const conn of moduleGraph.getOutgoingConnections(module)) {
|
|
34
|
+
if (!conn.module) continue;
|
|
35
|
+
const mod = conn.module;
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
const outputPath = compiler.outputPath;
|
|
32
|
-
const outputFile = path.join(outputPath, this.outputFile);
|
|
33
|
-
fs.mkdirSync(outputPath, {
|
|
34
|
-
recursive: true
|
|
35
|
-
});
|
|
36
|
-
fs.writeFileSync(outputFile, json, 'utf-8');
|
|
37
|
-
callback();
|
|
38
|
-
});
|
|
39
|
-
}
|
|
37
|
+
const ConcatenatedModule = require("webpack/lib/optimize/ConcatenatedModule");
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
if (mod instanceof ConcatenatedModule) {
|
|
40
|
+
for (const inner of mod.modules) {
|
|
41
|
+
if (inner.resource) {
|
|
42
|
+
const match = inner.resource.match(/(?<!node_modules\/)jsapps\/.*/);
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
if (match && /^(?!.*node_modules).*$/.test(match)) {
|
|
45
|
+
deps.add(match[0]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
const identifier = mod.resource || mod.identifier();
|
|
51
|
+
const match = identifier && identifier.match(/(?<!node_modules\/)jsapps\/.*/);
|
|
50
52
|
|
|
53
|
+
if (match && /^(?!.*node_modules).*$/.test(match)) {
|
|
54
|
+
deps.add(match[0]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
51
59
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
collectModules(innerModule, modules, context);
|
|
55
|
-
}
|
|
56
|
-
} // Handle Webpack 5 internal API (ConcatenatedModule inside _orderedConcatenationList)
|
|
60
|
+
hierarchy[chunk.name || chunk.id] = Array.from(deps);
|
|
61
|
+
}
|
|
57
62
|
|
|
63
|
+
const outputPath = compiler.options.output.path;
|
|
64
|
+
const outputFile = path.join(outputPath, this.outputFileName); // Ensure folder exists before writing
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
fs.mkdirSync(outputPath, {
|
|
67
|
+
recursive: true
|
|
68
|
+
});
|
|
69
|
+
fs.writeFileSync(outputFile, JSON.stringify(hierarchy, null, 2), "utf-8");
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.error("❌ ChunkHierarchyPlugin failed:", err);
|
|
63
72
|
}
|
|
64
|
-
}
|
|
73
|
+
});
|
|
65
74
|
}
|
|
75
|
+
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
module.exports = ChunkHierarchyPlugin;
|