@zohodesk/client_build_tool 0.0.6-exp.1 → 0.0.6-exp.11

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,6 +1,8 @@
1
1
  # Changelog and Release Notes
2
2
 
3
- **Featue:-**
3
+
4
+
5
+ **Feature:-**
4
6
  - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
5
7
  - to use externals, we use the following pattern in `app > externals` :
6
8
 
package/README.md CHANGED
@@ -84,7 +84,9 @@ 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
- **Featue:-**
87
+
88
+
89
+ **Feature:-**
88
90
  - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
89
91
  - to use externals, we use the following pattern in `app > externals` :
90
92
 
@@ -7,14 +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
11
 
12
- var _modeUtils = require("../common/modeUtils");
12
+ var _nameTemplates = require("../../common/nameTemplates");
13
+
14
+ var _modeUtils = require("../../common/modeUtils");
15
+
16
+ var _webpackCustomJsUrlLoader = _interopRequireDefault(require("./webpackCustomJsUrlLoader"));
13
17
 
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
19
 
16
20
  // import { RuntimeGlobals, RuntimeModule } from 'webpack';
21
+ // eslint-disable-next-line import/extensions
17
22
  // import { Template } from 'webpack';
23
+ // eslint-disable-next-line import/extensions
18
24
  const pluginName = 'CdnChangePlugin'; // const MODULE_TYPE = 'css/mini-extract';
19
25
  // class CdnChangeRuntimePlugin extends RuntimeModule {
20
26
  // constructor(compiler, { variableName }) {
@@ -80,6 +86,12 @@ class CdnChangePlugin {
80
86
  };
81
87
  cb && cb(null, data);
82
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, this.variableName));
93
+ return true;
94
+ });
83
95
  });
84
96
  }
85
97
 
@@ -0,0 +1,266 @@
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 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, variableName) {
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
+ this.variableName = variableName;
31
+ }
32
+
33
+ generate() {
34
+ const {
35
+ global,
36
+ chunk,
37
+ chunkGraph,
38
+ contentType,
39
+ getFilenameForChunk,
40
+ allChunks,
41
+ compilation
42
+ } = this;
43
+ const {
44
+ runtimeTemplate
45
+ } = compilation;
46
+ /** @type {Map<string | FilenameFunction, Set<Chunk>>} */
47
+
48
+ const chunkFilenames = new Map();
49
+ let maxChunks = 0;
50
+ /** @type {string} */
51
+
52
+ let dynamicFilename;
53
+ /**
54
+ * @param {Chunk} c the chunk
55
+ * @returns {void}
56
+ */
57
+
58
+ const addChunk = c => {
59
+ const chunkFilename = getFilenameForChunk(c);
60
+
61
+ if (chunkFilename) {
62
+ let set = chunkFilenames.get(chunkFilename);
63
+
64
+ if (set === undefined) {
65
+ chunkFilenames.set(chunkFilename, set = new Set());
66
+ }
67
+
68
+ set.add(c);
69
+
70
+ if (typeof chunkFilename === 'string') {
71
+ if (set.size < maxChunks) return;
72
+
73
+ if (set.size === maxChunks) {
74
+ if (chunkFilename.length < dynamicFilename.length) return;
75
+
76
+ if (chunkFilename.length === dynamicFilename.length) {
77
+ if (chunkFilename < dynamicFilename) return;
78
+ }
79
+ }
80
+
81
+ maxChunks = set.size;
82
+ dynamicFilename = chunkFilename;
83
+ }
84
+ }
85
+ };
86
+ /** @type {string[]} */
87
+
88
+
89
+ const includedChunksMessages = [];
90
+
91
+ if (allChunks) {
92
+ includedChunksMessages.push('all chunks');
93
+
94
+ for (const c of chunk.getAllReferencedChunks()) {
95
+ addChunk(c);
96
+ }
97
+ } else {
98
+ includedChunksMessages.push('async chunks');
99
+
100
+ for (const c of chunk.getAllAsyncChunks()) {
101
+ addChunk(c);
102
+ }
103
+
104
+ const includeEntries = chunkGraph.getTreeRuntimeRequirements(chunk).has(_webpack.RuntimeGlobals.ensureChunkIncludeEntries);
105
+
106
+ if (includeEntries) {
107
+ includedChunksMessages.push('sibling chunks for the entrypoint');
108
+
109
+ for (const c of chunkGraph.getChunkEntryDependentChunksIterable(chunk)) {
110
+ addChunk(c);
111
+ }
112
+ }
113
+ }
114
+
115
+ for (const entrypoint of chunk.getAllReferencedAsyncEntrypoints()) {
116
+ addChunk(entrypoint.chunks[entrypoint.chunks.length - 1]);
117
+ }
118
+ /** @type {Map<string, Set<string | number>>} */
119
+
120
+
121
+ const staticUrls = new Map();
122
+ /** @type {Set<Chunk>} */
123
+
124
+ const dynamicUrlChunks = new Set();
125
+ /**
126
+ * @param {Chunk} c the chunk
127
+ * @param {string | FilenameFunction} chunkFilename the filename template for the chunk
128
+ * @returns {void}
129
+ */
130
+
131
+ const addStaticUrl = (c, chunkFilename) => {
132
+ /**
133
+ * @param {string | number} value a value
134
+ * @returns {string} string to put in quotes
135
+ */
136
+ const unquotedStringify = value => {
137
+ const str = `${value}`;
138
+
139
+ if (str.length >= 5 && str === `${c.id}`) {
140
+ // This is shorter and generates the same result
141
+ return '" + chunkId + "';
142
+ }
143
+
144
+ const s = JSON.stringify(str);
145
+ return s.slice(1, s.length - 1);
146
+ };
147
+
148
+ const unquotedStringifyWithLength = value => length => unquotedStringify(`${value}`.slice(0, length));
149
+
150
+ const chunkFilenameValue = typeof chunkFilename === 'function' ? JSON.stringify(chunkFilename({
151
+ chunk: c,
152
+ contentHashType: contentType
153
+ })) : JSON.stringify(chunkFilename);
154
+ const staticChunkFilename = compilation.getPath(chunkFilenameValue, {
155
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
156
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
157
+ chunk: {
158
+ id: unquotedStringify(c.id),
159
+ hash: unquotedStringify(c.renderedHash),
160
+ hashWithLength: unquotedStringifyWithLength(c.renderedHash),
161
+ name: unquotedStringify(c.name || c.id),
162
+ contentHash: {
163
+ [contentType]: unquotedStringify(c.contentHash[contentType])
164
+ },
165
+ contentHashWithLength: {
166
+ [contentType]: unquotedStringifyWithLength(c.contentHash[contentType])
167
+ }
168
+ },
169
+ contentHashType: contentType
170
+ });
171
+ let set = staticUrls.get(staticChunkFilename);
172
+
173
+ if (set === undefined) {
174
+ staticUrls.set(staticChunkFilename, set = new Set());
175
+ }
176
+
177
+ set.add(c.id);
178
+ };
179
+
180
+ for (const [filename, chunks] of chunkFilenames) {
181
+ if (filename !== dynamicFilename) {
182
+ for (const c of chunks) addStaticUrl(c, filename);
183
+ } else {
184
+ for (const c of chunks) dynamicUrlChunks.add(c);
185
+ }
186
+ }
187
+ /**
188
+ * @param {function(Chunk): string | number} fn function from chunk to value
189
+ * @returns {string} code with static mapping of results of fn
190
+ */
191
+
192
+
193
+ const createMap = fn => {
194
+ const obj = {};
195
+ let useId = false;
196
+ let lastKey;
197
+ let entries = 0; // eslint-disable-next-line no-restricted-syntax
198
+
199
+ for (const c of dynamicUrlChunks) {
200
+ const value = fn(c);
201
+
202
+ if (value === c.id) {
203
+ useId = true;
204
+ } else {
205
+ obj[c.id] = value;
206
+ lastKey = c.id;
207
+ entries++;
208
+ }
209
+ }
210
+
211
+ if (entries === 0) return 'chunkId';
212
+
213
+ if (entries === 1) {
214
+ return useId ? `(chunkId === ${JSON.stringify(lastKey)} ? ${JSON.stringify(obj[lastKey])} : chunkId)` : JSON.stringify(obj[lastKey]);
215
+ }
216
+
217
+ return useId ? `(${JSON.stringify(obj)}[chunkId] || chunkId)` : `${JSON.stringify(obj)}[chunkId]`;
218
+ };
219
+ /**
220
+ * @param {function(Chunk): string | number} fn function from chunk to value
221
+ * @returns {string} code with static mapping of results of fn for including in quoted string
222
+ */
223
+
224
+
225
+ const mapExpr = fn => {
226
+ return `" + ${createMap(fn)} + "`;
227
+ };
228
+ /**
229
+ * @param {function(Chunk): string | number} fn function from chunk to value
230
+ * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
231
+ */
232
+
233
+
234
+ const mapExprWithLength = fn => length => {
235
+ return `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
236
+ };
237
+
238
+ const url = dynamicFilename && compilation.getPath(JSON.stringify(dynamicFilename), {
239
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
240
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
241
+ chunk: {
242
+ id: `" + chunkId + "`,
243
+ hash: mapExpr(c => c.renderedHash),
244
+ hashWithLength: mapExprWithLength(c => c.renderedHash),
245
+ name: mapExpr(c => c.name || c.id),
246
+ contentHash: {
247
+ [contentType]: mapExpr(c => c.contentHash[contentType])
248
+ },
249
+ contentHashWithLength: {
250
+ [contentType]: mapExprWithLength(c => c.contentHash[contentType])
251
+ }
252
+ },
253
+ contentHashType: contentType
254
+ });
255
+ const cdn = `__CSS_CDN__`;
256
+ 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?"...":"..."`
257
+ _webpack.Template.asString(Array.from(staticUrls, ([url, ids]) => {
258
+ const condition = ids.size === 1 ? `chunkId === ${JSON.stringify(first(ids))}` : `{${Array.from(ids, id => `${JSON.stringify(id)}:1`).join(',')}}[chunkId]`;
259
+ return `if (${condition}) return window.${cdn}+${url};`;
260
+ })), '// return url for filenames based on template', `return window.${cdn}+${url};`] : ['// return url for filenames based on template', `return window.${cdn}+${url};`])};`]);
261
+ }
262
+
263
+ }
264
+
265
+ var _default = CustomizedGetChunkFilenameRuntimeModule;
266
+ exports.default = _default;
@@ -95,7 +95,8 @@ class I18nRuntimeDealerPlugin {
95
95
  const {
96
96
  chunkFilename,
97
97
  locales,
98
- localeVarName
98
+ localeVarName,
99
+ createSeparateSMap
99
100
  } = this.options;
100
101
  const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(chunkFilename);
101
102
 
@@ -161,6 +162,11 @@ class I18nRuntimeDealerPlugin {
161
162
  const replaceText = chunkFilenameUrlGenerator(i18nChunks, locale);
162
163
  const replacedStr = runtimeFileSourceStr.replace(_constants.I18N_CHUNK_NAME_GENERATION_SEGMENT, replaceText);
163
164
  compilation.emitAsset(newRuntimeName, new RawSource(replacedStr));
165
+
166
+ if (createSeparateSMap) {
167
+ const updatedPath = newRuntimeName.replace('smap/', '');
168
+ compilation.emitAsset(updatedPath, new RawSource(replacedStr));
169
+ }
164
170
  } // eslint-disable-next-line no-restricted-syntax
165
171
 
166
172
 
@@ -27,6 +27,7 @@ function optionsHandler(options) {
27
27
  });
28
28
  return {
29
29
  filename: options.filename || _constants.DEFAULT_FILENAME,
30
+ createSeparateSMap: options.sourceMapOptions,
30
31
  chunkFilename: options.chunkFilename || chunkNameDecider(options.filename),
31
32
  mainChunkName: options.mainChunkName,
32
33
  templateLabel: options.templateLabel,
@@ -13,7 +13,7 @@ function checkSmapFilePattern(assetName) {
13
13
  }
14
14
 
15
15
  function skipRuntimeFiles(assetName) {
16
- return !assetName.includes('runtime') || !assetName.includes('[locale]');
16
+ return !assetName.includes('[locale]');
17
17
  }
18
18
 
19
19
  const pluginName = 'SplitSourceMapPlugin'; // Purpose:
@@ -34,9 +34,14 @@ class SourceMapPlugin {
34
34
  stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
35
35
  }, assets => {
36
36
  Object.keys(assets).forEach(assetName => {
37
+ if (assetName.includes('runtime')) {
38
+ console.log(assetName);
39
+ }
40
+
37
41
  const assetCode = assets[assetName].source();
38
42
 
39
- if (checkSmapFilePattern(assetName) && skipRuntimeFiles(assetName)) {
43
+ if (checkSmapFilePattern(assetName) // skipRuntimeFiles(assetName)
44
+ ) {
40
45
  compilation.renameAsset(assetName, `smap/${assetName}`);
41
46
 
42
47
  if (!/\.map$/.test(assetName)) {
@@ -15,7 +15,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
15
 
16
16
  function configI18nSplitPlugin(options) {
17
17
  const {
18
- i18nChunkSplit
18
+ i18nChunkSplit,
19
+ createSeparateSMap
19
20
  } = options;
20
21
 
21
22
  if (!i18nChunkSplit.chunkSplitEnable) {
@@ -36,6 +37,7 @@ function configI18nSplitPlugin(options) {
36
37
  publicPath: i18nPublicPath,
37
38
  i18nManifestFileName: (0, _nameTemplates.nameTemplates)('i18nmanifest', options),
38
39
  // template: (object, locale) => `window.loadI18n(${JSON.stringify(object)}, ${JSON.stringify(locale)})`,
39
- propertiesFolder: i18nChunkSplit.propertiesFolder
40
+ propertiesFolder: i18nChunkSplit.propertiesFolder,
41
+ sourceMapOptions: createSeparateSMap
40
42
  });
41
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.6-exp.1",
3
+ "version": "0.0.6-exp.11",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {