@zohodesk/client_build_tool 0.0.11-exp.21.0 → 0.0.11-exp.23.0
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/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
CHANGED
|
@@ -24,8 +24,11 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
24
24
|
} = this.options; // Build chunk-to-group mapping from config
|
|
25
25
|
|
|
26
26
|
const chunkToGroup = {};
|
|
27
|
+
const groupToChunks = {};
|
|
27
28
|
Object.entries(customGroups || {}).forEach(([groupName, config]) => {
|
|
28
|
-
|
|
29
|
+
const chunkNames = config.chunks || [];
|
|
30
|
+
groupToChunks[groupName] = chunkNames;
|
|
31
|
+
chunkNames.forEach(chunkName => {
|
|
29
32
|
chunkToGroup[chunkName] = groupName;
|
|
30
33
|
});
|
|
31
34
|
});
|
|
@@ -33,7 +36,8 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
33
36
|
// I18n Group Loading Runtime
|
|
34
37
|
(function() {
|
|
35
38
|
var loadedGroups = {};
|
|
36
|
-
var
|
|
39
|
+
var chunkNameToGroup = ${JSON.stringify(chunkToGroup)};
|
|
40
|
+
var groupToChunkNames = ${JSON.stringify(groupToChunks)};
|
|
37
41
|
var cachedI18nBase;
|
|
38
42
|
|
|
39
43
|
function ensureTrailingSlash(path) {
|
|
@@ -145,6 +149,43 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
145
149
|
document.head.appendChild(script);
|
|
146
150
|
});
|
|
147
151
|
}
|
|
152
|
+
|
|
153
|
+
function toLower(str) {
|
|
154
|
+
return typeof str === 'string' ? str.toLowerCase() : str;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function findGroupByChunkId(chunkId) {
|
|
158
|
+
var directGroup = chunkNameToGroup[chunkId];
|
|
159
|
+
if (directGroup) {
|
|
160
|
+
return directGroup;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
var stringId = '' + chunkId;
|
|
164
|
+
if (chunkNameToGroup[stringId]) {
|
|
165
|
+
return chunkNameToGroup[stringId];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (typeof __webpack_require__ !== 'undefined' && typeof __webpack_require__.u === 'function') {
|
|
169
|
+
var filename = __webpack_require__.u(chunkId) || '';
|
|
170
|
+
if (filename) {
|
|
171
|
+
var loweredFilename = toLower(filename);
|
|
172
|
+
for (var group in groupToChunkNames) {
|
|
173
|
+
if (!Object.prototype.hasOwnProperty.call(groupToChunkNames, group)) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
var chunkNames = groupToChunkNames[group] || [];
|
|
177
|
+
for (var i = 0; i < chunkNames.length; i++) {
|
|
178
|
+
var candidate = chunkNames[i];
|
|
179
|
+
if (candidate && loweredFilename.indexOf(toLower(candidate)) !== -1) {
|
|
180
|
+
return group;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
148
189
|
|
|
149
190
|
// Store original webpack chunk loading function
|
|
150
191
|
var originalEnsureChunk = __webpack_require__.e;
|
|
@@ -155,7 +196,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
155
196
|
var promise = originalEnsureChunk.apply(this, arguments);
|
|
156
197
|
|
|
157
198
|
// Check if this chunk needs an i18n group
|
|
158
|
-
var groupName =
|
|
199
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
159
200
|
if (groupName && !loadedGroups[groupName]) {
|
|
160
201
|
if (typeof console !== 'undefined' && console.log) {
|
|
161
202
|
console.log('[i18n-group:hook]', chunkId, '→', groupName);
|
|
@@ -175,7 +216,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
175
216
|
// Also check for webpackI18nGroup comments in dynamic imports
|
|
176
217
|
function wrapLoadScript(originalLoadScript) {
|
|
177
218
|
return function(url, done, key, chunkId) {
|
|
178
|
-
var groupName =
|
|
219
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
179
220
|
if (groupName && !loadedGroups[groupName]) {
|
|
180
221
|
var locale = ${localeVarName} || 'en_US';
|
|
181
222
|
var groupConfig = ${JSON.stringify(customGroups)};
|
|
@@ -186,17 +227,10 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
186
227
|
.replace('[locale]', locale);
|
|
187
228
|
var i18nUrl = buildI18nUrl(relativePath);
|
|
188
229
|
|
|
189
|
-
if (typeof console !== 'undefined' && console.log) {
|
|
190
|
-
console.log('[i18n-group:preload]', groupName, i18nUrl);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
230
|
var i18nScript = document.createElement('script');
|
|
194
231
|
i18nScript.src = i18nUrl;
|
|
195
232
|
i18nScript.onload = function() {
|
|
196
233
|
loadedGroups[groupName] = true;
|
|
197
|
-
if (typeof console !== 'undefined' && console.log) {
|
|
198
|
-
console.log('[i18n-group:loaded]', groupName, i18nUrl);
|
|
199
|
-
}
|
|
200
234
|
originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
201
235
|
};
|
|
202
236
|
i18nScript.onerror = function() {
|
|
@@ -215,6 +249,20 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
215
249
|
}
|
|
216
250
|
|
|
217
251
|
function installLoadScriptHook(loadScript) {
|
|
252
|
+
if (typeof loadScript !== 'function') {
|
|
253
|
+
Object.defineProperty(__webpack_require__, 'l', {
|
|
254
|
+
configurable: true,
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function() {
|
|
257
|
+
return loadScript;
|
|
258
|
+
},
|
|
259
|
+
set: function(newLoader) {
|
|
260
|
+
installLoadScriptHook(newLoader);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
218
266
|
Object.defineProperty(__webpack_require__, 'l', {
|
|
219
267
|
configurable: true,
|
|
220
268
|
enumerable: true,
|