@zohodesk/client_build_tool 0.0.11-exp.32.0 → 0.0.11-exp.34.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 +1 -2
- package/lib/schemas/defaultConfigValuesOnly.js +1 -2
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +9 -100
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +35 -15
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +136 -101
- 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 +1 -8
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -199,8 +199,7 @@ var _default = {
|
|
|
199
199
|
emitFiles: true,
|
|
200
200
|
injectI18nUrlInIndex: true,
|
|
201
201
|
customGroups: null,
|
|
202
|
-
chunkToGroupMapping: {}
|
|
203
|
-
groupPublicPathRuntimeExpression: 'window.__SMAP_PATH__'
|
|
202
|
+
chunkToGroupMapping: {}
|
|
204
203
|
},
|
|
205
204
|
publicFolders: {
|
|
206
205
|
dev: ['...'],
|
|
@@ -116,8 +116,7 @@ var _default = {
|
|
|
116
116
|
emitFiles: true,
|
|
117
117
|
injectI18nUrlInIndex: true,
|
|
118
118
|
customGroups: null,
|
|
119
|
-
chunkToGroupMapping: {}
|
|
120
|
-
groupPublicPathRuntimeExpression: 'window.__SMAP_PATH__'
|
|
119
|
+
chunkToGroupMapping: {}
|
|
121
120
|
},
|
|
122
121
|
publicFolders: {
|
|
123
122
|
dev: ['...'],
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
CHANGED
|
@@ -19,101 +19,29 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
19
19
|
customGroups,
|
|
20
20
|
chunkIdToGroupMapping,
|
|
21
21
|
localeVarName,
|
|
22
|
-
groupAssetUrls
|
|
23
|
-
publicPathRuntimeExpression
|
|
22
|
+
groupAssetUrls
|
|
24
23
|
} = this.options;
|
|
25
24
|
const chunkIdToGroup = chunkIdToGroupMapping || {};
|
|
26
|
-
const runtimePublicPathResolver = publicPathRuntimeExpression ? `function(){ try { return ${publicPathRuntimeExpression}; } catch (err) { return undefined; } }` : 'function(){ return undefined; }';
|
|
27
25
|
return `
|
|
28
|
-
// I18n Group Loading Runtime
|
|
29
26
|
(function() {
|
|
30
27
|
var loadedGroups = {};
|
|
31
28
|
var chunkIdToGroup = ${JSON.stringify(chunkIdToGroup)};
|
|
32
29
|
var groupAssetUrls = ${JSON.stringify(groupAssetUrls || {})};
|
|
33
|
-
var runtimePublicPathResolver = ${runtimePublicPathResolver};
|
|
34
|
-
var cachedDocumentBase;
|
|
35
|
-
|
|
36
|
-
function ensureTrailingSlash(path) {
|
|
37
|
-
if (!path) return '';
|
|
38
|
-
return path.charAt(path.length - 1) === '/' ? path : path + '/';
|
|
39
|
-
}
|
|
40
30
|
|
|
41
31
|
function normalizeRelativePath(path) {
|
|
42
|
-
|
|
43
|
-
return path.charAt(0) === '/' ? path.slice(1) : path;
|
|
32
|
+
return path && path.charAt(0) === '/' ? path.slice(1) : path;
|
|
44
33
|
}
|
|
45
34
|
|
|
46
35
|
function isFullUrl(value) {
|
|
47
|
-
|
|
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);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
var documentBase = getDocumentBase();
|
|
98
|
-
if (documentBase) {
|
|
99
|
-
return documentBase;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return '';
|
|
36
|
+
return typeof value === 'string' && (value.indexOf('://') !== -1 || value.startsWith('//'));
|
|
103
37
|
}
|
|
104
38
|
|
|
105
39
|
function buildI18nUrl(relativePath) {
|
|
106
|
-
if (!relativePath) {
|
|
107
|
-
return resolveRuntimePublicPath();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
40
|
if (isFullUrl(relativePath)) {
|
|
111
41
|
return relativePath;
|
|
112
42
|
}
|
|
113
|
-
|
|
114
43
|
var normalizedPath = normalizeRelativePath(relativePath);
|
|
115
|
-
|
|
116
|
-
return base + normalizedPath;
|
|
44
|
+
return ${_webpack.RuntimeGlobals.publicPath} + normalizedPath;
|
|
117
45
|
}
|
|
118
46
|
|
|
119
47
|
function loadI18nGroup(groupName) {
|
|
@@ -129,7 +57,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
129
57
|
return Promise.resolve();
|
|
130
58
|
}
|
|
131
59
|
|
|
132
|
-
return new Promise(function(resolve) {
|
|
60
|
+
return new Promise(function(resolve, reject) {
|
|
133
61
|
var relativePath;
|
|
134
62
|
|
|
135
63
|
if (groupAssetUrls[groupName] && groupAssetUrls[groupName][locale]) {
|
|
@@ -143,6 +71,9 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
143
71
|
var script = document.createElement('script');
|
|
144
72
|
script.src = i18nUrl;
|
|
145
73
|
script.async = true;
|
|
74
|
+
if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.nc) {
|
|
75
|
+
script.setAttribute('nonce', __webpack_require__.nc);
|
|
76
|
+
}
|
|
146
77
|
|
|
147
78
|
var cleanup = function() {
|
|
148
79
|
if (script.parentNode) {
|
|
@@ -158,11 +89,10 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
158
89
|
|
|
159
90
|
script.onerror = function(err) {
|
|
160
91
|
cleanup();
|
|
161
|
-
loadedGroups[groupName] = true;
|
|
162
92
|
if (typeof console !== 'undefined' && console.warn) {
|
|
163
93
|
console.warn('Failed to load i18n group', groupName, 'from', i18nUrl, err);
|
|
164
94
|
}
|
|
165
|
-
|
|
95
|
+
reject(new Error('Failed to load i18n group: ' + groupName));
|
|
166
96
|
};
|
|
167
97
|
|
|
168
98
|
document.head.appendChild(script);
|
|
@@ -173,26 +103,6 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
173
103
|
return chunkIdToGroup[chunkId];
|
|
174
104
|
}
|
|
175
105
|
|
|
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
106
|
if (!${_webpack.RuntimeGlobals.ensureChunkHandlers}) {
|
|
197
107
|
${_webpack.RuntimeGlobals.ensureChunkHandlers} = {};
|
|
198
108
|
}
|
|
@@ -203,7 +113,6 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
203
113
|
promises.push(loadI18nGroup(groupName));
|
|
204
114
|
}
|
|
205
115
|
};
|
|
206
|
-
|
|
207
116
|
function detectGroupFromUrl() {
|
|
208
117
|
if (typeof window === 'undefined') {
|
|
209
118
|
return null;
|
|
@@ -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) {
|
|
@@ -24,14 +24,11 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
24
24
|
|
|
25
25
|
apply(compiler) {
|
|
26
26
|
compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
27
|
-
_htmlWebpackPlugin.default.getHooks(compilation).
|
|
27
|
+
_htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, cb) => {
|
|
28
28
|
if (!this.options.injectI18nUrlInIndex) {
|
|
29
|
-
return cb(null,
|
|
29
|
+
return cb(null, data);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const {
|
|
33
|
-
assets
|
|
34
|
-
} = hookData;
|
|
35
32
|
const {
|
|
36
33
|
outputFolder = 'i18n-chunk',
|
|
37
34
|
numericFilenameTemplate,
|
|
@@ -41,7 +38,7 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
41
38
|
singleFile,
|
|
42
39
|
i18nAssetsPublicPathPrefix = ''
|
|
43
40
|
} = this.options;
|
|
44
|
-
const
|
|
41
|
+
const i18nScriptTags = [];
|
|
45
42
|
const emittedAssetNames = compilation.getAssets().map(asset => asset.name);
|
|
46
43
|
const recordedAssets = compilation[assetStoreKey] || [];
|
|
47
44
|
|
|
@@ -65,8 +62,10 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
if (fullPath.includes('[contenthash]')) {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
65
|
+
const escapedPath = fullPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
66
|
+
const pattern = escapedPath.replace('\\[contenthash\\]', '[a-f0-9]{8,}');
|
|
67
|
+
const regex = new RegExp('^' + pattern + '$');
|
|
68
|
+
const matchingAsset = emittedAssetNames.find(name => regex.test(name));
|
|
70
69
|
|
|
71
70
|
if (matchingAsset) {
|
|
72
71
|
return i18nAssetsPublicPathPrefix + matchingAsset;
|
|
@@ -80,27 +79,48 @@ class I18nNumericIndexHtmlInjectorPlugin {
|
|
|
80
79
|
const combinedFilename = resolveAssetPath(singleFileTemplate, 'single');
|
|
81
80
|
|
|
82
81
|
if (combinedFilename) {
|
|
83
|
-
|
|
82
|
+
i18nScriptTags.push({
|
|
83
|
+
tagName: 'script',
|
|
84
|
+
voidTag: false,
|
|
85
|
+
attributes: {
|
|
86
|
+
src: combinedFilename,
|
|
87
|
+
nonce: '{{--CSP-nonce}}'
|
|
88
|
+
}
|
|
89
|
+
});
|
|
84
90
|
}
|
|
85
91
|
} else {
|
|
86
92
|
const numericFilename = resolveAssetPath(numericFilenameTemplate, 'numeric');
|
|
87
93
|
|
|
88
94
|
if (numericFilename) {
|
|
89
|
-
|
|
95
|
+
i18nScriptTags.push({
|
|
96
|
+
tagName: 'script',
|
|
97
|
+
voidTag: false,
|
|
98
|
+
attributes: {
|
|
99
|
+
src: numericFilename,
|
|
100
|
+
nonce: '{{--CSP-nonce}}'
|
|
101
|
+
}
|
|
102
|
+
});
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
const dynamicFilename = resolveAssetPath(dynamicFilenameTemplate, 'dynamic');
|
|
93
106
|
|
|
94
107
|
if (dynamicFilename) {
|
|
95
|
-
|
|
108
|
+
i18nScriptTags.push({
|
|
109
|
+
tagName: 'script',
|
|
110
|
+
voidTag: false,
|
|
111
|
+
attributes: {
|
|
112
|
+
src: dynamicFilename,
|
|
113
|
+
nonce: '{{--CSP-nonce}}'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
96
116
|
}
|
|
97
117
|
}
|
|
98
118
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
119
|
+
if (i18nScriptTags.length > 0) {
|
|
120
|
+
data.headTags = [...i18nScriptTags, ...data.headTags];
|
|
101
121
|
}
|
|
102
122
|
|
|
103
|
-
|
|
123
|
+
cb(null, data);
|
|
104
124
|
});
|
|
105
125
|
});
|
|
106
126
|
}
|
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) {
|
|
@@ -53,8 +53,7 @@ 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 || {}
|
|
57
|
-
groupPublicPathRuntimeExpression: options.groupPublicPathRuntimeExpression || ''
|
|
56
|
+
chunkToGroupMapping: options.chunkToGroupMapping || {}
|
|
58
57
|
};
|
|
59
58
|
this.numericMap = {};
|
|
60
59
|
this.customGroups = {};
|
|
@@ -85,10 +84,7 @@ class I18nNumericIndexPlugin {
|
|
|
85
84
|
customGroups: this.options.customGroups,
|
|
86
85
|
chunkIdToGroupMapping: chunkMapping,
|
|
87
86
|
localeVarName: this.options.localeVarName,
|
|
88
|
-
|
|
89
|
-
groupAssetUrls: this.groupAssetUrls,
|
|
90
|
-
includeContentHash: this.options.includeContentHash,
|
|
91
|
-
publicPathRuntimeExpression: this.options.groupPublicPathRuntimeExpression
|
|
87
|
+
groupAssetUrls: this.groupAssetUrls
|
|
92
88
|
}));
|
|
93
89
|
}
|
|
94
90
|
});
|
|
@@ -161,6 +157,117 @@ class I18nNumericIndexPlugin {
|
|
|
161
157
|
return chunkIdToGroup;
|
|
162
158
|
}
|
|
163
159
|
|
|
160
|
+
getAvailableLocales(propertiesFolderPath) {
|
|
161
|
+
const locales = ['en_US'];
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const files = _fs.default.readdirSync(propertiesFolderPath);
|
|
165
|
+
|
|
166
|
+
files.forEach(file => {
|
|
167
|
+
if (file.endsWith('.properties')) {
|
|
168
|
+
const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
|
|
169
|
+
|
|
170
|
+
if (match && !locales.includes(match[1])) {
|
|
171
|
+
locales.push(match[1]);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
} catch (err) {}
|
|
176
|
+
|
|
177
|
+
return locales;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
processLocale(locale, jsResourceKeys, propertiesFolderPath, compilation) {
|
|
181
|
+
const {
|
|
182
|
+
customGroups,
|
|
183
|
+
jsonpFunc,
|
|
184
|
+
numericFilenameTemplate,
|
|
185
|
+
dynamicFilenameTemplate
|
|
186
|
+
} = this.options;
|
|
187
|
+
let localeData;
|
|
188
|
+
|
|
189
|
+
if (locale === 'en_US') {
|
|
190
|
+
localeData = jsResourceKeys;
|
|
191
|
+
} else {
|
|
192
|
+
const localeFile = _path.default.join(propertiesFolderPath, `ApplicationResources_${locale}.properties`);
|
|
193
|
+
|
|
194
|
+
if (!_fs.default.existsSync(localeFile)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
const localeProperties = (0, _propertiesUtils.getPropertiesAsJSON)(localeFile);
|
|
200
|
+
localeData = { ...jsResourceKeys,
|
|
201
|
+
...this.normalizeObjectValues(localeProperties)
|
|
202
|
+
};
|
|
203
|
+
} catch (err) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (this.options.restrictToBaseKeys) {
|
|
209
|
+
const baseKeys = Object.keys(jsResourceKeys);
|
|
210
|
+
const filtered = {};
|
|
211
|
+
baseKeys.forEach(k => {
|
|
212
|
+
filtered[k] = localeData[k];
|
|
213
|
+
});
|
|
214
|
+
localeData = filtered;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const numericData = {};
|
|
218
|
+
const dynamicData = {};
|
|
219
|
+
const groupData = {};
|
|
220
|
+
Object.keys(customGroups || {}).forEach(groupName => {
|
|
221
|
+
groupData[groupName] = {};
|
|
222
|
+
});
|
|
223
|
+
Object.keys(localeData).forEach(key => {
|
|
224
|
+
const value = localeData[key];
|
|
225
|
+
const numericId = this.numericMap[key];
|
|
226
|
+
const hasNumericId = numericId !== undefined && numericId !== null;
|
|
227
|
+
|
|
228
|
+
if (hasNumericId) {
|
|
229
|
+
const numericKey = String(numericId);
|
|
230
|
+
const belongsToGroup = this.getKeyGroup(key);
|
|
231
|
+
|
|
232
|
+
if (belongsToGroup) {
|
|
233
|
+
groupData[belongsToGroup][numericKey] = value;
|
|
234
|
+
} else {
|
|
235
|
+
numericData[numericKey] = value;
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
dynamicData[key] = value;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (this.options.singleFile) {
|
|
243
|
+
const combinedData = { ...numericData,
|
|
244
|
+
...dynamicData
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
if (Object.keys(combinedData).length > 0) {
|
|
248
|
+
const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
|
|
249
|
+
this.prepareChunkAsset(compilation, singleFileTemplate, locale, combinedData, jsonpFunc, null, null);
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
if (Object.keys(numericData).length > 0) {
|
|
253
|
+
this.prepareChunkAsset(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (Object.keys(dynamicData).length > 0) {
|
|
257
|
+
this.prepareChunkAsset(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
Object.entries(groupData).forEach(([groupName, data]) => {
|
|
262
|
+
const groupConfig = customGroups[groupName];
|
|
263
|
+
|
|
264
|
+
if (groupConfig && Object.keys(data).length > 0) {
|
|
265
|
+
const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
|
|
266
|
+
this.prepareChunkAsset(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
164
271
|
processI18nFiles(compilation) {
|
|
165
272
|
this.preparedAssets = [];
|
|
166
273
|
this.groupAssetUrls = {};
|
|
@@ -168,16 +275,28 @@ class I18nNumericIndexPlugin {
|
|
|
168
275
|
jsResourcePath,
|
|
169
276
|
propertiesFolderPath,
|
|
170
277
|
numericMapPath,
|
|
171
|
-
customGroups
|
|
172
|
-
jsonpFunc,
|
|
173
|
-
numericFilenameTemplate,
|
|
174
|
-
dynamicFilenameTemplate
|
|
278
|
+
customGroups
|
|
175
279
|
} = this.options;
|
|
176
280
|
|
|
177
281
|
if (!jsResourcePath || !propertiesFolderPath) {
|
|
178
282
|
return;
|
|
179
|
-
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
compilation.fileDependencies.add(_path.default.resolve(jsResourcePath));
|
|
286
|
+
|
|
287
|
+
if (numericMapPath) {
|
|
288
|
+
compilation.fileDependencies.add(_path.default.resolve(numericMapPath));
|
|
289
|
+
}
|
|
180
290
|
|
|
291
|
+
try {
|
|
292
|
+
const propertiesFiles = _fs.default.readdirSync(propertiesFolderPath);
|
|
293
|
+
|
|
294
|
+
propertiesFiles.forEach(file => {
|
|
295
|
+
if (file.endsWith('.properties')) {
|
|
296
|
+
compilation.fileDependencies.add(_path.default.resolve(propertiesFolderPath, file));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
} catch (err) {}
|
|
181
300
|
|
|
182
301
|
this.numericMap = {};
|
|
183
302
|
this.manifest = {};
|
|
@@ -202,93 +321,10 @@ class I18nNumericIndexPlugin {
|
|
|
202
321
|
this.parseCustomGroups(jsResourcePath, customGroups);
|
|
203
322
|
}
|
|
204
323
|
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
jsResourceI18nKeys: jsResourceKeys
|
|
209
|
-
});
|
|
210
|
-
Object.keys(allI18nObject).forEach(loc => {
|
|
211
|
-
allI18nObject[loc] = this.normalizeObjectValues(allI18nObject[loc]);
|
|
324
|
+
const availableLocales = this.getAvailableLocales(propertiesFolderPath);
|
|
325
|
+
availableLocales.forEach(locale => {
|
|
326
|
+
this.processLocale(locale, jsResourceKeys, propertiesFolderPath, compilation);
|
|
212
327
|
});
|
|
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
|
-
});
|
|
291
|
-
}); // Generate manifest file if enabled
|
|
292
328
|
|
|
293
329
|
if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
|
|
294
330
|
const manifestPath = this.options.manifestPath || _path.default.join(this.options.outputFolder, 'manifest.json');
|
|
@@ -394,7 +430,7 @@ class I18nNumericIndexPlugin {
|
|
|
394
430
|
}
|
|
395
431
|
|
|
396
432
|
const content = this.generateChunkContent(data, jsonpFunc, groupName);
|
|
397
|
-
let outputPath = this.constructFilePath(filenameTemplate, locale);
|
|
433
|
+
let outputPath = this.constructFilePath(filenameTemplate, locale);
|
|
398
434
|
|
|
399
435
|
if (outputPath.includes('[contenthash]')) {
|
|
400
436
|
const contentHash = this.generateContentHash(content, compilation);
|
|
@@ -402,8 +438,7 @@ class I18nNumericIndexPlugin {
|
|
|
402
438
|
} else if (this.options.includeContentHash) {
|
|
403
439
|
const contentHash = this.generateContentHash(content, compilation);
|
|
404
440
|
outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
|
|
405
|
-
}
|
|
406
|
-
|
|
441
|
+
}
|
|
407
442
|
|
|
408
443
|
if (this.options.generateManifest) {
|
|
409
444
|
const manifestKey = this.options.singleFile ? `${locale}.js` : outputPath;
|
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
|
|
|
@@ -21,12 +21,6 @@ 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;
|
|
30
24
|
|
|
31
25
|
try {
|
|
32
26
|
const result = (0, _i18nOptionsValidator.validateI18nIndexingOptions)(i18nOpts);
|
|
@@ -86,8 +80,7 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
86
80
|
manifestPath: i18nOpts.manifestPath || null,
|
|
87
81
|
customGroups: i18nOpts.customGroups || null,
|
|
88
82
|
chunkToGroupMapping: i18nOpts.chunkToGroupMapping || {},
|
|
89
|
-
emitFiles
|
|
90
|
-
groupPublicPathRuntimeExpression
|
|
83
|
+
emitFiles
|
|
91
84
|
};
|
|
92
85
|
const htmlInjectorOptions = { ...sharedOptions,
|
|
93
86
|
htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
|
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",
|