@zohodesk/client_build_tool 0.0.13 → 0.0.14-exp.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog and Release Notes
2
2
 
3
+ # v0.0.14 (06-10-2025)
4
+
5
+ **Feature:-**
6
+ - Added integrity and crossorigin attributes for all the js and css files in index.html
7
+
8
+ ```enableSubResourceIntegrity: true
9
+ ```
10
+ **Adjustments:-**
11
+ - add ts-loader to parse tsx and ts files
12
+
3
13
  # v0.0.13 (02-09-2025)
4
14
 
5
15
  **Adjustments:-**
package/README.md CHANGED
@@ -306,6 +306,16 @@ First Release
306
306
  - 'templates' command to create es for react library
307
307
  # Changelog and Release Notes
308
308
 
309
+ # v0.0.14 (06-10-2025)
310
+
311
+ **Feature:-**
312
+ - Added integrity and crossorigin attributes for all the js and css files in index.html
313
+
314
+ ```enableSubResourceIntegrity: true
315
+ ```
316
+ **Adjustments:-**
317
+ - add ts-loader to parse tsx and ts files
318
+
309
319
  # v0.0.13 (02-09-2025)
310
320
 
311
321
  **Adjustments:-**
@@ -300,7 +300,8 @@ var _default = {
300
300
  },
301
301
  customLoaders: [],
302
302
  resourceHints: {
303
- allowPrefetchingMultipleChunks: false
303
+ enable: false,
304
+ PreloadChunkNames: []
304
305
  },
305
306
  devModeContentHashAllowedTypes: null,
306
307
  nameTemplateCustomization: null,
@@ -355,6 +356,10 @@ var _default = {
355
356
  enable: false,
356
357
  chunkName: '',
357
358
  filePath: ''
359
+ },
360
+ enableSubResourceIntegrity: {
361
+ value: false,
362
+ cli: 'enable_sub_resource_integrity'
358
363
  }
359
364
  };
360
365
  exports.default = _default;
@@ -16,13 +16,28 @@ class InitialHtmlPlugin {
16
16
  this.options = options;
17
17
  }
18
18
 
19
+ getBaseName(str) {
20
+ const fileName = str.split("/").pop();
21
+ const parts = fileName.split("."); // Find index of the hash-like segment
22
+
23
+ const hashIndex = parts.findIndex(p => /^[0-9a-f_]{20,}$/i.test(p)); // If a hash is found, return everything before it
24
+
25
+ if (hashIndex < 0) {
26
+ console.error('this initial file dont have a hash');
27
+ return parts.slice(0, -1).join(".");
28
+ }
29
+
30
+ return parts.slice(0, hashIndex).join("."); // Otherwise fallback: remove only ".js"
31
+ }
32
+
19
33
  apply(compiler) {
20
34
  const {
21
35
  filename,
22
36
  template,
23
37
  minify,
24
38
  inject,
25
- mainChunkName
39
+ mainChunkName,
40
+ enableSubResourceIntegrity
26
41
  } = this.options;
27
42
  new _htmlWebpackPlugin.default({
28
43
  filename,
@@ -37,13 +52,36 @@ class InitialHtmlPlugin {
37
52
  const headTags = [];
38
53
  const bodyTags = [];
39
54
  data.headTags.forEach(tag => {
55
+ const url = tag.attributes?.src || tag.attributes?.href;
56
+ let chunkName;
57
+
58
+ const addIntegrity = (tag, suffix) => {
59
+ if (enableSubResourceIntegrity && chunkName) {
60
+ Object.assign(tag.attributes, {
61
+ integrity: `{{--${chunkName}-${suffix}-integrity}}`
62
+ });
63
+ }
64
+ };
65
+
66
+ if (enableSubResourceIntegrity) {
67
+ chunkName = this.getBaseName(url);
68
+ }
69
+
40
70
  Object.assign(tag.attributes, {
41
- nonce: '{{--CSP-nonce}}'
71
+ nonce: '{{--CSP-nonce}}',
72
+ crossorigin: "anonymous"
42
73
  });
43
74
 
44
75
  if (tag.tagName === 'link') {
76
+ addIntegrity(tag, 'css');
45
77
  headTags.push(tag);
46
78
  } else {
79
+ if (url.endsWith('.i18n.js')) {
80
+ addIntegrity(tag, 'i18n');
81
+ } else {
82
+ addIntegrity(tag, 'js');
83
+ }
84
+
47
85
  bodyTags.push(tag);
48
86
  }
49
87
  });
@@ -0,0 +1,48 @@
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;
@@ -22,11 +22,8 @@ const pluginName = 'prefetch-preload-chunk-plugin';
22
22
 
23
23
  class ResourceHintsPlugin {
24
24
  constructor({
25
- publicPath,
26
- resourceHints
25
+ publicPath
27
26
  }) {
28
- this.resourceHints = resourceHints;
29
- this.allowPrefetchingMultipleChunks = resourceHints.allowPrefetchingMultipleChunks;
30
27
  this.publicPathsTemplateObj = {
31
28
  js: publicPath,
32
29
  css: publicPath,
@@ -53,7 +50,6 @@ class ResourceHintsPlugin {
53
50
  compilation.addRuntimeModule(entryRuntimeChunk, // eslint-disable-next-line no-use-before-define
54
51
  new ResourceHintsRuntimePlugin(compiler, {
55
52
  chunk: entryRuntimeChunk,
56
- allowPrefetchingMultipleChunks: this.allowPrefetchingMultipleChunks,
57
53
  publicPathsTemplateObj
58
54
  }));
59
55
  };
@@ -69,13 +65,11 @@ exports.default = ResourceHintsPlugin;
69
65
  class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
70
66
  constructor(compiler, {
71
67
  chunk,
72
- publicPathsTemplateObj,
73
- allowPrefetchingMultipleChunks
68
+ publicPathsTemplateObj
74
69
  }) {
75
70
  super('ResourceHintsRuntimePlugin loading', 10);
76
71
  this.compiler = compiler;
77
72
  this.publicPathsTemplateObj = publicPathsTemplateObj;
78
- this.allowPrefetchingMultipleChunks = allowPrefetchingMultipleChunks;
79
73
  this.chunk = chunk;
80
74
  }
81
75
 
@@ -85,7 +79,7 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
85
79
  } = this;
86
80
  const idNameMap = chunk.getChunkMaps().name;
87
81
  const nameIdMap = {};
88
- let needsMap = this.allowPrefetchingMultipleChunks;
82
+ let needsMap = false;
89
83
  Object.keys(idNameMap).forEach(key => {
90
84
  const value = idNameMap[key];
91
85
  nameIdMap[value] = key;
@@ -111,7 +105,8 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
111
105
  */
112
106
 
113
107
  return _webpack.Template.asString([`const ntc = ${JSON.stringify(needsMap ? nameIdMap : {})};
114
- const cns = Object.keys(ntc);
108
+ // const cns = Object.keys(ntc);
109
+ const preloadChunkGraph = {{--preload-chunk-graph-object}}
115
110
 
116
111
  function clt(href, rel) {
117
112
  let link = document.createElement("link");
@@ -129,8 +124,8 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
129
124
  //return !url.includes(".undefined.");
130
125
  return url.indexOf(".undefined") === -1;
131
126
  }
132
- function lpp(_chunkId, rel) {
133
- let chunkId = ${_webpack.RuntimeGlobals.require}.getChunkId(_chunkId);
127
+ function lpp(chunkId, rel) {
128
+ // let chunkId = ${_webpack.RuntimeGlobals.require}.getChunkId(_chunkId);
134
129
  // ${_webpack.RuntimeGlobals.require}.e(chunkId);
135
130
  if(__webpack_require__.O.j(chunkId)) {
136
131
  return;
@@ -145,33 +140,28 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
145
140
  }
146
141
  }
147
142
 
148
- ${_webpack.RuntimeGlobals.require}.getChunkId = function getChunkId(chunkId) {
149
- ${needsMap ? 'chunkId = ntc[chunkId]||chunkId;' : ''}
150
- return chunkId;
143
+ ${_webpack.RuntimeGlobals.require}.getChunkId = function getChunkId(chunkName) {
144
+ return ntc[chunkName]||chunkName;
151
145
  }
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) {
146
+
147
+ // Preload a chunk (${pluginName})
148
+ ${_webpack.RuntimeGlobals.require}.plc = function preloadChunk(chunkId) {
164
149
  ${`
165
- let chunkIds = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId);
166
- chunkIds.forEach(idOfAChunk => {
167
- ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
168
- })`}
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
+ `}
169
159
  };
170
160
 
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");
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");
175
165
  }
176
166
  ` // `// Prefetch a chunk (${pluginName})`,
177
167
  // `${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {`,
@@ -190,4 +180,17 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
190
180
  ]);
191
181
  }
192
182
 
193
- }
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
+ // }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ const {
4
+ RawSource
5
+ } = require('webpack-sources');
6
+
7
+ class InjectChunkGraphPlugin {
8
+ constructor({
9
+ chunkName,
10
+ globalVarName = 'chunkGraph'
11
+ }) {
12
+ this.chunkNames = ['ticketDetailview'];
13
+ this.globalVarName = globalVarName;
14
+ }
15
+
16
+ apply(compiler) {
17
+ console.log('inject');
18
+ compiler.hooks.thisCompilation.tap('InjectChunkGraphPlugin', compilation => {
19
+ compilation.hooks.processAssets.tap({
20
+ name: 'InjectChunkGraphPlugin',
21
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
22
+ }, () => {
23
+ const stats = compilation.getStats().toJson({
24
+ all: true
25
+ });
26
+ const chunkGraph = {};
27
+ this.chunkNames.forEach(chunkName => {
28
+ const chunkGroup = stats.namedChunkGroups?.[chunkName];
29
+
30
+ if (!chunkGroup) {
31
+ compilation.warnings.push(new Error(`[InjectChunkGraphPlugin] Chunk group "${chunkName}" not found.`));
32
+ return;
33
+ }
34
+
35
+ chunkGraph[chunkName] = chunkGroup.chunks;
36
+ });
37
+ const code = `
38
+ window.preloadChunkGraph=${JSON.stringify(chunkGraph)};
39
+ `; // Find runtime chunk file
40
+
41
+ const runtimeChunk = stats.chunks.find(chunk => chunk.names?.some(n => n.includes('runtime~main')));
42
+ const runtimeChunkName = runtimeChunk.files[0];
43
+ const originalSource = compilation.assets[runtimeChunkName].source();
44
+ console.log(originalSource);
45
+ const newSource = originalSource + '\n' + code; // Update the runtime asset with injected code
46
+
47
+ compilation.updateAsset(runtimeChunkName, new RawSource(newSource));
48
+ });
49
+ });
50
+ }
51
+
52
+ }
53
+
54
+ module.exports = InjectChunkGraphPlugin;
@@ -16,7 +16,8 @@ var _InitialHtmlPlugin = require("../custom_plugins/InitialHtmlPlugin");
16
16
  function configHtmlWebpackPlugin(options) {
17
17
  const {
18
18
  htmlTemplate,
19
- mode
19
+ mode,
20
+ enableSubResourceIntegrity
20
21
  } = options;
21
22
  const {
22
23
  inject,
@@ -31,7 +32,8 @@ function configHtmlWebpackPlugin(options) {
31
32
  template: appInitialHTMLTemplatePath,
32
33
  minify: minifyHtmlOptions,
33
34
  inject,
34
- scriptLoading: 'defer'
35
+ scriptLoading: 'defer',
36
+ enableSubResourceIntegrity
35
37
  });
36
38
  }
37
39
 
@@ -0,0 +1,22 @@
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
+ }
@@ -14,8 +14,12 @@ function configResourceHintsPlugin(options) {
14
14
  publicPath,
15
15
  resourceHints
16
16
  } = options;
17
- return new _ResourceHintsPlugin.default({
18
- resourceHints,
19
- publicPath: JSON.stringify(publicPath)
20
- });
17
+
18
+ if (resourceHints.enable) {
19
+ return new _ResourceHintsPlugin.default({
20
+ publicPath: JSON.stringify(publicPath)
21
+ });
22
+ }
23
+
24
+ return null;
21
25
  }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configInjectChunkGraphPlugin = configInjectChunkGraphPlugin;
7
+
8
+ var _a = _interopRequireDefault(require("../custom_plugins/a"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function configInjectChunkGraphPlugin(options) {
13
+ console.log('whats');
14
+ return new _a.default(options);
15
+ }
@@ -51,10 +51,12 @@ var _configMurphyInjectorPlugin = require("./pluginConfigs/configMurphyInjectorP
51
51
 
52
52
  var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCustomScriptLoadingStrategyPlugin");
53
53
 
54
+ var _configInjectChunkGraphPlugin = require("./pluginConfigs/configInjectChunkGraphPlugin");
55
+
54
56
  // import { IgnorePlugin } from 'webpack';
55
57
  function plugins(options) {
56
58
  const {
57
59
  webpackPlugins
58
60
  } = options;
59
- 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), ...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, _configInjectChunkGraphPlugin.configInjectChunkGraphPlugin)(options), ...webpackPlugins].filter(Boolean);
60
62
  }
@@ -8,10 +8,11 @@ exports.tsLoaders = tsLoaders;
8
8
  var _babelLoaderConfig = require("./loaderConfigs/babelLoaderConfig");
9
9
 
10
10
  function tsLoaders(options) {
11
+ console.log('testing');
11
12
  return [{
12
- test: /\.tsx$/,
13
+ test: /\.tsx?$/,
13
14
  exclude: /node_modules/,
14
- use: [(0, _babelLoaderConfig.babelLoaderConfig)(options)] // include: path.join(appPath, folder)
15
+ use: "ts-loader" // include: path.join(appPath, folder)
15
16
 
16
17
  }];
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.13",
3
+ "version": "0.0.14-exp.1",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {