@zohodesk/client_build_tool 0.0.11-exp.31.0 → 0.0.11-exp.33.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 +101 -60
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +6 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +130 -94
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +1 -1
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +2 -2
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +9 -5
- package/npm-shrinkwrap.json +2 -2
- 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
|
+
}
|
|
50
45
|
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
46
|
+
function isFullUrl(value) {
|
|
47
|
+
if (typeof value !== 'string') {
|
|
48
|
+
return false;
|
|
54
49
|
}
|
|
50
|
+
return value.indexOf('://') !== -1 || value.startsWith('//');
|
|
51
|
+
}
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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;
|
|
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));
|
|
64
90
|
}
|
|
65
91
|
|
|
66
|
-
var
|
|
67
|
-
if (
|
|
68
|
-
|
|
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;
|
|
100
|
+
}
|
|
101
|
+
|
|
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,7 +129,6 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
89
129
|
return Promise.resolve();
|
|
90
130
|
}
|
|
91
131
|
|
|
92
|
-
|
|
93
132
|
return new Promise(function(resolve, reject) {
|
|
94
133
|
var relativePath;
|
|
95
134
|
|
|
@@ -104,6 +143,9 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
104
143
|
var script = document.createElement('script');
|
|
105
144
|
script.src = i18nUrl;
|
|
106
145
|
script.async = true;
|
|
146
|
+
if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.nc) {
|
|
147
|
+
script.setAttribute('nonce', __webpack_require__.nc);
|
|
148
|
+
}
|
|
107
149
|
|
|
108
150
|
var cleanup = function() {
|
|
109
151
|
if (script.parentNode) {
|
|
@@ -117,10 +159,12 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
117
159
|
resolve();
|
|
118
160
|
};
|
|
119
161
|
|
|
120
|
-
script.onerror = function() {
|
|
162
|
+
script.onerror = function(err) {
|
|
121
163
|
cleanup();
|
|
122
|
-
|
|
123
|
-
|
|
164
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
165
|
+
console.warn('Failed to load i18n group', groupName, 'from', i18nUrl, err);
|
|
166
|
+
}
|
|
167
|
+
reject(new Error('Failed to load i18n group: ' + groupName));
|
|
124
168
|
};
|
|
125
169
|
|
|
126
170
|
document.head.appendChild(script);
|
|
@@ -131,41 +175,35 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
131
175
|
return chunkIdToGroup[chunkId];
|
|
132
176
|
}
|
|
133
177
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (originalEnsureChunk) {
|
|
137
|
-
__webpack_require__.e = function(chunkId) {
|
|
138
|
-
var args = arguments;
|
|
139
|
-
var self = this;
|
|
140
|
-
var groupName = findGroupByChunkId(chunkId);
|
|
141
|
-
|
|
142
|
-
if (groupName && !loadedGroups[groupName]) {
|
|
143
|
-
var i18nPromise = loadI18nGroup(groupName, 'require');
|
|
144
|
-
|
|
145
|
-
return i18nPromise.then(function() {
|
|
146
|
-
return originalEnsureChunk.apply(self, args);
|
|
147
|
-
}).catch(function(err) {
|
|
148
|
-
return originalEnsureChunk.apply(self, args);
|
|
149
|
-
});
|
|
150
|
-
} else {
|
|
151
|
-
return originalEnsureChunk.apply(this, arguments);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
178
|
+
if (!${_webpack.RuntimeGlobals.ensureChunkHandlers}) {
|
|
179
|
+
${_webpack.RuntimeGlobals.ensureChunkHandlers} = {};
|
|
154
180
|
}
|
|
155
181
|
|
|
156
|
-
|
|
182
|
+
${_webpack.RuntimeGlobals.ensureChunkHandlers}.i18nGroup = function(chunkId, promises) {
|
|
183
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
184
|
+
if (groupName && !loadedGroups[groupName]) {
|
|
185
|
+
promises.push(loadI18nGroup(groupName));
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
157
189
|
function detectGroupFromUrl() {
|
|
158
|
-
if (typeof window === 'undefined')
|
|
190
|
+
if (typeof window === 'undefined') {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
159
193
|
|
|
160
194
|
var url = window.location.href;
|
|
161
195
|
var groupConfig = ${JSON.stringify(customGroups)};
|
|
162
196
|
|
|
163
197
|
for (var groupName in groupConfig) {
|
|
198
|
+
if (!Object.prototype.hasOwnProperty.call(groupConfig, groupName)) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
164
202
|
var config = groupConfig[groupName];
|
|
165
|
-
if (config
|
|
203
|
+
if (config && Array.isArray(config.urlPatterns)) {
|
|
166
204
|
for (var i = 0; i < config.urlPatterns.length; i++) {
|
|
167
205
|
var pattern = config.urlPatterns[i];
|
|
168
|
-
if (url.
|
|
206
|
+
if (pattern && url.indexOf(pattern) !== -1) {
|
|
169
207
|
return groupName;
|
|
170
208
|
}
|
|
171
209
|
}
|
|
@@ -179,16 +217,19 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
179
217
|
try {
|
|
180
218
|
var detectedGroup = detectGroupFromUrl();
|
|
181
219
|
if (detectedGroup && !loadedGroups[detectedGroup]) {
|
|
182
|
-
loadI18nGroup(detectedGroup
|
|
183
|
-
|
|
220
|
+
loadI18nGroup(detectedGroup).catch(function(err) {
|
|
221
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
222
|
+
console.warn('Failed to preload i18n group', detectedGroup, err);
|
|
223
|
+
}
|
|
184
224
|
});
|
|
185
225
|
}
|
|
186
226
|
} catch (err) {
|
|
187
|
-
|
|
227
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
228
|
+
console.warn('Error during i18n group detection', err);
|
|
229
|
+
}
|
|
188
230
|
}
|
|
189
231
|
}
|
|
190
232
|
|
|
191
|
-
// Check current URL for immediate loading
|
|
192
233
|
checkAndLoadGroupFromUrl();
|
|
193
234
|
})();
|
|
194
235
|
`;
|
|
@@ -12,7 +12,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
14
|
const pluginName = 'I18nNumericIndexHtmlInjectorPlugin';
|
|
15
|
-
const assetStoreKey = Symbol.for('
|
|
15
|
+
const assetStoreKey = Symbol.for('I18nNumericIndexPluginAssets_v1');
|
|
16
16
|
|
|
17
17
|
class I18nNumericIndexHtmlInjectorPlugin {
|
|
18
18
|
constructor(options) {
|
|
@@ -23,6 +23,7 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
apply(compiler) {
|
|
26
|
+
console.log(`[I18nNumericIndexHtmlInjectorPlugin] Plugin loaded - v1.0.0`);
|
|
26
27
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
27
28
|
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (hookData, cb) => {
|
|
28
29
|
if (!this.options.injectI18nUrlInIndex) {
|
|
@@ -65,8 +66,10 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
if (fullPath.includes('[contenthash]')) {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
69
|
+
const escapedPath = fullPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
70
|
+
const pattern = escapedPath.replace('\\[contenthash\\]', '[a-f0-9]{8,}');
|
|
71
|
+
const regex = new RegExp('^' + pattern + '$');
|
|
72
|
+
const matchingAsset = emittedAssetNames.find(name => regex.test(name));
|
|
70
73
|
|
|
71
74
|
if (matchingAsset) {
|
|
72
75
|
return i18nAssetsPublicPathPrefix + matchingAsset;
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js
CHANGED
|
@@ -15,14 +15,14 @@ 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
|
|
|
22
22
|
const {
|
|
23
23
|
RawSource
|
|
24
24
|
} = _webpack.sources;
|
|
25
|
-
const assetStoreKey = Symbol.for('
|
|
25
|
+
const assetStoreKey = Symbol.for('I18nNumericIndexPluginAssets_v1');
|
|
26
26
|
const pluginName = 'I18nNumericIndexPlugin';
|
|
27
27
|
|
|
28
28
|
function buildChunkMappingFromGroups(customGroups) {
|
|
@@ -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 = {};
|
|
@@ -68,6 +67,7 @@ class I18nNumericIndexPlugin {
|
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
apply(compiler) {
|
|
70
|
+
console.log(`[I18nNumericIndexPlugin] Plugin loaded - v1.0.0`);
|
|
71
71
|
this.detectI18nGroupComments(compiler);
|
|
72
72
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
73
73
|
this.groupAssetUrls = {};
|
|
@@ -81,6 +81,7 @@ class I18nNumericIndexPlugin {
|
|
|
81
81
|
if (chunk.name === 'main' || chunk.hasRuntime()) {
|
|
82
82
|
this.ensureAssetsPrepared(compilation);
|
|
83
83
|
const chunkMapping = this.getChunkIdToGroupMapping(compilation);
|
|
84
|
+
set.add(_webpack.RuntimeGlobals.publicPath);
|
|
84
85
|
compilation.addRuntimeModule(chunk, new _I18nGroupRuntimeModule.I18nGroupRuntimeModule({
|
|
85
86
|
customGroups: this.options.customGroups,
|
|
86
87
|
chunkIdToGroupMapping: chunkMapping,
|
|
@@ -88,7 +89,6 @@ class I18nNumericIndexPlugin {
|
|
|
88
89
|
jsonpFunc: this.options.jsonpFunc,
|
|
89
90
|
groupAssetUrls: this.groupAssetUrls,
|
|
90
91
|
includeContentHash: this.options.includeContentHash,
|
|
91
|
-
publicPathPrefix: this.options.groupPublicPathPrefix,
|
|
92
92
|
publicPathRuntimeExpression: this.options.groupPublicPathRuntimeExpression
|
|
93
93
|
}));
|
|
94
94
|
}
|
|
@@ -162,6 +162,120 @@ class I18nNumericIndexPlugin {
|
|
|
162
162
|
return chunkIdToGroup;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
getAvailableLocales(propertiesFolderPath) {
|
|
166
|
+
const locales = ['en_US'];
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
const files = _fs.default.readdirSync(propertiesFolderPath);
|
|
170
|
+
|
|
171
|
+
files.forEach(file => {
|
|
172
|
+
if (file.endsWith('.properties')) {
|
|
173
|
+
const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
|
|
174
|
+
|
|
175
|
+
if (match && !locales.includes(match[1])) {
|
|
176
|
+
locales.push(match[1]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.warn(`[I18nNumericIndexPlugin] Failed to read properties folder: ${err.message}`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return locales;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
processLocale(locale, jsResourceKeys, propertiesFolderPath, compilation) {
|
|
188
|
+
const {
|
|
189
|
+
customGroups,
|
|
190
|
+
jsonpFunc,
|
|
191
|
+
numericFilenameTemplate,
|
|
192
|
+
dynamicFilenameTemplate
|
|
193
|
+
} = this.options;
|
|
194
|
+
let localeData;
|
|
195
|
+
|
|
196
|
+
if (locale === 'en_US') {
|
|
197
|
+
localeData = jsResourceKeys;
|
|
198
|
+
} else {
|
|
199
|
+
const localeFile = _path.default.join(propertiesFolderPath, `ApplicationResources_${locale}.properties`);
|
|
200
|
+
|
|
201
|
+
if (!_fs.default.existsSync(localeFile)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
const localeProperties = (0, _propertiesUtils.getPropertiesAsJSON)(localeFile);
|
|
207
|
+
localeData = { ...jsResourceKeys,
|
|
208
|
+
...this.normalizeObjectValues(localeProperties)
|
|
209
|
+
};
|
|
210
|
+
} catch (err) {
|
|
211
|
+
console.warn(`[I18nNumericIndexPlugin] Failed to load locale ${locale}: ${err.message}`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (this.options.restrictToBaseKeys) {
|
|
217
|
+
const baseKeys = Object.keys(jsResourceKeys);
|
|
218
|
+
const filtered = {};
|
|
219
|
+
baseKeys.forEach(k => {
|
|
220
|
+
filtered[k] = localeData[k];
|
|
221
|
+
});
|
|
222
|
+
localeData = filtered;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const numericData = {};
|
|
226
|
+
const dynamicData = {};
|
|
227
|
+
const groupData = {};
|
|
228
|
+
Object.keys(customGroups || {}).forEach(groupName => {
|
|
229
|
+
groupData[groupName] = {};
|
|
230
|
+
});
|
|
231
|
+
Object.keys(localeData).forEach(key => {
|
|
232
|
+
const value = localeData[key];
|
|
233
|
+
const numericId = this.numericMap[key];
|
|
234
|
+
const hasNumericId = numericId !== undefined && numericId !== null;
|
|
235
|
+
|
|
236
|
+
if (hasNumericId) {
|
|
237
|
+
const numericKey = String(numericId);
|
|
238
|
+
const belongsToGroup = this.getKeyGroup(key);
|
|
239
|
+
|
|
240
|
+
if (belongsToGroup) {
|
|
241
|
+
groupData[belongsToGroup][numericKey] = value;
|
|
242
|
+
} else {
|
|
243
|
+
numericData[numericKey] = value;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
dynamicData[key] = value;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
if (this.options.singleFile) {
|
|
251
|
+
const combinedData = { ...numericData,
|
|
252
|
+
...dynamicData
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
if (Object.keys(combinedData).length > 0) {
|
|
256
|
+
const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
|
|
257
|
+
this.prepareChunkAsset(compilation, singleFileTemplate, locale, combinedData, jsonpFunc, null, null);
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
if (Object.keys(numericData).length > 0) {
|
|
261
|
+
this.prepareChunkAsset(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (Object.keys(dynamicData).length > 0) {
|
|
265
|
+
this.prepareChunkAsset(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
Object.entries(groupData).forEach(([groupName, data]) => {
|
|
270
|
+
const groupConfig = customGroups[groupName];
|
|
271
|
+
|
|
272
|
+
if (groupConfig && Object.keys(data).length > 0) {
|
|
273
|
+
const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
|
|
274
|
+
this.prepareChunkAsset(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
165
279
|
processI18nFiles(compilation) {
|
|
166
280
|
this.preparedAssets = [];
|
|
167
281
|
this.groupAssetUrls = {};
|
|
@@ -169,14 +283,18 @@ class I18nNumericIndexPlugin {
|
|
|
169
283
|
jsResourcePath,
|
|
170
284
|
propertiesFolderPath,
|
|
171
285
|
numericMapPath,
|
|
172
|
-
customGroups
|
|
173
|
-
jsonpFunc,
|
|
174
|
-
numericFilenameTemplate,
|
|
175
|
-
dynamicFilenameTemplate
|
|
286
|
+
customGroups
|
|
176
287
|
} = this.options;
|
|
177
288
|
|
|
178
289
|
if (!jsResourcePath || !propertiesFolderPath) {
|
|
179
290
|
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
compilation.fileDependencies.add(_path.default.resolve(jsResourcePath));
|
|
294
|
+
compilation.fileDependencies.add(_path.default.resolve(propertiesFolderPath));
|
|
295
|
+
|
|
296
|
+
if (numericMapPath) {
|
|
297
|
+
compilation.fileDependencies.add(_path.default.resolve(numericMapPath));
|
|
180
298
|
} // Reset caches for incremental builds
|
|
181
299
|
|
|
182
300
|
|
|
@@ -203,92 +321,10 @@ class I18nNumericIndexPlugin {
|
|
|
203
321
|
this.parseCustomGroups(jsResourcePath, customGroups);
|
|
204
322
|
}
|
|
205
323
|
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
Object.keys(allI18nObject).forEach(loc => {
|
|
212
|
-
allI18nObject[loc] = this.normalizeObjectValues(allI18nObject[loc]);
|
|
213
|
-
});
|
|
214
|
-
allI18nObject['en_US'] = jsResourceKeys;
|
|
215
|
-
|
|
216
|
-
if (this.options.restrictToBaseKeys) {
|
|
217
|
-
const baseKeys = Object.keys(jsResourceKeys);
|
|
218
|
-
Object.keys(allI18nObject).forEach(locale => {
|
|
219
|
-
const merged = { ...jsResourceKeys,
|
|
220
|
-
...allI18nObject[locale]
|
|
221
|
-
};
|
|
222
|
-
const filtered = {};
|
|
223
|
-
baseKeys.forEach(k => {
|
|
224
|
-
filtered[k] = merged[k];
|
|
225
|
-
});
|
|
226
|
-
allI18nObject[locale] = filtered;
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const locales = Object.keys(allI18nObject);
|
|
231
|
-
locales.forEach(locale => {
|
|
232
|
-
const localeData = allI18nObject[locale];
|
|
233
|
-
const numericData = {};
|
|
234
|
-
const dynamicData = {};
|
|
235
|
-
const groupData = {};
|
|
236
|
-
Object.keys(customGroups || {}).forEach(groupName => {
|
|
237
|
-
groupData[groupName] = {};
|
|
238
|
-
}); // Process each key
|
|
239
|
-
|
|
240
|
-
Object.keys(localeData).forEach(key => {
|
|
241
|
-
const value = localeData[key]; // Simple logic: if has numeric ID use it, otherwise it's dynamic
|
|
242
|
-
|
|
243
|
-
const numericId = this.numericMap[key];
|
|
244
|
-
const hasNumericId = numericId !== undefined && numericId !== null;
|
|
245
|
-
|
|
246
|
-
if (hasNumericId) {
|
|
247
|
-
const numericKey = String(numericId); // Check if belongs to a custom group
|
|
248
|
-
|
|
249
|
-
const belongsToGroup = this.getKeyGroup(key);
|
|
250
|
-
|
|
251
|
-
if (belongsToGroup) {
|
|
252
|
-
groupData[belongsToGroup][numericKey] = value;
|
|
253
|
-
} else {
|
|
254
|
-
numericData[numericKey] = value;
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
// No numeric ID = dynamic key
|
|
258
|
-
dynamicData[key] = value;
|
|
259
|
-
}
|
|
260
|
-
}); // Handle single-file mode or separate files
|
|
261
|
-
|
|
262
|
-
if (this.options.singleFile) {
|
|
263
|
-
const combinedData = { ...numericData,
|
|
264
|
-
...dynamicData
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
if (Object.keys(combinedData).length > 0) {
|
|
268
|
-
const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
|
|
269
|
-
this.prepareChunkAsset(compilation, singleFileTemplate, locale, combinedData, jsonpFunc, null, null);
|
|
270
|
-
}
|
|
271
|
-
} else {
|
|
272
|
-
// Emit numeric chunk
|
|
273
|
-
if (Object.keys(numericData).length > 0) {
|
|
274
|
-
this.prepareChunkAsset(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
|
|
275
|
-
} // Emit dynamic chunk
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (Object.keys(dynamicData).length > 0) {
|
|
279
|
-
this.prepareChunkAsset(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
|
|
280
|
-
}
|
|
281
|
-
} // Emit custom group chunks (always separate)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
Object.entries(groupData).forEach(([groupName, data]) => {
|
|
285
|
-
const groupConfig = customGroups[groupName];
|
|
286
|
-
|
|
287
|
-
if (groupConfig && Object.keys(data).length > 0) {
|
|
288
|
-
const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
|
|
289
|
-
this.prepareChunkAsset(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
324
|
+
const availableLocales = this.getAvailableLocales(propertiesFolderPath);
|
|
325
|
+
console.log(`[I18nNumericIndexPlugin] Processing ${availableLocales.length} locales:`, availableLocales.join(', '));
|
|
326
|
+
availableLocales.forEach(locale => {
|
|
327
|
+
this.processLocale(locale, jsResourceKeys, propertiesFolderPath, compilation);
|
|
292
328
|
}); // Generate manifest file if enabled
|
|
293
329
|
|
|
294
330
|
if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js
CHANGED
|
@@ -12,7 +12,7 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
12
12
|
|
|
13
13
|
var _path = _interopRequireDefault(require("path"));
|
|
14
14
|
|
|
15
|
-
var _propertiesUtils = require("../../I18nSplitPlugin/utils/propertiesUtils
|
|
15
|
+
var _propertiesUtils = require("../../I18nSplitPlugin/utils/propertiesUtils");
|
|
16
16
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.i18nIdReplaceLoaderConfig = i18nIdReplaceLoaderConfig;
|
|
7
7
|
|
|
8
|
-
var _propertiesUtils = require("../custom_plugins/I18nSplitPlugin/utils/propertiesUtils
|
|
8
|
+
var _propertiesUtils = require("../custom_plugins/I18nSplitPlugin/utils/propertiesUtils");
|
|
9
9
|
|
|
10
|
-
var _i18nOptionsValidator = require("../common/i18nOptionsValidator
|
|
10
|
+
var _i18nOptionsValidator = require("../common/i18nOptionsValidator");
|
|
11
11
|
|
|
12
12
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
13
|
|
|
@@ -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
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/client_build_tool",
|
|
3
|
-
"version": "0.0.11-exp.
|
|
3
|
+
"version": "0.0.11-exp.32.0",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@zohodesk/client_build_tool",
|
|
9
|
-
"version": "0.0.11-exp.
|
|
9
|
+
"version": "0.0.11-exp.32.0",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/cli": "7.17.10",
|