@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('fs');
4
+ const fs = require("fs");
5
5
 
6
- const path = require('path');
6
+ const path = require("path");
7
7
 
8
8
  class ChunkHierarchyPlugin {
9
- constructor(outputFile) {
10
- this.outputFile = outputFile || 'chunk-hierarchy-report.json';
9
+ constructor(outputFileName) {
10
+ this.outputFileName = outputFileName || "chunk-hierarchy-report.json";
11
11
  }
12
12
 
13
13
  apply(compiler) {
14
- compiler.hooks.emit.tapAsync('ChunkHierarchyPlugin', (compilation, callback) => {
15
- const result = {};
16
- const rootContext = path.resolve(compiler.context, '..', '..');
14
+ compiler.hooks.afterEmit.tap("ChunkHierarchyPlugin", compilation => {
15
+ try {
16
+ const {
17
+ chunkGraph,
18
+ moduleGraph
19
+ } = compilation;
20
+ const hierarchy = {};
17
21
 
18
- for (const chunk of compilation.chunks) {
19
- const chunkName = chunk.name || chunk.id;
20
- const modules = [];
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
- for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
23
- // Recursively extract real modules (handle ConcatenatedModules)
24
- collectModules(module, modules, rootContext);
25
- }
28
+ ;
29
+ const modules = chunkGraph.getChunkModulesIterable(chunk);
30
+ const deps = new Set();
26
31
 
27
- result[chunkName] = modules;
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
- const json = JSON.stringify(result, null, 2);
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
- function collectModules(module, modules, context) {
44
- // Handle normal modules
45
- if (module.resource) {
46
- console.log(module.resource);
47
- modules.push(path.relative(context, module.resource));
48
- return;
49
- } // Handle ConcatenatedModule (webpack internal)
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
- if (module.modules) {
53
- for (const innerModule of module.modules) {
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
- if (module._orderedConcatenationList) {
60
- for (const item of module._orderedConcatenationList) {
61
- if (item.module) {
62
- collectModules(item.module, modules, context);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.16-exp.6",
3
+ "version": "0.0.16-exp.7",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {