@zohodesk/client_build_tool 0.0.16-exp.7 → 0.0.16-exp.9

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,14 +7,15 @@ exports.default = void 0;
7
7
 
8
8
  var _os = require("os");
9
9
 
10
- var _webpack = require("webpack");
11
-
12
10
  // NOTE: Don't use 'config_file' as cli option it was reserved
13
11
  var _default = {
14
12
  context: {
15
13
  value: 'app',
16
14
  cli: 'context'
17
15
  },
16
+ library: {
17
+ ignorePatterns: []
18
+ },
18
19
  devtool: 'source-map',
19
20
  statsLogConfig: null,
20
21
  stats: {
@@ -183,6 +184,11 @@ var _default = {
183
184
  prod: ['...']
184
185
  },
185
186
  app: {
187
+ AdditionalEntry: {
188
+ enable: false,
189
+ entryFile: 'src/widget.js',
190
+ entryPointName: 'widget'
191
+ },
186
192
  entryFile: {
187
193
  value: 'src/index.js',
188
194
  cli: 'entry'
@@ -198,6 +204,7 @@ var _default = {
198
204
  alias: null
199
205
  },
200
206
  htmlTemplate: {
207
+ generateHtml: true,
201
208
  crossorigin: {
202
209
  value: false,
203
210
  cli: 'enable_crossorigin'
@@ -302,8 +309,7 @@ var _default = {
302
309
  },
303
310
  customLoaders: [],
304
311
  resourceHints: {
305
- enable: false,
306
- PreloadChunkNames: []
312
+ allowPrefetchingMultipleChunks: false
307
313
  },
308
314
  devModeContentHashAllowedTypes: null,
309
315
  nameTemplateCustomization: null,
@@ -30,7 +30,7 @@ function babelWebConfig(options, mode) {
30
30
  } = options.typeScript;
31
31
  return {
32
32
  presets: typeScriptEnable ? [getBabelPresetEnvConfig(browserList, mode), require.resolve('@babel/preset-react'), require.resolve('@babel/preset-typescript')] : [getBabelPresetEnvConfig(browserList, mode), require.resolve('@babel/preset-react')],
33
- plugins: customBabelPlugins(babelPlugins).concat((0, _getBabelPlugin.getBabelPlugin)(options)).filter(Boolean)
33
+ plugins: customBabelPlugins(babelPlugins).concat((0, _getBabelPlugin.getBabelPlugin)(options, mode)).filter(Boolean)
34
34
  };
35
35
  }
36
36
 
@@ -16,12 +16,22 @@ const babelPluginMapping = {
16
16
  };
17
17
  const babelPluginOrder = ['removeAttribute', 'removePropTypes', 'devConsoleExclude'];
18
18
 
19
- function getBabelPlugin(options) {
19
+ function getBabelPlugin(options, command) {
20
20
  const {
21
21
  mode
22
- } = options; // let customPlugins = [];
23
-
22
+ } = options;
23
+ const {
24
+ alias
25
+ } = options.resolve;
24
26
  let customPlugins = [];
27
+
28
+ if (command == 'es' || command == 'lib') {
29
+ customPlugins = [[require.resolve('babel-plugin-module-resolver'), {
30
+ root: ['./'],
31
+ alias
32
+ }]];
33
+ }
34
+
25
35
  const {
26
36
  babelCustomizations
27
37
  } = options;
@@ -11,18 +11,32 @@ var _babelWebConfig = require("./babelWebConfig");
11
11
 
12
12
  var _copyFile = require("../fileUtils/copyFile");
13
13
 
14
+ var _fs = require("fs");
15
+
14
16
  function runBabelForTSFile({
15
17
  filename,
16
18
  outputFile,
17
19
  options,
18
20
  mode = 'es'
19
21
  }) {
22
+ const {
23
+ ignorePatterns
24
+ } = options.library;
20
25
  const {
21
26
  enable
22
27
  } = options.typeScript;
23
28
 
24
29
  if (enable) {
25
- // const jsSourceCode = readFileSync(filename).toString();
30
+ function shouldIgnore(filename) {
31
+ return ignorePatterns.some(pattern => pattern.test(filename));
32
+ }
33
+
34
+ if (shouldIgnore(filename)) {
35
+ const jsSourceCode = (0, _fs.readFileSync)(filename).toString();
36
+ (0, _copyFile.writeFile)(outputFile, jsSourceCode);
37
+ return;
38
+ }
39
+
26
40
  const babelConfig = (0, _babelWebConfig.babelWebConfig)(options, mode);
27
41
  const result = (0, _core.transformFileSync)(filename, babelConfig);
28
42
  (0, _copyFile.writeFile)(outputFile.replace('.tsx', '.js').replace('.ts', '.js'), result.code);
@@ -1,78 +1,68 @@
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(outputFileName) {
10
- this.outputFileName = outputFileName || "chunk-hierarchy-report.json";
9
+ constructor(outputFile) {
10
+ this.outputFile = outputFile || 'chunk-hierarchy-report.json';
11
11
  }
12
12
 
13
13
  apply(compiler) {
14
- compiler.hooks.afterEmit.tap("ChunkHierarchyPlugin", compilation => {
15
- try {
16
- const {
17
- chunkGraph,
18
- moduleGraph
19
- } = compilation;
20
- const hierarchy = {};
14
+ compiler.hooks.emit.tapAsync('ChunkHierarchyPlugin', (compilation, callback) => {
15
+ const result = {};
16
+ const rootContext = path.resolve(compiler.context, '..', '..');
21
17
 
22
- for (const chunk of compilation.chunks) {
23
- // skip unnamed or runtime chunks
24
- if (chunk.name && chunk.name.includes("runtime")) {
25
- continue;
26
- }
18
+ for (const chunk of compilation.chunks) {
19
+ const chunkName = chunk.name || chunk.id;
20
+ const modules = [];
27
21
 
28
- ;
29
- const modules = chunkGraph.getChunkModulesIterable(chunk);
30
- const deps = new Set();
22
+ for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
23
+ // Recursively extract real modules (handle ConcatenatedModules)
24
+ collectModules(module, modules, rootContext);
25
+ }
31
26
 
32
- for (const module of modules) {
33
- for (const conn of moduleGraph.getOutgoingConnections(module)) {
34
- if (!conn.module) continue;
35
- const mod = conn.module;
27
+ result[chunkName] = modules;
28
+ }
36
29
 
37
- const ConcatenatedModule = require("webpack/lib/optimize/ConcatenatedModule");
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
+ }
38
40
 
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\/.*/);
41
+ }
43
42
 
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\/.*/);
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)
52
50
 
53
- if (match && /^(?!.*node_modules).*$/.test(match)) {
54
- deps.add(match[0]);
55
- }
56
- }
57
- }
58
- }
59
51
 
60
- hierarchy[chunk.name || chunk.id] = Array.from(deps);
61
- }
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)
62
57
 
63
- const outputPath = compiler.options.output.path;
64
- const outputFile = path.join(outputPath, this.outputFileName); // Ensure folder exists before writing
65
58
 
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);
59
+ if (module._orderedConcatenationList) {
60
+ for (const item of module._orderedConcatenationList) {
61
+ if (item.module) {
62
+ collectModules(item.module, modules, context);
72
63
  }
73
- });
64
+ }
74
65
  }
75
-
76
66
  }
77
67
 
78
68
  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__
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
+ }
@@ -14,7 +14,8 @@ function entryConfig(options) {
14
14
  entryPointName
15
15
  } = options.efc;
16
16
  const {
17
- entryFile: mainEntry
17
+ entryFile: mainEntry,
18
+ AdditionalEntry
18
19
  } = options.app;
19
20
  const entry = {
20
21
  main: (0, _constants.joinWithAppPath)(mainEntry)
@@ -24,5 +25,9 @@ function entryConfig(options) {
24
25
  entry[entryPointName] = (0, _constants.joinWithAppPath)(entryFile);
25
26
  }
26
27
 
28
+ if (AdditionalEntry.enable) {
29
+ entry[AdditionalEntry.entryPointName] = (0, _constants.joinWithAppPath)(AdditionalEntry.entryFile);
30
+ }
31
+
27
32
  return entry;
28
33
  }
@@ -17,13 +17,19 @@ function configHtmlWebpackPlugin(options) {
17
17
  const {
18
18
  htmlTemplate,
19
19
  mode,
20
- enableSubResourceIntegrity
20
+ enableSubResourceIntegrity,
21
+ generateHtml
21
22
  } = options;
22
23
  const {
23
24
  inject,
24
25
  templateFile
25
26
  } = htmlTemplate;
26
27
  const appInitialHTMLTemplatePath = (0, _constants.joinWithAppPath)(templateFile);
28
+
29
+ if (!generateHtml) {
30
+ return null;
31
+ }
32
+
27
33
  const minifyHtmlOptions = (0, _modeUtils.isProductionMode)(mode) ? // eslint-disable-next-line no-use-before-define
28
34
  getHTMLMinifyOptions(htmlTemplate) : false;
29
35
  return new _InitialHtmlPlugin.InitialHtmlPlugin({
@@ -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
  }
@@ -60,5 +60,5 @@ function plugins(options) {
60
60
  const {
61
61
  webpackPlugins
62
62
  } = options;
63
- 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), (0, _configInjectChunkGraphPlugin.configInjectChunkGraphPlugin)(options), ...webpackPlugins].filter(Boolean);
63
+ 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);
64
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.16-exp.7",
3
+ "version": "0.0.16-exp.9",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {