@zohodesk/client_build_tool 0.0.6-exp.16 → 0.0.6-exp.18
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.
|
@@ -15,10 +15,10 @@ var _modeUtils = require("./modeUtils");
|
|
|
15
15
|
const templates = {
|
|
16
16
|
html: ['index.html', 'index.[contenthash].html'],
|
|
17
17
|
js: ['js/[name].js', 'js/[name].[contenthash].js'],
|
|
18
|
-
chunkjs: ['js-
|
|
19
|
-
i18njs: ['i18n-
|
|
20
|
-
i18nchunkjs: ['i18n-
|
|
21
|
-
'i18n-
|
|
18
|
+
chunkjs: ['js-chunk/[name].js', 'js-chunks/[name].[contenthash].js'],
|
|
19
|
+
i18njs: ['i18n-chunk/[locale]/[name].i18n.js', 'i18n-chunk/[locale]/[name].[chunkhash].i18n.js'],
|
|
20
|
+
i18nchunkjs: ['i18n-chunk/[locale]/[name].i18n.js', // 'i18n-chunk/[locale]/[name].[chunkhash].i18n.js'
|
|
21
|
+
'i18n-chunk/[locale]/[name].[contenthash].i18n.js'],
|
|
22
22
|
i18nmanifest: ['i18n-manifest.json', 'i18n-manifest.json'],
|
|
23
23
|
workerjs: ['js/[name].js', 'js/[name].[contenthash].js'],
|
|
24
24
|
css: ['css/[name].css', 'css/[name].[contenthash].css'],
|
|
@@ -77,7 +77,7 @@ class CdnChangePlugin {
|
|
|
77
77
|
data.assets = { ...data.assets,
|
|
78
78
|
css: data.assets.css.map(css => `${this.cssTemplate}${css}`),
|
|
79
79
|
js: data.assets.js.map(js => {
|
|
80
|
-
if ((
|
|
80
|
+
if ((0, _modeUtils.isProductionMode)(mode) && createSeparateSMap && !(0, _nameTemplates.isI18nFile)(js)) {
|
|
81
81
|
if (js.includes('smap')) {
|
|
82
82
|
js = js.replace('smap/js/', `{{--js-smap}}js/`); //eslint-disable-line
|
|
83
83
|
} else {
|
|
@@ -92,6 +92,10 @@ class CdnChangePlugin {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.getChunkScriptFilename).tap(pluginName, (chunk, set) => {
|
|
95
|
+
if (typeof compilation.outputOptions.chunkFilename === 'string' && /\[(full)?hash(:\d+)?\]/.test(compilation.outputOptions.chunkFilename)) {
|
|
96
|
+
set.add(_webpack.RuntimeGlobals.getFullHash);
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
compilation.addRuntimeModule(chunk, // eslint-disable-next-line new-cap
|
|
96
100
|
new _webpackCustomJsUrlLoader.default('javascript', 'javascript', _webpack.RuntimeGlobals.getChunkScriptFilename, chunk => chunk.filenameTemplate || (chunk.canBeInitial() ? compilation.outputOptions.filename : compilation.outputOptions.chunkFilename), false, this.variableName));
|
|
97
101
|
return true;
|
package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js
CHANGED
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// import { RuntimeGlobals, RuntimeModule, Template } from 'webpack';
|
|
9
|
+
const GetChunkFilenameRuntimeModule = require('webpack/lib/runtime/GetChunkFilenameRuntimeModule'); // import GetChunkFilenameRuntimeModule from 'webpack/lib/runtime/GetChunkFilenameRuntimeModule';
|
|
10
|
+
// const first = set => {
|
|
11
|
+
// const entry = set.values().next();
|
|
12
|
+
// return entry.done ? undefined : entry.value;
|
|
13
|
+
// };
|
|
9
14
|
|
|
10
|
-
const first = set => {
|
|
11
|
-
const entry = set.values().next();
|
|
12
|
-
return entry.done ? undefined : entry.value;
|
|
13
|
-
};
|
|
14
15
|
|
|
15
|
-
class CustomizedGetChunkFilenameRuntimeModule extends
|
|
16
|
+
class CustomizedGetChunkFilenameRuntimeModule extends GetChunkFilenameRuntimeModule {
|
|
16
17
|
/**
|
|
17
18
|
* @param {string} contentType the to use the content hash for
|
|
18
19
|
* @param {string} name kind of filename
|
|
@@ -21,7 +22,7 @@ class CustomizedGetChunkFilenameRuntimeModule extends _webpack.RuntimeModule {
|
|
|
21
22
|
* @param {boolean} allChunks when false, only async chunks are included
|
|
22
23
|
*/
|
|
23
24
|
constructor(contentType, name, global, getFilenameForChunk, allChunks, variableName) {
|
|
24
|
-
super(
|
|
25
|
+
super(contentType, name, global, getFilenameForChunk, allChunks);
|
|
25
26
|
this.contentType = contentType;
|
|
26
27
|
this.global = global;
|
|
27
28
|
this.getFilenameForChunk = getFilenameForChunk;
|
|
@@ -31,232 +32,9 @@ class CustomizedGetChunkFilenameRuntimeModule extends _webpack.RuntimeModule {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
generate() {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
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 ${this.variableName}+${url};`;
|
|
259
|
-
})), '// return url for filenames based on template', `return ${this.variableName}+${url};`] : ['// return url for filenames based on template', `return ${this.variableName}+${url};`])};`]);
|
|
35
|
+
const sourceCode = super.generate().toString();
|
|
36
|
+
const replaceCode = sourceCode.replaceAll('"js-chunks/', `${this.variableName} + "js-chunks/`);
|
|
37
|
+
return replaceCode;
|
|
260
38
|
}
|
|
261
39
|
|
|
262
40
|
}
|