@zohodesk/client_build_tool 0.0.11-exp.32.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 +5 -23
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +6 -3
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +128 -91
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +1 -1
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
CHANGED
|
@@ -129,7 +129,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
129
129
|
return Promise.resolve();
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
return new Promise(function(resolve) {
|
|
132
|
+
return new Promise(function(resolve, reject) {
|
|
133
133
|
var relativePath;
|
|
134
134
|
|
|
135
135
|
if (groupAssetUrls[groupName] && groupAssetUrls[groupName][locale]) {
|
|
@@ -143,6 +143,9 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
143
143
|
var script = document.createElement('script');
|
|
144
144
|
script.src = i18nUrl;
|
|
145
145
|
script.async = true;
|
|
146
|
+
if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.nc) {
|
|
147
|
+
script.setAttribute('nonce', __webpack_require__.nc);
|
|
148
|
+
}
|
|
146
149
|
|
|
147
150
|
var cleanup = function() {
|
|
148
151
|
if (script.parentNode) {
|
|
@@ -158,11 +161,10 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
158
161
|
|
|
159
162
|
script.onerror = function(err) {
|
|
160
163
|
cleanup();
|
|
161
|
-
loadedGroups[groupName] = true;
|
|
162
164
|
if (typeof console !== 'undefined' && console.warn) {
|
|
163
165
|
console.warn('Failed to load i18n group', groupName, 'from', i18nUrl, err);
|
|
164
166
|
}
|
|
165
|
-
|
|
167
|
+
reject(new Error('Failed to load i18n group: ' + groupName));
|
|
166
168
|
};
|
|
167
169
|
|
|
168
170
|
document.head.appendChild(script);
|
|
@@ -173,26 +175,6 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
173
175
|
return chunkIdToGroup[chunkId];
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
var originalEnsureChunk = __webpack_require__.e;
|
|
177
|
-
|
|
178
|
-
if (originalEnsureChunk) {
|
|
179
|
-
__webpack_require__.e = function(chunkId) {
|
|
180
|
-
var args = arguments;
|
|
181
|
-
var self = this;
|
|
182
|
-
var groupName = findGroupByChunkId(chunkId);
|
|
183
|
-
|
|
184
|
-
if (groupName && !loadedGroups[groupName]) {
|
|
185
|
-
return loadI18nGroup(groupName).then(function() {
|
|
186
|
-
return originalEnsureChunk.apply(self, args);
|
|
187
|
-
}).catch(function() {
|
|
188
|
-
return originalEnsureChunk.apply(self, args);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return originalEnsureChunk.apply(this, args);
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
178
|
if (!${_webpack.RuntimeGlobals.ensureChunkHandlers}) {
|
|
197
179
|
${_webpack.RuntimeGlobals.ensureChunkHandlers} = {};
|
|
198
180
|
}
|
|
@@ -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
|
@@ -22,7 +22,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
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) {
|
|
@@ -67,6 +67,7 @@ class I18nNumericIndexPlugin {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
apply(compiler) {
|
|
70
|
+
console.log(`[I18nNumericIndexPlugin] Plugin loaded - v1.0.0`);
|
|
70
71
|
this.detectI18nGroupComments(compiler);
|
|
71
72
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
72
73
|
this.groupAssetUrls = {};
|
|
@@ -161,6 +162,120 @@ class I18nNumericIndexPlugin {
|
|
|
161
162
|
return chunkIdToGroup;
|
|
162
163
|
}
|
|
163
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
|
+
|
|
164
279
|
processI18nFiles(compilation) {
|
|
165
280
|
this.preparedAssets = [];
|
|
166
281
|
this.groupAssetUrls = {};
|
|
@@ -168,14 +283,18 @@ class I18nNumericIndexPlugin {
|
|
|
168
283
|
jsResourcePath,
|
|
169
284
|
propertiesFolderPath,
|
|
170
285
|
numericMapPath,
|
|
171
|
-
customGroups
|
|
172
|
-
jsonpFunc,
|
|
173
|
-
numericFilenameTemplate,
|
|
174
|
-
dynamicFilenameTemplate
|
|
286
|
+
customGroups
|
|
175
287
|
} = this.options;
|
|
176
288
|
|
|
177
289
|
if (!jsResourcePath || !propertiesFolderPath) {
|
|
178
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));
|
|
179
298
|
} // Reset caches for incremental builds
|
|
180
299
|
|
|
181
300
|
|
|
@@ -202,92 +321,10 @@ class I18nNumericIndexPlugin {
|
|
|
202
321
|
this.parseCustomGroups(jsResourcePath, customGroups);
|
|
203
322
|
}
|
|
204
323
|
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
});
|
|
210
|
-
Object.keys(allI18nObject).forEach(loc => {
|
|
211
|
-
allI18nObject[loc] = this.normalizeObjectValues(allI18nObject[loc]);
|
|
212
|
-
});
|
|
213
|
-
allI18nObject['en_US'] = jsResourceKeys;
|
|
214
|
-
|
|
215
|
-
if (this.options.restrictToBaseKeys) {
|
|
216
|
-
const baseKeys = Object.keys(jsResourceKeys);
|
|
217
|
-
Object.keys(allI18nObject).forEach(locale => {
|
|
218
|
-
const merged = { ...jsResourceKeys,
|
|
219
|
-
...allI18nObject[locale]
|
|
220
|
-
};
|
|
221
|
-
const filtered = {};
|
|
222
|
-
baseKeys.forEach(k => {
|
|
223
|
-
filtered[k] = merged[k];
|
|
224
|
-
});
|
|
225
|
-
allI18nObject[locale] = filtered;
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const locales = Object.keys(allI18nObject);
|
|
230
|
-
locales.forEach(locale => {
|
|
231
|
-
const localeData = allI18nObject[locale];
|
|
232
|
-
const numericData = {};
|
|
233
|
-
const dynamicData = {};
|
|
234
|
-
const groupData = {};
|
|
235
|
-
Object.keys(customGroups || {}).forEach(groupName => {
|
|
236
|
-
groupData[groupName] = {};
|
|
237
|
-
}); // Process each key
|
|
238
|
-
|
|
239
|
-
Object.keys(localeData).forEach(key => {
|
|
240
|
-
const value = localeData[key]; // Simple logic: if has numeric ID use it, otherwise it's dynamic
|
|
241
|
-
|
|
242
|
-
const numericId = this.numericMap[key];
|
|
243
|
-
const hasNumericId = numericId !== undefined && numericId !== null;
|
|
244
|
-
|
|
245
|
-
if (hasNumericId) {
|
|
246
|
-
const numericKey = String(numericId); // Check if belongs to a custom group
|
|
247
|
-
|
|
248
|
-
const belongsToGroup = this.getKeyGroup(key);
|
|
249
|
-
|
|
250
|
-
if (belongsToGroup) {
|
|
251
|
-
groupData[belongsToGroup][numericKey] = value;
|
|
252
|
-
} else {
|
|
253
|
-
numericData[numericKey] = value;
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
// No numeric ID = dynamic key
|
|
257
|
-
dynamicData[key] = value;
|
|
258
|
-
}
|
|
259
|
-
}); // Handle single-file mode or separate files
|
|
260
|
-
|
|
261
|
-
if (this.options.singleFile) {
|
|
262
|
-
const combinedData = { ...numericData,
|
|
263
|
-
...dynamicData
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
if (Object.keys(combinedData).length > 0) {
|
|
267
|
-
const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
|
|
268
|
-
this.prepareChunkAsset(compilation, singleFileTemplate, locale, combinedData, jsonpFunc, null, null);
|
|
269
|
-
}
|
|
270
|
-
} else {
|
|
271
|
-
// Emit numeric chunk
|
|
272
|
-
if (Object.keys(numericData).length > 0) {
|
|
273
|
-
this.prepareChunkAsset(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
|
|
274
|
-
} // Emit dynamic chunk
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (Object.keys(dynamicData).length > 0) {
|
|
278
|
-
this.prepareChunkAsset(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
|
|
279
|
-
}
|
|
280
|
-
} // Emit custom group chunks (always separate)
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
Object.entries(groupData).forEach(([groupName, data]) => {
|
|
284
|
-
const groupConfig = customGroups[groupName];
|
|
285
|
-
|
|
286
|
-
if (groupConfig && Object.keys(data).length > 0) {
|
|
287
|
-
const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
|
|
288
|
-
this.prepareChunkAsset(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
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);
|
|
291
328
|
}); // Generate manifest file if enabled
|
|
292
329
|
|
|
293
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
|
|
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",
|