@zohodesk/client_build_tool 0.0.5 → 0.0.6

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,19 @@
1
1
  # Changelog and Release Notes
2
2
 
3
+ ## v0.0.6 (4-09-2023)
4
+
5
+ **Feature:-**
6
+ - 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`.
7
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
8
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
9
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
10
+ - added support for glob pattern for custom chunks split logic.
11
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
12
+
13
+ **Change:-**
14
+ - i18n name not generated issue fix.
15
+ - public path not correctly set issue fix.
16
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
3
17
  ## v0.0.5 (6-08-2023)
4
18
 
5
19
  **Changes:--**
package/README.md CHANGED
@@ -84,6 +84,20 @@ 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
+ ## v0.0.6 (4-09-2023)
88
+
89
+ **Feature:-**
90
+ - 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`.
91
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
92
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
93
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
94
+ - added support for glob pattern for custom chunks split logic.
95
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
96
+
97
+ **Change:-**
98
+ - i18n name not generated issue fix.
99
+ - public path not correctly set issue fix.
100
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
87
101
  ## v0.0.5 (6-08-2023)
88
102
 
89
103
  **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: {
@@ -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;
@@ -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,7 @@ 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)) {
27
40
  compilation.renameAsset(assetName, `smap/${assetName}`);
28
41
 
29
42
  if (!/\.map$/.test(assetName)) {
@@ -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",
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",