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