@zohodesk/client_build_tool 0.0.5 → 0.0.6-exp.10

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +27 -0
  3. package/lib/commands/build/optionsProcessor.js +2 -2
  4. package/lib/commands/start/optionsProcessor.js +1 -1
  5. package/lib/schemas/defaultConfigValues.js +17 -1
  6. package/lib/schemas/defaultConfigValuesOnly.js +8 -1
  7. package/lib/shared/bundler/webpack/common/modeUtils.js +8 -0
  8. package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +83 -0
  9. package/lib/shared/bundler/webpack/custom_plugins/{CdnChangePlugin.js → CdnChangePlugin/index.js} +19 -3
  10. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +265 -0
  11. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +2 -0
  12. package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +39 -38
  13. package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +73 -0
  14. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +16 -2
  15. package/lib/shared/bundler/webpack/externals.js +5 -1
  16. package/lib/shared/bundler/webpack/outputConfig.js +4 -3
  17. package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +11 -11
  18. package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +36 -0
  19. package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +31 -0
  20. package/lib/shared/bundler/webpack/plugins.js +5 -1
  21. package/lib/shared/bundler/webpack/splitChunksConfig.js +14 -11
  22. package/lib/shared/bundler/webpack/utils/object-manipulation.js +87 -0
  23. package/lib/shared/commands-utils/doBasicRequirementCheck.js +2 -2
  24. package/lib/shared/server/corsHandling.js +9 -0
  25. package/npm-shrinkwrap.json +2 -2
  26. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog and Release Notes
2
2
 
3
+
4
+
5
+ **Feature:-**
6
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
7
+ - to use externals, we use the following pattern in `app > externals` :
8
+
9
+ For example
10
+ ```
11
+ externals: {
12
+ <key> : <value>
13
+ }
14
+ ```
15
+
16
+ ## v0.0.6 (4-09-2023)
17
+
18
+ **Feature:-**
19
+ - Generating bundle integrity report json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
20
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
21
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
22
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
23
+ - added support for glob pattern for custom chunks split logic.
24
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
25
+
26
+ **Change:-**
27
+ - i18n name not generated issue fix.
28
+ - public path not correctly set issue fix.
29
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
3
30
  ## v0.0.5 (6-08-2023)
4
31
 
5
32
  **Changes:--**
package/README.md CHANGED
@@ -84,6 +84,33 @@ These commands provide flexibility and control over your client-side build proce
84
84
  For more [Details](ConfigurationDocumentation.md)
85
85
  # Changelog and Release Notes
86
86
 
87
+
88
+
89
+ **Feature:-**
90
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
91
+ - to use externals, we use the following pattern in `app > externals` :
92
+
93
+ For example
94
+ ```
95
+ externals: {
96
+ <key> : <value>
97
+ }
98
+ ```
99
+
100
+ ## v0.0.6 (4-09-2023)
101
+
102
+ **Feature:-**
103
+ - Generating bundle integrity report json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
104
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
105
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
106
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
107
+ - added support for glob pattern for custom chunks split logic.
108
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
109
+
110
+ **Change:-**
111
+ - i18n name not generated issue fix.
112
+ - public path not correctly set issue fix.
113
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
87
114
  ## v0.0.5 (6-08-2023)
88
115
 
89
116
  **Changes:--**
@@ -21,13 +21,13 @@ function optionsProcessor(options) {
21
21
  isCdnEnabled
22
22
  } = options.cdnMapping;
23
23
  const serverExtras = (0, _decidePublicPath.modifiedServerOptions)(options);
24
- const publicPath = noPublicPath ? '' : (0, _decidePublicPath.decidePublicPath)(serverExtras);
24
+ const publicPath = noPublicPath ? undefined : (0, _decidePublicPath.decidePublicPath)(serverExtras);
25
25
  const contextFolderPath = (0, _constants.joinWithAppPath)(context);
26
26
  const defaultAppliedOptions = { ...options,
27
27
  serverExtras,
28
28
  // eslint-disable-next-line no-nested-ternary
29
29
  mode: mode === null ? 'prod' : mode === 'dev' ? 'dev' : 'prod',
30
- publicPath: (0, _modeUtils.isDevelopmentMode)(mode) || isCdnEnabled ? '' : publicPath,
30
+ publicPath: (0, _modeUtils.isDevelopmentMode)(mode) || isCdnEnabled ? undefined : publicPath,
31
31
  contextFolderPath,
32
32
  httpsOptions: serverExtras.httpsOptions
33
33
  };
@@ -16,7 +16,7 @@ function optionsProcessor(options) {
16
16
  noPublicPath
17
17
  } = options;
18
18
  const serverExtras = (0, _decidePublicPath.modifiedServerOptions)(options);
19
- const publicPath = noPublicPath ? '' : (0, _decidePublicPath.decidePublicPath)(serverExtras);
19
+ const publicPath = noPublicPath ? undefined : (0, _decidePublicPath.decidePublicPath)(serverExtras);
20
20
  const contextFolderPath = (0, _constants.joinWithAppPath)(context);
21
21
  const defaultAppliedOptions = { ...options,
22
22
  // eslint-disable-next-line no-nested-ternary
@@ -15,6 +15,16 @@ var _default = {
15
15
  },
16
16
  devtool: 'source-map',
17
17
  statsLogConfig: null,
18
+ stats: {
19
+ enable: {
20
+ value: false,
21
+ cli: 'enable_stats',
22
+ type: 'boolean'
23
+ },
24
+ fileName: null,
25
+ options: null,
26
+ excludeKeys: null
27
+ },
18
28
  enableFileNameHashing: {
19
29
  value: false,
20
30
  cli: 'enable_hash'
@@ -210,6 +220,11 @@ var _default = {
210
220
  outputFile: {
211
221
  value: 'efc-sdk-[version].js',
212
222
  cli: 'efc_output'
223
+ },
224
+ resourceCleanup: {
225
+ value: false,
226
+ cli: 'enable_efc_resource_cleanup',
227
+ type: 'boolean'
213
228
  }
214
229
  },
215
230
  createSeparateSMap: {
@@ -307,6 +322,7 @@ var _default = {
307
322
  jsAttributes: null,
308
323
  cssAttributes: null,
309
324
  i18nAttributes: null
310
- }
325
+ },
326
+ externals: null
311
327
  };
312
328
  exports.default = _default;
@@ -119,7 +119,8 @@ var _default = {
119
119
  version: 'v1',
120
120
  createSDkFile: false,
121
121
  templateFilePath: 'efcTemplate.js',
122
- outputFile: 'efc-sdk-[version].js'
122
+ outputFile: 'efc-sdk-[version].js',
123
+ resourceCleanup: false
123
124
  },
124
125
  createSeparateSMap: false,
125
126
  babelCustomizations: {
@@ -175,6 +176,12 @@ var _default = {
175
176
  templateFilePath: 'sw.js',
176
177
  outputFilePath: '/v1.js',
177
178
  replaceText: '//<!--AssetsFromBuild -->'
179
+ },
180
+ stats: {
181
+ enable: false,
182
+ fileName: null,
183
+ options: null,
184
+ excludeKeys: null
178
185
  }
179
186
  };
180
187
  exports.default = _default;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getGlobalCacheStorageName = getGlobalCacheStorageName;
6
7
  exports.getWebpackMode = getWebpackMode;
7
8
  exports.isDevelopmentMode = isDevelopmentMode;
8
9
  exports.isNotProduction = isNotProduction;
@@ -23,6 +24,13 @@ function getWebpackMode(options) {
23
24
  return isProductionMode(mode) ? 'production' : 'development';
24
25
  }
25
26
 
27
+ function getGlobalCacheStorageName(options) {
28
+ const {
29
+ context
30
+ } = options;
31
+ return `${context}Jsonp`;
32
+ }
33
+
26
34
  function isNotProduction(options) {
27
35
  const {
28
36
  mode
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BundleIntegrityReport = void 0;
7
+
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ var _stream = require("stream");
13
+
14
+ var _objectManipulation = require("../../utils/object-manipulation");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const pluginName = 'BundleIntegrityReportPlugin';
19
+
20
+ class BundleIntegrityReport {
21
+ constructor({
22
+ options,
23
+ excludeKeysInReport,
24
+ fileName
25
+ }) {
26
+ this.excludeKeysInStat = excludeKeysInReport;
27
+ this.statsFileName = fileName;
28
+ this.statsOptions = options;
29
+ }
30
+
31
+ apply(compiler) {
32
+ compiler.hooks.done.tapAsync(pluginName, (stats, callback) => {
33
+ const statsJson = (0, _objectManipulation.removeKeysFromObject)(stats.toJson(this.statsOptions), this.excludeKeysInStat);
34
+ this.emitStats(statsJson).on('end', () => {
35
+ callback();
36
+ }).on('error', e => {
37
+ callback(e);
38
+ });
39
+ });
40
+ }
41
+
42
+ writeStatsFileInAStream(statsObj) {
43
+ const {
44
+ outputPath
45
+ } = statsObj;
46
+
47
+ const ouputFileName = _path.default.join(outputPath, this.statsFileName);
48
+
49
+ return this.createReadStream(statsObj).pipe(_fs.default.createWriteStream(ouputFileName));
50
+ }
51
+
52
+ createReadStream(statsObj) {
53
+ const excludeKeys = this.excludeKeysInStat;
54
+ return new _stream.Readable({
55
+ read() {
56
+ let isDone = false;
57
+ const objToStringGen = (0, _objectManipulation.convertObjectToStringGen)(statsObj, excludeKeys);
58
+
59
+ while (!isDone) {
60
+ const {
61
+ done,
62
+ value
63
+ } = objToStringGen.next();
64
+
65
+ if (done) {
66
+ isDone = true;
67
+ this.push(null);
68
+ } else {
69
+ this.push(value);
70
+ }
71
+ }
72
+ }
73
+
74
+ });
75
+ }
76
+
77
+ emitStats(statsJson) {
78
+ return this.writeStatsFileInAStream(statsJson);
79
+ }
80
+
81
+ }
82
+
83
+ exports.BundleIntegrityReport = BundleIntegrityReport;
@@ -7,12 +7,20 @@ exports.default = void 0;
7
7
 
8
8
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
9
 
10
- var _nameTemplates = require("../common/nameTemplates");
10
+ var _webpack = require("webpack");
11
+
12
+ var _nameTemplates = require("../../common/nameTemplates");
13
+
14
+ var _modeUtils = require("../../common/modeUtils");
15
+
16
+ var _webpackCustomJsUrlLoader = _interopRequireDefault(require("./webpackCustomJsUrlLoader"));
11
17
 
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
19
 
14
20
  // import { RuntimeGlobals, RuntimeModule } from 'webpack';
21
+ // eslint-disable-next-line import/extensions
15
22
  // import { Template } from 'webpack';
23
+ // eslint-disable-next-line import/extensions
16
24
  const pluginName = 'CdnChangePlugin'; // const MODULE_TYPE = 'css/mini-extract';
17
25
  // class CdnChangeRuntimePlugin extends RuntimeModule {
18
26
  // constructor(compiler, { variableName }) {
@@ -34,6 +42,7 @@ class CdnChangePlugin {
34
42
  this.variableName = options.variableName || '__CSS_CDN__';
35
43
  this.cssTemplate = options.cssTemplate || '{{__CSS_CDN__}}';
36
44
  this.jsTemplate = options.jsTemplate || '{{__JS_CDN__}}';
45
+ this.mode = options.mode || 'prod';
37
46
  }
38
47
 
39
48
  apply(compiler) {
@@ -61,13 +70,14 @@ class CdnChangePlugin {
61
70
  compiler.hooks.compilation.tap(pluginName, compilation => {
62
71
  _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, (data, cb) => {
63
72
  const {
64
- createSeparateSMap
73
+ createSeparateSMap,
74
+ mode
65
75
  } = this; // eslint-disable-next-line no-param-reassign
66
76
 
67
77
  data.assets = { ...data.assets,
68
78
  css: data.assets.css.map(css => `${this.cssTemplate}${css}`),
69
79
  js: data.assets.js.map(js => {
70
- if (createSeparateSMap && !(0, _nameTemplates.isI18nFile)(js)) {
80
+ if (((0, _modeUtils.isProductionMode)(mode) || createSeparateSMap) && !(0, _nameTemplates.isI18nFile)(js)) {
71
81
  js = js.replace('js/', `{{--js-smap}}js/`); //eslint-disable-line
72
82
  }
73
83
 
@@ -76,6 +86,12 @@ class CdnChangePlugin {
76
86
  };
77
87
  cb && cb(null, data);
78
88
  });
89
+
90
+ compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.getChunkScriptFilename).tap(pluginName, (chunk, set) => {
91
+ compilation.addRuntimeModule(chunk, // eslint-disable-next-line new-cap
92
+ new _webpackCustomJsUrlLoader.default('javascript', 'javascript', _webpack.RuntimeGlobals.getChunkScriptFilename, chunk => chunk.filenameTemplate || (chunk.canBeInitial() ? compilation.outputOptions.filename : compilation.outputOptions.chunkFilename), false));
93
+ return true;
94
+ });
79
95
  });
80
96
  }
81
97
 
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _webpack = require("webpack");
9
+
10
+ const first = set => {
11
+ const entry = set.values().next();
12
+ return entry.done ? undefined : entry.value;
13
+ };
14
+
15
+ class CustomizedGetChunkFilenameRuntimeModule extends _webpack.RuntimeModule {
16
+ /**
17
+ * @param {string} contentType the contentType to use the content hash for
18
+ * @param {string} name kind of filename
19
+ * @param {string} global function name to be assigned
20
+ * @param {function(Chunk): string | FilenameFunction} getFilenameForChunk functor to get the filename or function
21
+ * @param {boolean} allChunks when false, only async chunks are included
22
+ */
23
+ constructor(contentType, name, global, getFilenameForChunk, allChunks) {
24
+ super(`get ${name} chunk filename`);
25
+ this.contentType = contentType;
26
+ this.global = global;
27
+ this.getFilenameForChunk = getFilenameForChunk;
28
+ this.allChunks = allChunks;
29
+ this.dependentHash = true;
30
+ }
31
+
32
+ generate() {
33
+ const {
34
+ global,
35
+ chunk,
36
+ chunkGraph,
37
+ contentType,
38
+ getFilenameForChunk,
39
+ allChunks,
40
+ compilation
41
+ } = this;
42
+ const {
43
+ runtimeTemplate
44
+ } = compilation;
45
+ /** @type {Map<string | FilenameFunction, Set<Chunk>>} */
46
+
47
+ const chunkFilenames = new Map();
48
+ let maxChunks = 0;
49
+ /** @type {string} */
50
+
51
+ let dynamicFilename;
52
+ /**
53
+ * @param {Chunk} c the chunk
54
+ * @returns {void}
55
+ */
56
+
57
+ const addChunk = c => {
58
+ const chunkFilename = getFilenameForChunk(c);
59
+
60
+ if (chunkFilename) {
61
+ let set = chunkFilenames.get(chunkFilename);
62
+
63
+ if (set === undefined) {
64
+ chunkFilenames.set(chunkFilename, set = new Set());
65
+ }
66
+
67
+ set.add(c);
68
+
69
+ if (typeof chunkFilename === 'string') {
70
+ if (set.size < maxChunks) return;
71
+
72
+ if (set.size === maxChunks) {
73
+ if (chunkFilename.length < dynamicFilename.length) return;
74
+
75
+ if (chunkFilename.length === dynamicFilename.length) {
76
+ if (chunkFilename < dynamicFilename) return;
77
+ }
78
+ }
79
+
80
+ maxChunks = set.size;
81
+ dynamicFilename = chunkFilename;
82
+ }
83
+ }
84
+ };
85
+ /** @type {string[]} */
86
+
87
+
88
+ const includedChunksMessages = [];
89
+
90
+ if (allChunks) {
91
+ includedChunksMessages.push('all chunks');
92
+
93
+ for (const c of chunk.getAllReferencedChunks()) {
94
+ addChunk(c);
95
+ }
96
+ } else {
97
+ includedChunksMessages.push('async chunks');
98
+
99
+ for (const c of chunk.getAllAsyncChunks()) {
100
+ addChunk(c);
101
+ }
102
+
103
+ const includeEntries = chunkGraph.getTreeRuntimeRequirements(chunk).has(_webpack.RuntimeGlobals.ensureChunkIncludeEntries);
104
+
105
+ if (includeEntries) {
106
+ includedChunksMessages.push('sibling chunks for the entrypoint');
107
+
108
+ for (const c of chunkGraph.getChunkEntryDependentChunksIterable(chunk)) {
109
+ addChunk(c);
110
+ }
111
+ }
112
+ }
113
+
114
+ for (const entrypoint of chunk.getAllReferencedAsyncEntrypoints()) {
115
+ addChunk(entrypoint.chunks[entrypoint.chunks.length - 1]);
116
+ }
117
+ /** @type {Map<string, Set<string | number>>} */
118
+
119
+
120
+ const staticUrls = new Map();
121
+ /** @type {Set<Chunk>} */
122
+
123
+ const dynamicUrlChunks = new Set();
124
+ /**
125
+ * @param {Chunk} c the chunk
126
+ * @param {string | FilenameFunction} chunkFilename the filename template for the chunk
127
+ * @returns {void}
128
+ */
129
+
130
+ const addStaticUrl = (c, chunkFilename) => {
131
+ /**
132
+ * @param {string | number} value a value
133
+ * @returns {string} string to put in quotes
134
+ */
135
+ const unquotedStringify = value => {
136
+ const str = `${value}`;
137
+
138
+ if (str.length >= 5 && str === `${c.id}`) {
139
+ // This is shorter and generates the same result
140
+ return '" + chunkId + "';
141
+ }
142
+
143
+ const s = JSON.stringify(str);
144
+ return s.slice(1, s.length - 1);
145
+ };
146
+
147
+ const unquotedStringifyWithLength = value => length => unquotedStringify(`${value}`.slice(0, length));
148
+
149
+ const chunkFilenameValue = typeof chunkFilename === 'function' ? JSON.stringify(chunkFilename({
150
+ chunk: c,
151
+ contentHashType: contentType
152
+ })) : JSON.stringify(chunkFilename);
153
+ const staticChunkFilename = compilation.getPath(chunkFilenameValue, {
154
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
155
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
156
+ chunk: {
157
+ id: unquotedStringify(c.id),
158
+ hash: unquotedStringify(c.renderedHash),
159
+ hashWithLength: unquotedStringifyWithLength(c.renderedHash),
160
+ name: unquotedStringify(c.name || c.id),
161
+ contentHash: {
162
+ [contentType]: unquotedStringify(c.contentHash[contentType])
163
+ },
164
+ contentHashWithLength: {
165
+ [contentType]: unquotedStringifyWithLength(c.contentHash[contentType])
166
+ }
167
+ },
168
+ contentHashType: contentType
169
+ });
170
+ let set = staticUrls.get(staticChunkFilename);
171
+
172
+ if (set === undefined) {
173
+ staticUrls.set(staticChunkFilename, set = new Set());
174
+ }
175
+
176
+ set.add(c.id);
177
+ };
178
+
179
+ for (const [filename, chunks] of chunkFilenames) {
180
+ if (filename !== dynamicFilename) {
181
+ for (const c of chunks) addStaticUrl(c, filename);
182
+ } else {
183
+ for (const c of chunks) dynamicUrlChunks.add(c);
184
+ }
185
+ }
186
+ /**
187
+ * @param {function(Chunk): string | number} fn function from chunk to value
188
+ * @returns {string} code with static mapping of results of fn
189
+ */
190
+
191
+
192
+ const createMap = fn => {
193
+ const obj = {};
194
+ let useId = false;
195
+ let lastKey;
196
+ let entries = 0; // eslint-disable-next-line no-restricted-syntax
197
+
198
+ for (const c of dynamicUrlChunks) {
199
+ const value = fn(c);
200
+
201
+ if (value === c.id) {
202
+ useId = true;
203
+ } else {
204
+ obj[c.id] = value;
205
+ lastKey = c.id;
206
+ entries++;
207
+ }
208
+ }
209
+
210
+ if (entries === 0) return 'chunkId';
211
+
212
+ if (entries === 1) {
213
+ return useId ? `(chunkId === ${JSON.stringify(lastKey)} ? ${JSON.stringify(obj[lastKey])} : chunkId)` : JSON.stringify(obj[lastKey]);
214
+ }
215
+
216
+ return useId ? `(${JSON.stringify(obj)}[chunkId] || chunkId)` : `${JSON.stringify(obj)}[chunkId]`;
217
+ };
218
+ /**
219
+ * @param {function(Chunk): string | number} fn function from chunk to value
220
+ * @returns {string} code with static mapping of results of fn for including in quoted string
221
+ */
222
+
223
+
224
+ const mapExpr = fn => {
225
+ return `" + ${createMap(fn)} + "`;
226
+ };
227
+ /**
228
+ * @param {function(Chunk): string | number} fn function from chunk to value
229
+ * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
230
+ */
231
+
232
+
233
+ const mapExprWithLength = fn => length => {
234
+ return `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
235
+ };
236
+
237
+ const url = dynamicFilename && compilation.getPath(JSON.stringify(dynamicFilename), {
238
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
239
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
240
+ chunk: {
241
+ id: `" + chunkId + "`,
242
+ hash: mapExpr(c => c.renderedHash),
243
+ hashWithLength: mapExprWithLength(c => c.renderedHash),
244
+ name: mapExpr(c => c.name || c.id),
245
+ contentHash: {
246
+ [contentType]: mapExpr(c => c.contentHash[contentType])
247
+ },
248
+ contentHashWithLength: {
249
+ [contentType]: mapExprWithLength(c => c.contentHash[contentType])
250
+ }
251
+ },
252
+ contentHashType: contentType
253
+ });
254
+ const cdn = `__CSS_CDN__`;
255
+ return _webpack.Template.asString([`// This function allow to reference ${includedChunksMessages.join(' and ')}`, `${global} = ${runtimeTemplate.basicFunction('chunkId', staticUrls.size > 0 ? ['// return url for filenames not based on template', // it minimizes to `x===1?"...":x===2?"...":"..."`
256
+ _webpack.Template.asString(Array.from(staticUrls, ([url, ids]) => {
257
+ const condition = ids.size === 1 ? `chunkId === ${JSON.stringify(first(ids))}` : `{${Array.from(ids, id => `${JSON.stringify(id)}:1`).join(',')}}[chunkId]`;
258
+ return `if (${condition}) return window.${cdn}+${url};`;
259
+ })), '// return url for filenames based on template', `return window.${cdn}+${url};`] : ['// return url for filenames based on template', `return window.${cdn}+${url};`])};`]);
260
+ }
261
+
262
+ }
263
+
264
+ var _default = CustomizedGetChunkFilenameRuntimeModule;
265
+ exports.default = _default;
@@ -136,6 +136,8 @@ class I18nFilesEmitPlugin {
136
136
  const fileName = fileNameTemplate.replaceAll('[locale]', locale);
137
137
  const filename = (0, _pathCreator.pathCreator)(fileName, compilation, {
138
138
  hash: compilation.hash,
139
+ locale,
140
+ chunkName: chunk.name,
139
141
  chunkId: chunk.id,
140
142
  chunkHash: chunk.hash,
141
143
  contentHash
@@ -45,14 +45,13 @@ class ResourceHintsPlugin {
45
45
  }
46
46
 
47
47
  enabledChunks.add(entryRuntimeChunk);
48
- set.add(_webpack.RuntimeGlobals.getFullHash);
49
- set.add(_webpack.RuntimeGlobals.getChunkCssFilename);
48
+ set.add(_webpack.RuntimeGlobals.getFullHash); // set.add(RuntimeGlobals.getChunkCssFilename);
49
+
50
50
  const {
51
51
  publicPathsTemplateObj
52
52
  } = this;
53
53
  compilation.addRuntimeModule(entryRuntimeChunk, // eslint-disable-next-line no-use-before-define
54
- new ResourceHintsRuntimePlugin(set, {
55
- compiler,
54
+ new ResourceHintsRuntimePlugin(compiler, {
56
55
  chunk: entryRuntimeChunk,
57
56
  allowPrefetchingMultipleChunks: this.allowPrefetchingMultipleChunks,
58
57
  publicPathsTemplateObj
@@ -95,17 +94,26 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
95
94
  needsMap = true;
96
95
  }
97
96
  });
98
- const {
99
- js: jsPP = '',
100
- css: cssPP = '',
101
- i18n: i18nPP = ''
97
+ let {
98
+ js: jsPP,
99
+ css: cssPP,
100
+ i18n: i18nPP
102
101
  } = this.publicPathsTemplateObj;
103
- return _webpack.Template.asString([`
104
- const preloadedChunks = {};
105
- const nameToChunkIdMap = ${JSON.stringify(needsMap ? nameIdMap : {})};
106
- const chunkNames = Object.keys(nameToChunkIdMap);
107
-
108
- function createLinkTag(href, rel) {
102
+ jsPP = jsPP || _webpack.RuntimeGlobals.publicPath;
103
+ cssPP = cssPP || _webpack.RuntimeGlobals.publicPath;
104
+ i18nPP = i18nPP || _webpack.RuntimeGlobals.publicPath;
105
+ /**
106
+ * naming abbr
107
+ * ntc -> nameToChunkIdMap
108
+ * cns -> chunkNames
109
+ * clt -> createLinkTag
110
+ * lpp -> loadAsPreloadOrPrefetch
111
+ */
112
+
113
+ return _webpack.Template.asString([`const ntc = ${JSON.stringify(needsMap ? nameIdMap : {})};
114
+ const cns = Object.keys(ntc);
115
+
116
+ function clt(href, rel) {
109
117
  let link = document.createElement("link");
110
118
  link.href = href;
111
119
  link.rel = rel;
@@ -120,26 +128,24 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
120
128
  //return !url.includes(".undefined.");
121
129
  return url.indexOf(".undefined.") === -1;
122
130
  }
123
- function loadAsPreloadOrPrefetch(_chunkId, rel) {
131
+ function lpp(_chunkId, rel) {
124
132
  let chunkId = ${_webpack.RuntimeGlobals.require}.getChunkId(_chunkId);
125
133
  // ${_webpack.RuntimeGlobals.require}.e(chunkId);
126
- if(__webpack_require__.O.j(chunkId) || preloadedChunks[chunkId]) {
127
- preloadedChunks[chunkId] = true;
128
- // console.log("skipped loadAsPreloadOrPrefetch", _chunkId, chunkId, rel);
134
+ if(__webpack_require__.O.j(chunkId)) {
129
135
  return;
130
136
  }
131
137
  const jsUrl = ${jsPP} + __webpack_require__.u(chunkId);
132
138
  const cssUrl = ${cssPP} + __webpack_require__.miniCssF(chunkId);
133
- isValidUrl(jsUrl) && createLinkTag(jsUrl, rel);
134
- isValidUrl(cssUrl) && createLinkTag(cssUrl, rel);
139
+ isValidUrl(jsUrl) && clt(jsUrl, rel);
140
+ isValidUrl(cssUrl) && clt(cssUrl, rel);
135
141
  if(__webpack_require__.miniI18nF) {
136
142
  const i18nUrl = ${i18nPP} + __webpack_require__.miniI18nF(chunkId);
137
- isValidUrl(i18nUrl) && createLinkTag(i18nUrl, rel);
143
+ isValidUrl(i18nUrl) && clt(i18nUrl, rel);
138
144
  }
139
145
  }
140
146
 
141
147
  ${_webpack.RuntimeGlobals.require}.getChunkId = function getChunkId(chunkId) {
142
- ${needsMap ? 'chunkId = nameToChunkIdMap[chunkId]||chunkId;' : ''}
148
+ ${needsMap ? 'chunkId = ntc[chunkId]||chunkId;' : ''}
143
149
  return chunkId;
144
150
  }
145
151
  ${_webpack.RuntimeGlobals.require}.getChunkIds = function getChunkIds(chunkId) {
@@ -147,30 +153,25 @@ class ResourceHintsRuntimePlugin extends _webpack.RuntimeModule {
147
153
  this.allowPrefetchingMultipleChunks ? `
148
154
  const isRegExAsChunkId = chunkId instanceof RegExp;
149
155
  if(isRegExAsChunkId) {
150
- return chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]);
151
- }` : ''}
152
- return [${_webpack.RuntimeGlobals.require}.getChunkId(chunkId)];
156
+ return cns.filter(chunkName => chunkId.test(chunkName)).map(chunkName => ntc[chunkName]);
157
+ }
158
+ return [${_webpack.RuntimeGlobals.require}.getChunkId(chunkId)];
159
+ ` : `return [${_webpack.RuntimeGlobals.require}.getChunkId(chunkId)];`}
153
160
  }
154
161
  // Prefetch a chunk (${pluginName})
155
162
  ${_webpack.RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {
156
- loadAsPreloadOrPrefetch(chunkId, "prefetch");
157
- ${this.allowPrefetchingMultipleChunks ? `
158
- let chunkIds = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId)
163
+ ${`
164
+ let chunkIds = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId);
159
165
  chunkIds.forEach(idOfAChunk => {
160
- // ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
161
- loadAsPreloadOrPrefetch(idOfAChunk, "prefetch");
162
- })` : 'loadAsPreloadOrPrefetch(chunkId, "prefetch");'}
166
+ ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
167
+ })`}
163
168
  };
164
169
 
165
170
  // Preload a chunk (${pluginName})
166
171
  ${_webpack.RuntimeGlobals.require}.plc = function preloadChunk(chunkId) {
167
- ${this.allowPrefetchingMultipleChunks ? `
168
- let chunkIds = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId)
169
- chunkIds.forEach(idOfAChunk => {
170
- // ${_webpack.RuntimeGlobals.require}.e(idOfAChunk);
171
- loadAsPreloadOrPrefetch(idOfAChunk, "preload");
172
- })` : 'loadAsPreloadOrPrefetch(chunkId, "preload");'}
173
- };
172
+ let idOfAChunk = ${_webpack.RuntimeGlobals.require}.getChunkIds(chunkId)[0];
173
+ lpp(idOfAChunk, "preload");
174
+ }
174
175
  ` // `// Prefetch a chunk (${pluginName})`,
175
176
  // `${RuntimeGlobals.require}.pfc = function prefetchChunk(chunkId) {`,
176
177
  // Template.indent([
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _webpack = require("webpack");
9
+
10
+ const pluginName = 'RuntimeResourceCleanupPlugin';
11
+
12
+ class RuntimeResourceCleanup {
13
+ constructor({
14
+ enable: scriptCleanUpEnabled,
15
+ chunkLoadingGlobal,
16
+ ...options
17
+ }) {
18
+ this.options = options;
19
+ this.scriptCleanUpEnabled = scriptCleanUpEnabled;
20
+ this.chunkLoadingGlobal = chunkLoadingGlobal;
21
+ }
22
+
23
+ apply(compiler) {
24
+ compiler.hooks.compilation.tap(pluginName, compilation => {
25
+ compilation.hooks.processAssets.tap({
26
+ name: pluginName,
27
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
28
+ }, assets => {
29
+ const runtimeFiles = Object.keys(assets).filter(assetName => /.+?runtime.*\.js$/.test(assetName));
30
+ const searchString = 'chunkLoadingGlobal.forEach';
31
+
32
+ function generateScriptCleanUpCode(attributes) {
33
+ const [[attributeKey, attributeValue]] = Object.entries(attributes);
34
+ const selectorForGettingResources = `[${attributeKey}="${attributeValue}"]`;
35
+ return `
36
+ document.querySelectorAll('${selectorForGettingResources}').forEach(resource => resource.remove());
37
+ `;
38
+ }
39
+
40
+ function generateRunTimeObjectCleanupCode() {
41
+ return `
42
+ Object.keys(__webpack_modules__).forEach(moduleKey => __webpack_modules__[moduleKey] = null);
43
+ Object.keys(__webpack_module_cache__).forEach(moduleCacheKey => __webpack_module_cache__[moduleCacheKey] = null);
44
+ __webpack_modules__ = null;
45
+ __webpack_module_cache__ = null;
46
+ Object.keys(__webpack_require__).forEach(staticMethodsKey => __webpack_require__[staticMethodsKey] = null);
47
+ __webpack_require__ = null;
48
+ `;
49
+ }
50
+
51
+ function attachUninstallMethodToChunkGlobal() {
52
+ const {
53
+ chunkLoadingGlobal
54
+ } = this;
55
+ return `self['${chunkLoadingGlobal}'].unInstall = function() {
56
+ ${generateRunTimeObjectCleanupCode()};
57
+ ${this.scriptCleanUpEnabled ? generateScriptCleanUpCode(this.options.attributes) : ''}
58
+ }`;
59
+ }
60
+
61
+ runtimeFiles.forEach(runtTimeFile => {
62
+ const runTimeSource = assets[runtTimeFile].source();
63
+ const newRunTimeCode = runTimeSource.replace(searchString, `${attachUninstallMethodToChunkGlobal.call(this)};${searchString}`);
64
+ const newRunTimeResource = new compiler.webpack.sources.RawSource(newRunTimeCode);
65
+ compilation.updateAsset(runtTimeFile, newRunTimeResource);
66
+ });
67
+ });
68
+ });
69
+ }
70
+
71
+ }
72
+
73
+ exports.default = RuntimeResourceCleanup;
@@ -8,7 +8,20 @@ exports.SourceMapPlugin = void 0;
8
8
  var _webpack = require("webpack");
9
9
 
10
10
  /* eslint-disable class-methods-use-this */
11
- const pluginName = 'SplitSourceMapPlugin';
11
+ function checkSmapFilePattern(assetName) {
12
+ return /\.js$/.test(assetName) && !/\.i18n\.js$/.test(assetName) || /\.js\.map$/.test(assetName) && !/\.i18n\.js\.map$/.test(assetName);
13
+ }
14
+
15
+ function skipRuntimeFiles(assetName) {
16
+ return !assetName.includes('runtime') || !assetName.includes('[locale]');
17
+ }
18
+
19
+ const pluginName = 'SplitSourceMapPlugin'; // Purpose:
20
+
21
+ /**
22
+ * we want build that can load files source map and without sourcemap at the same time,
23
+ * or can be mentioned as so single build need to support two different clients that one for fast load and one for debugging.
24
+ */
12
25
 
13
26
  class SourceMapPlugin {
14
27
  apply(compiler) {
@@ -23,7 +36,8 @@ class SourceMapPlugin {
23
36
  Object.keys(assets).forEach(assetName => {
24
37
  const assetCode = assets[assetName].source();
25
38
 
26
- if (/\.js$/.test(assetName) && !/\.i18n\.js$/.test(assetName) || /\.js\.map$/.test(assetName) && !/\.i18n\.js\.map$/.test(assetName)) {
39
+ if (checkSmapFilePattern(assetName) // skipRuntimeFiles(assetName)
40
+ ) {
27
41
  compilation.renameAsset(assetName, `smap/${assetName}`);
28
42
 
29
43
  if (!/\.map$/.test(assetName)) {
@@ -7,7 +7,11 @@ exports.externals = externals;
7
7
 
8
8
  // eslint-disable-next-line no-unused-vars
9
9
  function externals(options) {
10
+ const {
11
+ externals
12
+ } = options;
10
13
  return {
11
- ZC: '$ZC'
14
+ ZC: '$ZC',
15
+ ...externals
12
16
  };
13
17
  }
@@ -11,19 +11,20 @@ var _constants = require("../../constants");
11
11
 
12
12
  var _nameTemplates = require("./common/nameTemplates");
13
13
 
14
+ var _modeUtils = require("./common/modeUtils");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  function outputConfig(options) {
17
19
  const {
18
20
  output,
19
21
  publicPath,
20
- htmlTemplate,
21
- context
22
+ htmlTemplate
22
23
  } = options;
23
24
  const outputO = {
24
25
  filename: (0, _nameTemplates.nameTemplates)('js', options),
25
26
  chunkFilename: (0, _nameTemplates.nameTemplates)('chunkjs', options),
26
- chunkLoadingGlobal: `${context}Jsonp`,
27
+ chunkLoadingGlobal: (0, _modeUtils.getGlobalCacheStorageName)(options),
27
28
  publicPath,
28
29
  // clean: true,
29
30
  path: _path.default.resolve(_constants.appPath, output)
@@ -25,16 +25,16 @@ function configBundleAnalyzer(options) {
25
25
  function getBundleAnalyzerOptions(options) {
26
26
  return {
27
27
  analyzerMode: 'static',
28
- generateStatsFile: true,
29
- openAnalyzer: false,
30
- statsOptions: {
31
- source: false,
32
- normal: true,
33
- chunks: false,
34
- chunkGroups: false,
35
- module: false,
36
- assets: true,
37
- assetsSort: 'name'
38
- }
28
+ // generateStatsFile: false,
29
+ openAnalyzer: false // statsOptions: {
30
+ // source: false,
31
+ // normal: true,
32
+ // chunks: false,
33
+ // chunkGroups: false,
34
+ // module: false,
35
+ // assets: true,
36
+ // assetsSort: 'name'
37
+ // }
38
+
39
39
  };
40
40
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configBundleIntegrityReport = configBundleIntegrityReport;
7
+
8
+ var _modeUtils = require("../common/modeUtils");
9
+
10
+ var _BundleIntegrityReport = require("../custom_plugins/BundleIntegrityReport");
11
+
12
+ function configBundleIntegrityReport(options) {
13
+ const webpackMode = (0, _modeUtils.getWebpackMode)(options);
14
+ const isProduction = (0, _modeUtils.isProductionMode)(webpackMode);
15
+ const {
16
+ enable: statsEnable
17
+ } = options.stats;
18
+
19
+ if (isProduction && statsEnable) {
20
+ return new _BundleIntegrityReport.BundleIntegrityReport({
21
+ fileName: options.stats.fileName || 'bundle-report-integrity.json',
22
+ excludeKeysInReport: options.stats.excludeKeys || [],
23
+ options: {
24
+ preset: 'verbose',
25
+ ...options.stats.options,
26
+ assets: true,
27
+ chunks: true,
28
+ modules: true,
29
+ builtAt: true,
30
+ hash: true
31
+ }
32
+ });
33
+ }
34
+
35
+ return null;
36
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configRuntimeResourceCleanup = configRuntimeResourceCleanup;
7
+
8
+ var _modeUtils = require("../common/modeUtils");
9
+
10
+ var _RuntimeResourceCleanup = _interopRequireDefault(require("../custom_plugins/RuntimeResourceCleanup"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function configRuntimeResourceCleanup(options) {
15
+ const chunkLoadingGlobal = (0, _modeUtils.getGlobalCacheStorageName)(options);
16
+ const {
17
+ resourceCleanup: runtimeResourceCleanupEnabled,
18
+ hasEFC: efcEnabled
19
+ } = options.efc;
20
+ const {
21
+ customAttributes = {}
22
+ } = options;
23
+
24
+ if (efcEnabled && runtimeResourceCleanupEnabled) {
25
+ return new _RuntimeResourceCleanup.default({ ...customAttributes,
26
+ chunkLoadingGlobal
27
+ });
28
+ }
29
+
30
+ return null;
31
+ }
@@ -43,10 +43,14 @@ var _configTPHashMappingPlugin = require("./pluginConfigs/configTPHashMappingPlu
43
43
 
44
44
  var _configCustomAttributesPlugin = require("./pluginConfigs/configCustomAttributesPlugin");
45
45
 
46
+ var _configBundleIntegrityReport = require("./pluginConfigs/configBundleIntegrityReport");
47
+
48
+ var _configRuntimeResourceCleanup = require("./pluginConfigs/configRuntimeResourceCleanup");
49
+
46
50
  // import { IgnorePlugin } from 'webpack';
47
51
  function plugins(options) {
48
52
  const {
49
53
  webpackPlugins
50
54
  } = options;
51
- 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, _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), ...webpackPlugins].filter(Boolean);
55
+ 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, _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), ...webpackPlugins].filter(Boolean);
52
56
  }
@@ -36,17 +36,14 @@ function splitChunksConfig(options) {
36
36
  minChunks: 1,
37
37
  test: isReact,
38
38
  enforce: true,
39
- // priority: 10
40
- priority: 0
39
+ priority: 30
41
40
  },
42
41
  vendor: {
43
42
  name: 'vendor',
44
43
  chunks: 'all',
45
- // chunks: 'initial',
46
44
  minChunks: 1,
47
45
  test: isVendor,
48
- // priority: 19,
49
- priority: 0
46
+ priority: 20
50
47
  }
51
48
  };
52
49
  const customChunksConfig = {};
@@ -56,16 +53,17 @@ function splitChunksConfig(options) {
56
53
  const obj = getCacheGroup(cacheGroupObj, index);
57
54
  customChunksConfig[cacheGroupName] = obj;
58
55
  });
59
- return {
56
+ const splitChunksConfig = {
60
57
  minSize: 12000,
61
58
  ...(customChunksBaseConfig || {}),
62
59
  cacheGroups: {
63
60
  default: false,
64
- vendors: false,
61
+ defaultVendors: false,
65
62
  ...defaultChunks,
66
63
  ...customChunksConfig
67
64
  }
68
65
  };
66
+ return splitChunksConfig;
69
67
  }
70
68
 
71
69
  function getCacheGroup(obj, index) {
@@ -75,16 +73,17 @@ function getCacheGroup(obj, index) {
75
73
  chunks = 'all'
76
74
  } = obj;
77
75
  const {
76
+ name,
78
77
  patterns,
79
78
  enforce,
80
79
  minSize,
81
80
  maxSize,
82
81
  reuseExistingChunk,
83
- name
82
+ automaticNameDelimiter
84
83
  } = obj;
84
+ chunks = obj.chunks || 'all';
85
85
  minChunks = obj.minChunks || 2;
86
86
  priority = obj.priority || 10 * (index + 2);
87
- chunks = obj.chunks || 'all';
88
87
  const cacheGroup = {
89
88
  name,
90
89
  test: m => {
@@ -92,9 +91,9 @@ function getCacheGroup(obj, index) {
92
91
  return userRequest && (0, _checkIsPatternsMatchFilename.checkIsPatternsMatchFilename)(patterns, userRequest);
93
92
  },
94
93
  chunks,
95
- enforce,
96
94
  minChunks,
97
- priority
95
+ priority,
96
+ enforce
98
97
  };
99
98
 
100
99
  if (minSize !== undefined) {
@@ -109,5 +108,9 @@ function getCacheGroup(obj, index) {
109
108
  cacheGroup.reuseExistingChunk = reuseExistingChunk;
110
109
  }
111
110
 
111
+ if (automaticNameDelimiter !== undefined) {
112
+ cacheGroup.automaticNameDelimiter = automaticNameDelimiter;
113
+ }
114
+
112
115
  return cacheGroup;
113
116
  }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertObjectToStringGen = convertObjectToStringGen;
7
+ exports.removeKeysFromObject = removeKeysFromObject;
8
+
9
+ /* eslint-disable no-restricted-syntax */
10
+ function objectPathMatcher(currentKey, objHierarchy = [], keysToBeRemoved = []) {
11
+ const objPathKey = objHierarchy.length > 0 ? `${objHierarchy.join('.')}.${currentKey}` : currentKey;
12
+ return keysToBeRemoved.some(key => {
13
+ const isWildPath = /^\*/.test(key);
14
+
15
+ if (isWildPath) {
16
+ const newKey = key.replace(/\*\.?/, '');
17
+ return objPathKey.includes(newKey);
18
+ }
19
+
20
+ return key === objPathKey;
21
+ });
22
+ }
23
+ /*
24
+ 1) *.keyTobeRemoved -> means match every object path, this key will be removed
25
+ 2) keyToBeremoved -> means root object key
26
+ 3) nestedPath.keyToBeRemoved -> means only that nested path key
27
+ 4) don't need to account for array iteration, just object key path is enough in the key to be removed.
28
+ */
29
+
30
+
31
+ function removeKeysFromObject(obj, keysToBeRemoved, prevKeys = []) {
32
+ if (Array.isArray(obj)) {
33
+ return obj.map(item => removeKeysFromObject(item, keysToBeRemoved, prevKeys));
34
+ }
35
+
36
+ if (obj && typeof obj === 'object') {
37
+ const filteredKeyObject = {};
38
+ const ObjectKeys = Object.keys(obj);
39
+
40
+ for (const objectKey of ObjectKeys) {
41
+ const isKeyToBeRemoved = objectPathMatcher(objectKey, prevKeys, keysToBeRemoved);
42
+
43
+ if (!isKeyToBeRemoved) {
44
+ filteredKeyObject[objectKey] = removeKeysFromObject(obj[objectKey], keysToBeRemoved, [...prevKeys, objectKey]);
45
+ }
46
+ }
47
+
48
+ return filteredKeyObject;
49
+ }
50
+
51
+ return obj;
52
+ }
53
+
54
+ function* convertObjectToStringGen(obj) {
55
+ if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || obj === null) {
56
+ yield JSON.stringify(obj);
57
+ } else if (Array.isArray(obj)) {
58
+ yield '[';
59
+ let isFirst = true;
60
+
61
+ for (let item of obj) {
62
+ if (item === undefined) {
63
+ item = null;
64
+ }
65
+
66
+ yield `${isFirst ? '' : ','}`;
67
+ yield* convertObjectToStringGen(item);
68
+ isFirst = false;
69
+ }
70
+
71
+ yield ']';
72
+ } else {
73
+ yield '{';
74
+ let isFirst = true;
75
+ const entries = Object.entries(obj);
76
+
77
+ for (const [itemKey, itemValue] of entries) {
78
+ if (itemValue !== undefined) {
79
+ yield `${isFirst ? '' : ','}${JSON.stringify(itemKey)}: `;
80
+ yield* convertObjectToStringGen(itemValue);
81
+ isFirst = false;
82
+ }
83
+ }
84
+
85
+ yield '}';
86
+ }
87
+ }
@@ -9,9 +9,9 @@ exports.doBasicRequirementCheck = doBasicRequirementCheck;
9
9
  function doBasicRequirementCheck() {
10
10
  const majorV = Number(process.version.slice(1, 4));
11
11
 
12
- if (majorV >= 12 && majorV <= 18) {
12
+ if (majorV >= 14 && majorV <= 18) {
13
13
  return true;
14
14
  }
15
15
 
16
- throw `your node version not compatible with this cli please update node version to 12 - 18, and your current version is ${process.version}`;
16
+ throw `your node version not compatible with this cli please update node version to 14 - 18, and your current version is ${process.version}`;
17
17
  }
@@ -13,6 +13,15 @@ function corsHandling(app, options) {
13
13
 
14
14
  res.setHeader('Access-Control-Allow-Private-Network', true);
15
15
  res.setHeader('Access-Control-Allow-Credentials', true);
16
+
17
+ if (req.get('Access-Control-Request-Headers')) {
18
+ res.setHeader('Access-Control-Allow-Headers', req.get('Access-Control-Request-Headers'));
19
+ }
20
+
21
+ if (req.get('Access-Control-Request-Method')) {
22
+ res.setHeader('Access-Control-Allow-Methods', req.get('Access-Control-Request-Method'));
23
+ }
24
+
16
25
  next();
17
26
  });
18
27
  app.options('/*', (req, res) => {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.2",
3
+ "version": "0.0.5-exp.3",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@zohodesk/client_build_tool",
9
- "version": "0.0.2",
9
+ "version": "0.0.5-exp.3",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@babel/cli": "7.17.10",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.5",
3
+ "version": "0.0.6-exp.10",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  "cbt": "cli.js"
9
9
  },
10
10
  "scripts": {
11
+ "exp:publish": "npm publish --tag exp",
11
12
  "start": "rm -r lib && npm run build -- -w",
12
13
  "prepare": "npm run build",
13
14
  "build": "babel src --out-dir lib --copy-files --config-file=./.babelrc",