@zohodesk/client_build_tool 0.0.14-exp.3 → 0.0.14-exp.5

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.
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _os = require("os");
9
9
 
10
+ var _webpack = require("webpack");
11
+
10
12
  // NOTE: Don't use 'config_file' as cli option it was reserved
11
13
  var _default = {
12
14
  context: {
@@ -300,8 +302,7 @@ var _default = {
300
302
  },
301
303
  customLoaders: [],
302
304
  resourceHints: {
303
- enable: false,
304
- PreloadChunkNames: []
305
+ allowPrefetchingMultipleChunks: false
305
306
  },
306
307
  devModeContentHashAllowedTypes: null,
307
308
  nameTemplateCustomization: null,
@@ -360,6 +361,13 @@ var _default = {
360
361
  enableSubResourceIntegrity: {
361
362
  value: false,
362
363
  cli: 'enable_sub_resource_integrity'
364
+ },
365
+ chunkGraph: {
366
+ enable: {
367
+ value: false,
368
+ cli: 'chunk_graph_enable'
369
+ },
370
+ fileName: ''
363
371
  }
364
372
  };
365
373
  exports.default = _default;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ // plugins/ChunkHierarchyPlugin.js
4
+ const fs = require("fs");
5
+
6
+ const path = require("path");
7
+
8
+ class ChunkHierarchyPlugin {
9
+ constructor(outputFileName) {
10
+ this.outputFileName = outputFileName || "chunk-hierarchy-report.json";
11
+ }
12
+
13
+ apply(compiler) {
14
+ compiler.hooks.afterEmit.tap("ChunkHierarchyPlugin", compilation => {
15
+ try {
16
+ const {
17
+ chunkGraph,
18
+ moduleGraph
19
+ } = compilation;
20
+ const hierarchy = {};
21
+
22
+ for (const chunk of compilation.chunks) {
23
+ // skip unnamed or runtime chunks
24
+ if (!chunk.name) {
25
+ continue;
26
+ }
27
+
28
+ ;
29
+
30
+ if (chunk.name.includes("runtime")) {
31
+ continue;
32
+ }
33
+
34
+ ;
35
+ const modules = chunkGraph.getChunkModulesIterable(chunk);
36
+ const deps = new Set();
37
+
38
+ for (const module of modules) {
39
+ for (const conn of moduleGraph.getOutgoingConnections(module)) {
40
+ if (conn.module && conn.module.resource) {
41
+ deps.add(conn.module.resource.match(/jsapps\/supportapp.*/)?.[0]);
42
+ }
43
+ }
44
+ }
45
+
46
+ hierarchy[chunk.name] = Array.from(deps);
47
+ }
48
+
49
+ const outputPath = compiler.options.output.path;
50
+ const outputFile = path.join(outputPath, this.outputFileName); // Ensure folder exists before writing
51
+
52
+ fs.mkdirSync(outputPath, {
53
+ recursive: true
54
+ });
55
+ fs.writeFileSync(outputFile, JSON.stringify(hierarchy, null, 2), "utf-8");
56
+ } catch (err) {
57
+ console.error("❌ ChunkHierarchyPlugin failed:", err);
58
+ }
59
+ });
60
+ }
61
+
62
+ }
63
+
64
+ module.exports = ChunkHierarchyPlugin;
@@ -22,8 +22,11 @@ const pluginName = 'prefetch-preload-chunk-plugin';
22
22
 
23
23
  class ResourceHintsPlugin {
24
24
  constructor({
25
- publicPath
25
+ publicPath,
26
+ resourceHints
26
27
  }) {
28
+ this.resourceHints = resourceHints;
29
+ this.allowPrefetchingMultipleChunks = resourceHints.allowPrefetchingMultipleChunks;
27
30
  this.publicPathsTemplateObj = {
28
31
  js: publicPath,
29
32
  css: publicPath,
@@ -50,6 +53,7 @@ class ResourceHintsPlugin {
50
53
  compilation.addRuntimeModule(entryRuntimeChunk, // eslint-disable-next-line no-use-before-define
51
54
  new ResourceHintsRuntimePlugin(compiler, {
52
55
  chunk: entryRuntimeChunk,
56
+ allowPrefetchingMultipleChunks: this.allowPrefetchingMultipleChunks,
53
57
  publicPathsTemplateObj
54
58
  }));
55
59
  };
@@ -65,11 +69,13 @@ exports.default = ResourceHintsPlugin;
65
69
  class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
66
70
  constructor(compiler, {
67
71
  chunk,
68
- publicPathsTemplateObj
72
+ publicPathsTemplateObj,
73
+ allowPrefetchingMultipleChunks
69
74
  }) {
70
75
  super('ResourceHintsRuntimePlugin loading', 10);
71
76
  this.compiler = compiler;
72
77
  this.publicPathsTemplateObj = publicPathsTemplateObj;
78
+ this.allowPrefetchingMultipleChunks = allowPrefetchingMultipleChunks;
73
79
  this.chunk = chunk;
74
80
  }
75
81
 
@@ -79,7 +85,7 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
79
85
  } = this;
80
86
  const idNameMap = chunk.getChunkMaps().name;
81
87
  const nameIdMap = {};
82
- let needsMap = false;
88
+ let needsMap = this.allowPrefetchingMultipleChunks;
83
89
  Object.keys(idNameMap).forEach(key => {
84
90
  const value = idNameMap[key];
85
91
  nameIdMap[value] = key;
@@ -105,7 +111,7 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
105
111
  */
106
112
 
107
113
  return _webpack.Template.asString([`const ntc = ${JSON.stringify(needsMap ? nameIdMap : {})};
108
- // const cns = Object.keys(ntc);
114
+ const cns = Object.keys(ntc);
109
115
 
110
116
  function clt(href, rel) {
111
117
  let link = document.createElement("link");
@@ -123,8 +129,8 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
123
129
  //return !url.includes(".undefined.");
124
130
  return url.indexOf(".undefined") === -1;
125
131
  }
126
- function lpp(chunkId, rel) {
127
- // let chunkId = ${_webpack.RuntimeGlobals.require}.getChunkId(_chunkId);
132
+ function lpp(_chunkId, rel) {
133
+ let chunkId = ${_webpack.RuntimeGlobals.require}.getChunkId(_chunkId);
128
134
  // ${_webpack.RuntimeGlobals.require}.e(chunkId);
129
135
  if(__webpack_require__.O.j(chunkId)) {
130
136
  return;
@@ -139,29 +145,33 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
139
145
  }
140
146
  }
141
147
 
142
- ${_webpack.RuntimeGlobals.require}.getChunkId = function getChunkId(chunkName) {
143
- return ntc[chunkName]||chunkName;
148
+ ${_webpack.RuntimeGlobals.require}.getChunkId = function getChunkId(chunkId) {
149
+ ${needsMap ? 'chunkId = ntc[chunkId]||chunkId;' : ''}
150
+ return chunkId;
144
151
  }
145
-
146
- // Preload a chunk (${pluginName})
147
- ${_webpack.RuntimeGlobals.require}.plc = function preloadChunk(chunkId) {
148
- const preloadChunkGraph = {{--preload-chunk-graph-object}}
152
+ ${_webpack.RuntimeGlobals.require}.getChunkIds = function getChunkIds(chunkId) {
153
+ ${// eslint-disable-next-line no-nested-ternary
154
+ this.allowPrefetchingMultipleChunks ? `
155
+ const isRegExAsChunkId = chunkId instanceof RegExp;
156
+ if(isRegExAsChunkId) {
157
+ return cns.filter(chunkName => chunkId.test(chunkName)).map(chunkName => ntc[chunkName]);
158
+ }
159
+ return [${_webpack.RuntimeGlobals.require}.getChunkId(chunkId)];
160
+ ` : `return [${_webpack.RuntimeGlobals.require}.getChunkId(chunkId)];`}
161
+ }
162
+ // Prefetch a chunk (${pluginName})
163
+ ${_webpack.RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {
149
164
  ${`
150
- if (typeof preloadChunkGraph !== 'object' || !preloadChunkGraph) return;
151
- preloadChunkGraph[chunkId].forEach(idOfAChunk => {
152
- ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
153
- })
154
- // let idOfAChunk = ${_webpack.RuntimeGlobals.require}.getChunkId(chunkId);
155
- // chunkIds.forEach(idOfAChunk => {
156
- // ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
157
- // })
158
- `}
165
+ let chunkIds = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId);
166
+ chunkIds.forEach(idOfAChunk => {
167
+ ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
168
+ })`}
159
169
  };
160
170
 
161
- // Prefetch a chunk (${pluginName})
162
- ${_webpack.RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {
163
- let idOfAChunk = ${_webpack.RuntimeGlobals.require}.getChunkId(chunkId);
164
- lpp(idOfAChunk, "prefetch");
171
+ // Preload a chunk (${pluginName})
172
+ ${_webpack.RuntimeGlobals.require}.plc = function preloadChunk(chunkId) {
173
+ let idOfAChunk = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId)[0];
174
+ lpp(idOfAChunk, "preload");
165
175
  }
166
176
  ` // `// Prefetch a chunk (${pluginName})`,
167
177
  // `${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {`,
@@ -180,17 +190,4 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
180
190
  ]);
181
191
  }
182
192
 
183
- } // ${RuntimeGlobals.require}.getChunkIds = function getChunkIds(chunkId) {
184
- // ${
185
- // // eslint-disable-next-line no-nested-ternary
186
- // this.allowPrefetchingMultipleChunks
187
- // ? `
188
- // const isRegExAsChunkId = chunkId instanceof RegExp;
189
- // if(isRegExAsChunkId) {
190
- // return cns.filter(chunkName => chunkId.test(chunkName)).map(chunkName => ntc[chunkName]);
191
- // }
192
- // return [${RuntimeGlobals.require}.getChunkId(chunkId)];
193
- // `
194
- // : `return [${RuntimeGlobals.require}.getChunkId(chunkId)];`
195
- // }
196
- // }
193
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configChunkHierarchyPlugin = configChunkHierarchyPlugin;
7
+
8
+ var _ChunkHierarchyPlugin = _interopRequireDefault(require("../custom_plugins/ChunkHierarchyPlugin"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /* eslint-disable no-use-before-define */
13
+ function configChunkHierarchyPlugin(options) {
14
+ if (options.chunkGraph.enable) {
15
+ return new _ChunkHierarchyPlugin.default(options.chunkGraph.fileName);
16
+ }
17
+
18
+ return null;
19
+ }
@@ -14,12 +14,8 @@ function configResourceHintsPlugin(options) {
14
14
  publicPath,
15
15
  resourceHints
16
16
  } = options;
17
-
18
- if (resourceHints.enable) {
19
- return new _ResourceHintsPlugin.default({
20
- publicPath: JSON.stringify(publicPath)
21
- });
22
- }
23
-
24
- return null;
17
+ return new _ResourceHintsPlugin.default({
18
+ resourceHints,
19
+ publicPath: JSON.stringify(publicPath)
20
+ });
25
21
  }
@@ -51,12 +51,12 @@ var _configMurphyInjectorPlugin = require("./pluginConfigs/configMurphyInjectorP
51
51
 
52
52
  var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCustomScriptLoadingStrategyPlugin");
53
53
 
54
- var _configInjectChunkGraphPlugin = require("./pluginConfigs/configInjectChunkGraphPlugin");
54
+ var _configChunkHierarchyPlugin = require("./pluginConfigs/configChunkHierarchyPlugin");
55
55
 
56
56
  // import { IgnorePlugin } from 'webpack';
57
57
  function plugins(options) {
58
58
  const {
59
59
  webpackPlugins
60
60
  } = options;
61
- return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), (0, _configMurphyInjectorPlugin.configMurphyInjectorPlugin)(options), (0, _configInjectChunkGraphPlugin.configInjectChunkGraphPlugin)(options), ...webpackPlugins].filter(Boolean);
61
+ return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), (0, _configMurphyInjectorPlugin.configMurphyInjectorPlugin)(options), (0, _configChunkHierarchyPlugin.configChunkHierarchyPlugin)(options), ...webpackPlugins].filter(Boolean);
62
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.14-exp.3",
3
+ "version": "0.0.14-exp.5",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://zgit.csez.zohocorpin.com/zohodesk/react-cli.git"
21
+ "url": "https://zgit.csecz.zohocorpin.com/zohodesk/react-cli.git"
22
22
  },
23
23
  "keywords": [
24
24
  "buildtool",
@@ -32,7 +32,6 @@
32
32
  "@babel/preset-env": "7.18.2",
33
33
  "@babel/preset-react": "7.17.12",
34
34
  "@babel/preset-typescript": "7.23.2",
35
- "@zohodesk-private/client_dev_cert": "^1.0.6",
36
35
  "@zohodesk/client_packages_group": "1.0.2",
37
36
  "babel-loader": "9.1.2",
38
37
  "babel-plugin-module-resolver": "5.0.2",
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- RawSource
5
- } = require('webpack-sources');
6
-
7
- class InjectChunkGraphPlugin {
8
- constructor(resourceHints) {
9
- this.chunkNames = resourceHints.PreloadChunkNames || [];
10
- }
11
-
12
- apply(compiler) {
13
- compiler.hooks.thisCompilation.tap('InjectChunkGraphPlugin', compilation => {
14
- compilation.hooks.processAssets.tap({
15
- name: 'InjectChunkGraphPlugin',
16
- stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
17
- }, () => {
18
- const stats = compilation.getStats().toJson({
19
- all: true
20
- });
21
- const chunkGraph = {};
22
- this.chunkNames.forEach(chunkName => {
23
- const chunkGroup = stats.namedChunkGroups?.[chunkName];
24
-
25
- if (!chunkGroup) {
26
- compilation.warnings.push(new Error(`[InjectChunkGraphPlugin] Chunk group "${chunkName}" not found.`));
27
- return;
28
- }
29
-
30
- chunkGraph[chunkName] = chunkGroup.chunks;
31
- });
32
- const code = `
33
- preloadChunkGraph=${JSON.stringify(chunkGraph)};
34
- `; // Find runtime chunk file
35
-
36
- const runtimeChunk = stats.chunks.find(chunk => chunk.names?.some(n => n.includes('runtime~main')));
37
- const runtimeChunkName = runtimeChunk.files[0];
38
- const originalSource = compilation.assets[runtimeChunkName].source();
39
- const newSource = originalSource + '\n' + code; // Update the runtime asset with injected code
40
-
41
- compilation.updateAsset(runtimeChunkName, new RawSource(newSource.replace('{{--preload-chunk-graph-object}}', `${JSON.stringify(chunkGraph)}`)));
42
- });
43
- });
44
- }
45
-
46
- }
47
-
48
- module.exports = InjectChunkGraphPlugin;
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.configInjectChunkGraphPlugin = configInjectChunkGraphPlugin;
7
-
8
- var _InjectChunkGraphPlugin = _interopRequireDefault(require("../custom_plugins/InjectChunkGraphPlugin"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function configInjectChunkGraphPlugin(options) {
13
- const {
14
- resourceHints
15
- } = options;
16
-
17
- if (resourceHints.enable) {
18
- return new _InjectChunkGraphPlugin.default(resourceHints);
19
- }
20
-
21
- return null;
22
- }