@zohodesk/client_build_tool 0.0.6-exp.1 → 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.
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));
93
+ return true;
94
+ });
83
95
  });
84
96
  }
85
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;
@@ -36,7 +36,8 @@ class SourceMapPlugin {
36
36
  Object.keys(assets).forEach(assetName => {
37
37
  const assetCode = assets[assetName].source();
38
38
 
39
- if (checkSmapFilePattern(assetName) && skipRuntimeFiles(assetName)) {
39
+ if (checkSmapFilePattern(assetName) // skipRuntimeFiles(assetName)
40
+ ) {
40
41
  compilation.renameAsset(assetName, `smap/${assetName}`);
41
42
 
42
43
  if (!/\.map$/.test(assetName)) {
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.10",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {