@zohodesk/client_build_tool 0.0.11-exp.34.0 → 0.0.11-exp.35.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
|
@@ -22,18 +22,21 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
22
22
|
groupAssetUrls
|
|
23
23
|
} = this.options;
|
|
24
24
|
const chunkIdToGroup = chunkIdToGroupMapping || {};
|
|
25
|
+
console.log("kiren");
|
|
25
26
|
return `
|
|
26
27
|
(function() {
|
|
27
|
-
var loadedGroups =
|
|
28
|
+
var loadedGroups = Object.create(null);
|
|
29
|
+
var loadingGroups = Object.create(null);
|
|
28
30
|
var chunkIdToGroup = ${JSON.stringify(chunkIdToGroup)};
|
|
29
31
|
var groupAssetUrls = ${JSON.stringify(groupAssetUrls || {})};
|
|
32
|
+
var groupConfig = ${JSON.stringify(customGroups || {})};
|
|
30
33
|
|
|
31
34
|
function normalizeRelativePath(path) {
|
|
32
35
|
return path && path.charAt(0) === '/' ? path.slice(1) : path;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
function isFullUrl(value) {
|
|
36
|
-
return typeof value === 'string' && (value.indexOf('://') !== -1 || value.
|
|
39
|
+
return typeof value === 'string' && (value.indexOf('://') !== -1 || value.indexOf('//') === 0);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
function buildI18nUrl(relativePath) {
|
|
@@ -41,7 +44,13 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
41
44
|
return relativePath;
|
|
42
45
|
}
|
|
43
46
|
var normalizedPath = normalizeRelativePath(relativePath);
|
|
44
|
-
|
|
47
|
+
var publicPath = ${_webpack.RuntimeGlobals.publicPath};
|
|
48
|
+
|
|
49
|
+
if (typeof publicPath === 'undefined' || publicPath === 'undefined') {
|
|
50
|
+
publicPath = '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return publicPath + normalizedPath;
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
function loadI18nGroup(groupName) {
|
|
@@ -49,15 +58,22 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
49
58
|
return Promise.resolve();
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
if (loadingGroups[groupName]) {
|
|
62
|
+
return loadingGroups[groupName];
|
|
63
|
+
}
|
|
55
64
|
|
|
65
|
+
var config = groupConfig[groupName];
|
|
56
66
|
if (!config) {
|
|
57
67
|
return Promise.resolve();
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
|
|
70
|
+
if (typeof document === 'undefined' || !document.head || !document.createElement) {
|
|
71
|
+
return Promise.resolve();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var locale = ${localeVarName} || 'en_US';
|
|
75
|
+
|
|
76
|
+
var loadPromise = new Promise(function(resolve, reject) {
|
|
61
77
|
var relativePath;
|
|
62
78
|
|
|
63
79
|
if (groupAssetUrls[groupName] && groupAssetUrls[groupName][locale]) {
|
|
@@ -67,14 +83,24 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
var i18nUrl = buildI18nUrl(relativePath);
|
|
70
|
-
|
|
71
86
|
var script = document.createElement('script');
|
|
87
|
+
|
|
72
88
|
script.src = i18nUrl;
|
|
73
89
|
script.async = true;
|
|
90
|
+
|
|
74
91
|
if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.nc) {
|
|
75
92
|
script.setAttribute('nonce', __webpack_require__.nc);
|
|
76
93
|
}
|
|
77
94
|
|
|
95
|
+
var target = document.head || document.getElementsByTagName('head')[0] || document.documentElement;
|
|
96
|
+
|
|
97
|
+
if (!target) {
|
|
98
|
+
loadedGroups[groupName] = true;
|
|
99
|
+
delete loadingGroups[groupName];
|
|
100
|
+
resolve();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
78
104
|
var cleanup = function() {
|
|
79
105
|
if (script.parentNode) {
|
|
80
106
|
script.parentNode.removeChild(script);
|
|
@@ -83,20 +109,27 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
83
109
|
|
|
84
110
|
script.onload = function() {
|
|
85
111
|
loadedGroups[groupName] = true;
|
|
112
|
+
delete loadingGroups[groupName];
|
|
86
113
|
cleanup();
|
|
87
114
|
resolve();
|
|
88
115
|
};
|
|
89
116
|
|
|
90
117
|
script.onerror = function(err) {
|
|
118
|
+
delete loadingGroups[groupName];
|
|
91
119
|
cleanup();
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
var errorMessage = 'Failed to load i18n group: ' + groupName + ' from ' + i18nUrl;
|
|
121
|
+
if (err && err.message) {
|
|
122
|
+
errorMessage += ' (' + err.message + ')';
|
|
94
123
|
}
|
|
95
|
-
reject(new Error(
|
|
124
|
+
reject(new Error(errorMessage));
|
|
96
125
|
};
|
|
97
126
|
|
|
98
|
-
|
|
127
|
+
target.appendChild(script);
|
|
99
128
|
});
|
|
129
|
+
|
|
130
|
+
loadingGroups[groupName] = loadPromise;
|
|
131
|
+
|
|
132
|
+
return loadPromise;
|
|
100
133
|
}
|
|
101
134
|
|
|
102
135
|
function findGroupByChunkId(chunkId) {
|
|
@@ -113,13 +146,9 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
113
146
|
promises.push(loadI18nGroup(groupName));
|
|
114
147
|
}
|
|
115
148
|
};
|
|
116
|
-
function detectGroupFromUrl() {
|
|
117
|
-
if (typeof window === 'undefined') {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
149
|
|
|
150
|
+
function detectGroupFromUrl() {
|
|
121
151
|
var url = window.location.href;
|
|
122
|
-
var groupConfig = ${JSON.stringify(customGroups)};
|
|
123
152
|
|
|
124
153
|
for (var groupName in groupConfig) {
|
|
125
154
|
if (!Object.prototype.hasOwnProperty.call(groupConfig, groupName)) {
|
|
@@ -127,12 +156,12 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
127
156
|
}
|
|
128
157
|
|
|
129
158
|
var config = groupConfig[groupName];
|
|
130
|
-
if (config
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
159
|
+
if (!config.urlPatterns || !Array.isArray(config.urlPatterns)) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
for (var i = 0; i < config.urlPatterns.length; i++) {
|
|
163
|
+
if (url.indexOf(config.urlPatterns[i]) !== -1) {
|
|
164
|
+
return groupName;
|
|
136
165
|
}
|
|
137
166
|
}
|
|
138
167
|
}
|
|
@@ -144,20 +173,49 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
144
173
|
try {
|
|
145
174
|
var detectedGroup = detectGroupFromUrl();
|
|
146
175
|
if (detectedGroup && !loadedGroups[detectedGroup]) {
|
|
147
|
-
loadI18nGroup(detectedGroup).catch(function(
|
|
148
|
-
if (typeof console !== 'undefined' && console.warn) {
|
|
149
|
-
console.warn('Failed to preload i18n group', detectedGroup, err);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
176
|
+
loadI18nGroup(detectedGroup).catch(function() {});
|
|
152
177
|
}
|
|
153
|
-
} catch (err) {
|
|
154
|
-
|
|
155
|
-
|
|
178
|
+
} catch (err) {}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function safeCheckAndLoadGroupFromUrl() {
|
|
182
|
+
var publicPath = ${_webpack.RuntimeGlobals.publicPath};
|
|
183
|
+
if (typeof publicPath === 'undefined' || publicPath === 'undefined') {
|
|
184
|
+
if (typeof document !== 'undefined' && document.readyState === 'loading') {
|
|
185
|
+
document.addEventListener('DOMContentLoaded', checkAndLoadGroupFromUrl);
|
|
186
|
+
} else {
|
|
187
|
+
setTimeout(checkAndLoadGroupFromUrl, 0);
|
|
156
188
|
}
|
|
189
|
+
} else {
|
|
190
|
+
checkAndLoadGroupFromUrl();
|
|
157
191
|
}
|
|
158
192
|
}
|
|
159
193
|
|
|
160
|
-
|
|
194
|
+
safeCheckAndLoadGroupFromUrl();
|
|
195
|
+
|
|
196
|
+
if (typeof window !== 'undefined' && window.history) {
|
|
197
|
+
var originalPushState = window.history.pushState;
|
|
198
|
+
var originalReplaceState = window.history.replaceState;
|
|
199
|
+
|
|
200
|
+
if (originalPushState) {
|
|
201
|
+
window.history.pushState = function() {
|
|
202
|
+
var result = originalPushState.apply(this, arguments);
|
|
203
|
+
checkAndLoadGroupFromUrl();
|
|
204
|
+
return result;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (originalReplaceState) {
|
|
209
|
+
window.history.replaceState = function() {
|
|
210
|
+
var result = originalReplaceState.apply(this, arguments);
|
|
211
|
+
checkAndLoadGroupFromUrl();
|
|
212
|
+
return result;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
window.addEventListener('popstate', checkAndLoadGroupFromUrl);
|
|
217
|
+
window.addEventListener('hashchange', checkAndLoadGroupFromUrl);
|
|
218
|
+
}
|
|
161
219
|
})();
|
|
162
220
|
`;
|
|
163
221
|
}
|