@zohodesk/client_build_tool 0.0.11-exp.31.0 → 0.0.11-exp.32.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 +104 -45
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +2 -3
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +9 -5
- package/package.json +1 -1
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
CHANGED
|
@@ -20,63 +20,103 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
20
20
|
chunkIdToGroupMapping,
|
|
21
21
|
localeVarName,
|
|
22
22
|
groupAssetUrls,
|
|
23
|
-
publicPathPrefix,
|
|
24
23
|
publicPathRuntimeExpression
|
|
25
24
|
} = this.options;
|
|
26
25
|
const chunkIdToGroup = chunkIdToGroupMapping || {};
|
|
26
|
+
const runtimePublicPathResolver = publicPathRuntimeExpression ? `function(){ try { return ${publicPathRuntimeExpression}; } catch (err) { return undefined; } }` : 'function(){ return undefined; }';
|
|
27
27
|
return `
|
|
28
28
|
// I18n Group Loading Runtime
|
|
29
29
|
(function() {
|
|
30
30
|
var loadedGroups = {};
|
|
31
31
|
var chunkIdToGroup = ${JSON.stringify(chunkIdToGroup)};
|
|
32
32
|
var groupAssetUrls = ${JSON.stringify(groupAssetUrls || {})};
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var runtimePublicPathPrefixResolver = ${publicPathRuntimeExpression ? `function(){ try { return ${publicPathRuntimeExpression}; } catch (err) { return undefined; } }` : 'function(){ return undefined; }'};
|
|
36
|
-
var runtimePublicPathPrefix = runtimePublicPathPrefixResolver();
|
|
37
|
-
if (runtimePublicPathPrefix === undefined || runtimePublicPathPrefix === null || runtimePublicPathPrefix === '') {
|
|
38
|
-
runtimePublicPathPrefix = ${JSON.stringify(publicPathPrefix || '')};
|
|
39
|
-
}
|
|
40
|
-
if (typeof runtimePublicPathPrefix !== 'string') {
|
|
41
|
-
runtimePublicPathPrefix = runtimePublicPathPrefix != null ? String(runtimePublicPathPrefix) : '';
|
|
42
|
-
}
|
|
33
|
+
var runtimePublicPathResolver = ${runtimePublicPathResolver};
|
|
34
|
+
var cachedDocumentBase;
|
|
43
35
|
|
|
44
36
|
function ensureTrailingSlash(path) {
|
|
45
37
|
if (!path) return '';
|
|
46
38
|
return path.charAt(path.length - 1) === '/' ? path : path + '/';
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
|
|
41
|
+
function normalizeRelativePath(path) {
|
|
42
|
+
if (!path) return '';
|
|
43
|
+
return path.charAt(0) === '/' ? path.slice(1) : path;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isFullUrl(value) {
|
|
47
|
+
if (typeof value !== 'string') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return value.indexOf('://') !== -1 || value.startsWith('//');
|
|
51
|
+
}
|
|
50
52
|
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
53
|
+
function getDocumentBase() {
|
|
54
|
+
if (cachedDocumentBase !== undefined) {
|
|
55
|
+
return cachedDocumentBase;
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (typeof document === 'undefined') {
|
|
59
|
+
cachedDocumentBase = '';
|
|
60
|
+
return cachedDocumentBase;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var script = document.currentScript;
|
|
64
|
+
if (!script) {
|
|
65
|
+
var scripts = document.getElementsByTagName('script');
|
|
66
|
+
if (scripts.length) {
|
|
67
|
+
script = scripts[scripts.length - 1];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (script && script.src) {
|
|
72
|
+
var scriptUrl = script.src.replace(/[?#].*$/, '');
|
|
73
|
+
var lastSlash = scriptUrl.lastIndexOf('/');
|
|
74
|
+
var withoutFile = lastSlash >= 0 ? scriptUrl.slice(0, lastSlash + 1) : '';
|
|
75
|
+
var normalized = withoutFile.endsWith('js/')
|
|
76
|
+
? withoutFile.slice(0, withoutFile.length - 3)
|
|
77
|
+
: withoutFile;
|
|
78
|
+
cachedDocumentBase = ensureTrailingSlash(normalized);
|
|
79
|
+
} else {
|
|
80
|
+
cachedDocumentBase = '';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return cachedDocumentBase;
|
|
59
84
|
}
|
|
60
85
|
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
86
|
+
function resolveRuntimePublicPath() {
|
|
87
|
+
var dynamicBase = runtimePublicPathResolver();
|
|
88
|
+
if (dynamicBase != null && dynamicBase !== '') {
|
|
89
|
+
return ensureTrailingSlash(String(dynamicBase));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var webpackPublicPath = ${_webpack.RuntimeGlobals.publicPath};
|
|
93
|
+
if (typeof webpackPublicPath === 'string' && webpackPublicPath) {
|
|
94
|
+
return ensureTrailingSlash(webpackPublicPath);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var documentBase = getDocumentBase();
|
|
98
|
+
if (documentBase) {
|
|
99
|
+
return documentBase;
|
|
64
100
|
}
|
|
65
101
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function buildI18nUrl(relativePath) {
|
|
106
|
+
if (!relativePath) {
|
|
107
|
+
return resolveRuntimePublicPath();
|
|
69
108
|
}
|
|
70
109
|
|
|
71
|
-
if (
|
|
72
|
-
return
|
|
110
|
+
if (isFullUrl(relativePath)) {
|
|
111
|
+
return relativePath;
|
|
73
112
|
}
|
|
74
113
|
|
|
75
|
-
var
|
|
114
|
+
var normalizedPath = normalizeRelativePath(relativePath);
|
|
115
|
+
var base = resolveRuntimePublicPath();
|
|
76
116
|
return base + normalizedPath;
|
|
77
117
|
}
|
|
78
118
|
|
|
79
|
-
function loadI18nGroup(groupName
|
|
119
|
+
function loadI18nGroup(groupName) {
|
|
80
120
|
if (loadedGroups[groupName]) {
|
|
81
121
|
return Promise.resolve();
|
|
82
122
|
}
|
|
@@ -89,8 +129,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
89
129
|
return Promise.resolve();
|
|
90
130
|
}
|
|
91
131
|
|
|
92
|
-
|
|
93
|
-
return new Promise(function(resolve, reject) {
|
|
132
|
+
return new Promise(function(resolve) {
|
|
94
133
|
var relativePath;
|
|
95
134
|
|
|
96
135
|
if (groupAssetUrls[groupName] && groupAssetUrls[groupName][locale]) {
|
|
@@ -117,9 +156,12 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
117
156
|
resolve();
|
|
118
157
|
};
|
|
119
158
|
|
|
120
|
-
script.onerror = function() {
|
|
159
|
+
script.onerror = function(err) {
|
|
121
160
|
cleanup();
|
|
122
161
|
loadedGroups[groupName] = true;
|
|
162
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
163
|
+
console.warn('Failed to load i18n group', groupName, 'from', i18nUrl, err);
|
|
164
|
+
}
|
|
123
165
|
resolve();
|
|
124
166
|
};
|
|
125
167
|
|
|
@@ -140,32 +182,46 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
140
182
|
var groupName = findGroupByChunkId(chunkId);
|
|
141
183
|
|
|
142
184
|
if (groupName && !loadedGroups[groupName]) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return i18nPromise.then(function() {
|
|
185
|
+
return loadI18nGroup(groupName).then(function() {
|
|
146
186
|
return originalEnsureChunk.apply(self, args);
|
|
147
|
-
}).catch(function(
|
|
187
|
+
}).catch(function() {
|
|
148
188
|
return originalEnsureChunk.apply(self, args);
|
|
149
189
|
});
|
|
150
|
-
} else {
|
|
151
|
-
return originalEnsureChunk.apply(this, arguments);
|
|
152
190
|
}
|
|
191
|
+
|
|
192
|
+
return originalEnsureChunk.apply(this, args);
|
|
153
193
|
};
|
|
154
194
|
}
|
|
155
195
|
|
|
156
|
-
|
|
196
|
+
if (!${_webpack.RuntimeGlobals.ensureChunkHandlers}) {
|
|
197
|
+
${_webpack.RuntimeGlobals.ensureChunkHandlers} = {};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
${_webpack.RuntimeGlobals.ensureChunkHandlers}.i18nGroup = function(chunkId, promises) {
|
|
201
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
202
|
+
if (groupName && !loadedGroups[groupName]) {
|
|
203
|
+
promises.push(loadI18nGroup(groupName));
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
157
207
|
function detectGroupFromUrl() {
|
|
158
|
-
if (typeof window === 'undefined')
|
|
208
|
+
if (typeof window === 'undefined') {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
159
211
|
|
|
160
212
|
var url = window.location.href;
|
|
161
213
|
var groupConfig = ${JSON.stringify(customGroups)};
|
|
162
214
|
|
|
163
215
|
for (var groupName in groupConfig) {
|
|
216
|
+
if (!Object.prototype.hasOwnProperty.call(groupConfig, groupName)) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
164
220
|
var config = groupConfig[groupName];
|
|
165
|
-
if (config
|
|
221
|
+
if (config && Array.isArray(config.urlPatterns)) {
|
|
166
222
|
for (var i = 0; i < config.urlPatterns.length; i++) {
|
|
167
223
|
var pattern = config.urlPatterns[i];
|
|
168
|
-
if (url.
|
|
224
|
+
if (pattern && url.indexOf(pattern) !== -1) {
|
|
169
225
|
return groupName;
|
|
170
226
|
}
|
|
171
227
|
}
|
|
@@ -179,16 +235,19 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
179
235
|
try {
|
|
180
236
|
var detectedGroup = detectGroupFromUrl();
|
|
181
237
|
if (detectedGroup && !loadedGroups[detectedGroup]) {
|
|
182
|
-
loadI18nGroup(detectedGroup
|
|
183
|
-
|
|
238
|
+
loadI18nGroup(detectedGroup).catch(function(err) {
|
|
239
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
240
|
+
console.warn('Failed to preload i18n group', detectedGroup, err);
|
|
241
|
+
}
|
|
184
242
|
});
|
|
185
243
|
}
|
|
186
244
|
} catch (err) {
|
|
187
|
-
|
|
245
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
246
|
+
console.warn('Error during i18n group detection', err);
|
|
247
|
+
}
|
|
188
248
|
}
|
|
189
249
|
}
|
|
190
250
|
|
|
191
|
-
// Check current URL for immediate loading
|
|
192
251
|
checkAndLoadGroupFromUrl();
|
|
193
252
|
})();
|
|
194
253
|
`;
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js
CHANGED
|
@@ -15,7 +15,7 @@ var _propertiesUtils = require("../I18nSplitPlugin/utils/propertiesUtils");
|
|
|
15
15
|
|
|
16
16
|
var _I18nGroupRuntimeModule = require("./I18nGroupRuntimeModule");
|
|
17
17
|
|
|
18
|
-
var _i18nDataLoader = require("./utils/i18nDataLoader
|
|
18
|
+
var _i18nDataLoader = require("./utils/i18nDataLoader");
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
@@ -54,7 +54,6 @@ class I18nNumericIndexPlugin {
|
|
|
54
54
|
manifestPath: options.manifestPath || null,
|
|
55
55
|
emitFiles: options.emitFiles !== undefined ? options.emitFiles : true,
|
|
56
56
|
chunkToGroupMapping: options.chunkToGroupMapping || {},
|
|
57
|
-
groupPublicPathPrefix: options.groupPublicPathPrefix || '',
|
|
58
57
|
groupPublicPathRuntimeExpression: options.groupPublicPathRuntimeExpression || ''
|
|
59
58
|
};
|
|
60
59
|
this.numericMap = {};
|
|
@@ -81,6 +80,7 @@ class I18nNumericIndexPlugin {
|
|
|
81
80
|
if (chunk.name === 'main' || chunk.hasRuntime()) {
|
|
82
81
|
this.ensureAssetsPrepared(compilation);
|
|
83
82
|
const chunkMapping = this.getChunkIdToGroupMapping(compilation);
|
|
83
|
+
set.add(_webpack.RuntimeGlobals.publicPath);
|
|
84
84
|
compilation.addRuntimeModule(chunk, new _I18nGroupRuntimeModule.I18nGroupRuntimeModule({
|
|
85
85
|
customGroups: this.options.customGroups,
|
|
86
86
|
chunkIdToGroupMapping: chunkMapping,
|
|
@@ -88,7 +88,6 @@ class I18nNumericIndexPlugin {
|
|
|
88
88
|
jsonpFunc: this.options.jsonpFunc,
|
|
89
89
|
groupAssetUrls: this.groupAssetUrls,
|
|
90
90
|
includeContentHash: this.options.includeContentHash,
|
|
91
|
-
publicPathPrefix: this.options.groupPublicPathPrefix,
|
|
92
91
|
publicPathRuntimeExpression: this.options.groupPublicPathRuntimeExpression
|
|
93
92
|
}));
|
|
94
93
|
}
|
|
@@ -11,7 +11,7 @@ var _I18nNumericIndexHtmlInjectorPlugin = require("../custom_plugins/I18nNumeric
|
|
|
11
11
|
|
|
12
12
|
var _readI18nValues = require("../custom_plugins/I18nSplitPlugin/readI18nValues");
|
|
13
13
|
|
|
14
|
-
var _i18nOptionsValidator = require("../common/i18nOptionsValidator
|
|
14
|
+
var _i18nOptionsValidator = require("../common/i18nOptionsValidator");
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
@@ -21,8 +21,12 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const i18nOpts = options.i18nIndexing;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const cdnMapping = options.cdnMapping || {};
|
|
25
|
+
const cdnVariableName = cdnMapping.variableName || 'window.__SMAP_PATH__';
|
|
26
|
+
const {
|
|
27
|
+
groupPublicPathRuntimeExpression: configuredRuntimeExpression
|
|
28
|
+
} = i18nOpts;
|
|
29
|
+
const groupPublicPathRuntimeExpression = configuredRuntimeExpression !== undefined ? configuredRuntimeExpression : cdnVariableName;
|
|
26
30
|
|
|
27
31
|
try {
|
|
28
32
|
const result = (0, _i18nOptionsValidator.validateI18nIndexingOptions)(i18nOpts);
|
|
@@ -83,7 +87,6 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
83
87
|
customGroups: i18nOpts.customGroups || null,
|
|
84
88
|
chunkToGroupMapping: i18nOpts.chunkToGroupMapping || {},
|
|
85
89
|
emitFiles,
|
|
86
|
-
groupPublicPathPrefix,
|
|
87
90
|
groupPublicPathRuntimeExpression
|
|
88
91
|
};
|
|
89
92
|
const htmlInjectorOptions = { ...sharedOptions,
|
|
@@ -91,5 +94,6 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
91
94
|
i18nAssetsPublicPathPrefix: '',
|
|
92
95
|
injectI18nUrlInIndex: injectHtml
|
|
93
96
|
};
|
|
94
|
-
|
|
97
|
+
const plugins = [new _I18nNumericIndexPlugin.default(numericIndexPluginOptions), new _I18nNumericIndexHtmlInjectorPlugin.I18nNumericIndexHtmlInjectorPlugin(htmlInjectorOptions)];
|
|
98
|
+
return plugins;
|
|
95
99
|
}
|