@rushstack/webpack4-localization-plugin 0.19.13 → 0.20.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.
Files changed (76) hide show
  1. package/CHANGELOG.json +41 -0
  2. package/CHANGELOG.md +13 -1
  3. package/dist/tsdoc-metadata.json +1 -1
  4. package/lib-esm/AssetProcessor.js +277 -0
  5. package/lib-esm/AssetProcessor.js.map +1 -0
  6. package/lib-esm/LocalizationPlugin.js +580 -0
  7. package/lib-esm/LocalizationPlugin.js.map +1 -0
  8. package/lib-esm/WebpackConfigurationUpdater.js +106 -0
  9. package/lib-esm/WebpackConfigurationUpdater.js.map +1 -0
  10. package/lib-esm/index.js +4 -0
  11. package/lib-esm/index.js.map +1 -0
  12. package/lib-esm/interfaces.js +4 -0
  13. package/lib-esm/interfaces.js.map +1 -0
  14. package/lib-esm/loaders/InPlaceLocFileLoader.js +20 -0
  15. package/lib-esm/loaders/InPlaceLocFileLoader.js.map +1 -0
  16. package/lib-esm/loaders/LoaderFactory.js +14 -0
  17. package/lib-esm/loaders/LoaderFactory.js.map +1 -0
  18. package/lib-esm/loaders/LocLoader.js +38 -0
  19. package/lib-esm/loaders/LocLoader.js.map +1 -0
  20. package/lib-esm/utilities/Constants.js +17 -0
  21. package/lib-esm/utilities/Constants.js.map +1 -0
  22. package/lib-esm/utilities/EntityMarker.js +15 -0
  23. package/lib-esm/utilities/EntityMarker.js.map +1 -0
  24. package/lib-esm/utilities/LoaderTerminalProvider.js +24 -0
  25. package/lib-esm/utilities/LoaderTerminalProvider.js.map +1 -0
  26. package/lib-esm/webpackInterfaces.js +4 -0
  27. package/lib-esm/webpackInterfaces.js.map +1 -0
  28. package/package.json +30 -8
  29. /package/{lib → lib-commonjs}/AssetProcessor.js +0 -0
  30. /package/{lib → lib-commonjs}/AssetProcessor.js.map +0 -0
  31. /package/{lib → lib-commonjs}/LocalizationPlugin.js +0 -0
  32. /package/{lib → lib-commonjs}/LocalizationPlugin.js.map +0 -0
  33. /package/{lib → lib-commonjs}/WebpackConfigurationUpdater.js +0 -0
  34. /package/{lib → lib-commonjs}/WebpackConfigurationUpdater.js.map +0 -0
  35. /package/{lib → lib-commonjs}/index.js +0 -0
  36. /package/{lib → lib-commonjs}/index.js.map +0 -0
  37. /package/{lib → lib-commonjs}/interfaces.js +0 -0
  38. /package/{lib → lib-commonjs}/interfaces.js.map +0 -0
  39. /package/{lib → lib-commonjs}/loaders/InPlaceLocFileLoader.js +0 -0
  40. /package/{lib → lib-commonjs}/loaders/InPlaceLocFileLoader.js.map +0 -0
  41. /package/{lib → lib-commonjs}/loaders/LoaderFactory.js +0 -0
  42. /package/{lib → lib-commonjs}/loaders/LoaderFactory.js.map +0 -0
  43. /package/{lib → lib-commonjs}/loaders/LocLoader.js +0 -0
  44. /package/{lib → lib-commonjs}/loaders/LocLoader.js.map +0 -0
  45. /package/{lib → lib-commonjs}/utilities/Constants.js +0 -0
  46. /package/{lib → lib-commonjs}/utilities/Constants.js.map +0 -0
  47. /package/{lib → lib-commonjs}/utilities/EntityMarker.js +0 -0
  48. /package/{lib → lib-commonjs}/utilities/EntityMarker.js.map +0 -0
  49. /package/{lib → lib-commonjs}/utilities/LoaderTerminalProvider.js +0 -0
  50. /package/{lib → lib-commonjs}/utilities/LoaderTerminalProvider.js.map +0 -0
  51. /package/{lib → lib-commonjs}/webpackInterfaces.js +0 -0
  52. /package/{lib → lib-commonjs}/webpackInterfaces.js.map +0 -0
  53. /package/{lib → lib-dts}/AssetProcessor.d.ts +0 -0
  54. /package/{lib → lib-dts}/AssetProcessor.d.ts.map +0 -0
  55. /package/{lib → lib-dts}/LocalizationPlugin.d.ts +0 -0
  56. /package/{lib → lib-dts}/LocalizationPlugin.d.ts.map +0 -0
  57. /package/{lib → lib-dts}/WebpackConfigurationUpdater.d.ts +0 -0
  58. /package/{lib → lib-dts}/WebpackConfigurationUpdater.d.ts.map +0 -0
  59. /package/{lib → lib-dts}/index.d.ts +0 -0
  60. /package/{lib → lib-dts}/index.d.ts.map +0 -0
  61. /package/{lib → lib-dts}/interfaces.d.ts +0 -0
  62. /package/{lib → lib-dts}/interfaces.d.ts.map +0 -0
  63. /package/{lib → lib-dts}/loaders/InPlaceLocFileLoader.d.ts +0 -0
  64. /package/{lib → lib-dts}/loaders/InPlaceLocFileLoader.d.ts.map +0 -0
  65. /package/{lib → lib-dts}/loaders/LoaderFactory.d.ts +0 -0
  66. /package/{lib → lib-dts}/loaders/LoaderFactory.d.ts.map +0 -0
  67. /package/{lib → lib-dts}/loaders/LocLoader.d.ts +0 -0
  68. /package/{lib → lib-dts}/loaders/LocLoader.d.ts.map +0 -0
  69. /package/{lib → lib-dts}/utilities/Constants.d.ts +0 -0
  70. /package/{lib → lib-dts}/utilities/Constants.d.ts.map +0 -0
  71. /package/{lib → lib-dts}/utilities/EntityMarker.d.ts +0 -0
  72. /package/{lib → lib-dts}/utilities/EntityMarker.d.ts.map +0 -0
  73. /package/{lib → lib-dts}/utilities/LoaderTerminalProvider.d.ts +0 -0
  74. /package/{lib → lib-dts}/utilities/LoaderTerminalProvider.d.ts.map +0 -0
  75. /package/{lib → lib-dts}/webpackInterfaces.d.ts +0 -0
  76. /package/{lib → lib-dts}/webpackInterfaces.d.ts.map +0 -0
package/CHANGELOG.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@rushstack/webpack4-localization-plugin",
3
3
  "entries": [
4
+ {
5
+ "version": "0.20.0",
6
+ "tag": "@rushstack/webpack4-localization-plugin_v0.20.0",
7
+ "date": "Thu, 19 Feb 2026 00:04:53 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `\"exports\"` field in `package.json`."
12
+ }
13
+ ],
14
+ "dependency": [
15
+ {
16
+ "comment": "Updating dependency \"@rushstack/localization-utilities\" to `0.15.0`"
17
+ },
18
+ {
19
+ "comment": "Updating dependency \"@rushstack/node-core-library\" to `5.20.0`"
20
+ },
21
+ {
22
+ "comment": "Updating dependency \"@rushstack/terminal\" to `0.22.0`"
23
+ },
24
+ {
25
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.2.0`"
26
+ }
27
+ ]
28
+ }
29
+ },
30
+ {
31
+ "version": "0.19.14",
32
+ "tag": "@rushstack/webpack4-localization-plugin_v0.19.14",
33
+ "date": "Sat, 07 Feb 2026 01:13:26 GMT",
34
+ "comments": {
35
+ "dependency": [
36
+ {
37
+ "comment": "Updating dependency \"@rushstack/localization-utilities\" to `0.14.14`"
38
+ },
39
+ {
40
+ "comment": "Updating dependency \"@rushstack/heft\" to `1.1.14`"
41
+ }
42
+ ]
43
+ }
44
+ },
4
45
  {
5
46
  "version": "0.19.13",
6
47
  "tag": "@rushstack/webpack4-localization-plugin_v0.19.13",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Change Log - @rushstack/webpack4-localization-plugin
2
2
 
3
- This log was last generated on Wed, 04 Feb 2026 20:42:47 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 19 Feb 2026 00:04:53 GMT and should not be manually modified.
4
+
5
+ ## 0.20.0
6
+ Thu, 19 Feb 2026 00:04:53 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Normalize package layout. CommonJS is now under `lib-commonjs`, DTS is now under `lib-dts`, and ESM is now under `lib-esm`. Imports to `lib` still work as before, handled by the `"exports"` field in `package.json`.
11
+
12
+ ## 0.19.14
13
+ Sat, 07 Feb 2026 01:13:26 GMT
14
+
15
+ _Version update only_
4
16
 
5
17
  ## 0.19.13
6
18
  Wed, 04 Feb 2026 20:42:47 GMT
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.56.1"
8
+ "packageVersion": "7.56.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,277 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2
+ // See LICENSE in the project root for license information.
3
+ import { Constants } from './utilities/Constants';
4
+ export const PLACEHOLDER_REGEX = new RegExp(`${Constants.STRING_PLACEHOLDER_PREFIX}_(\\\\*)_([A-C])(\\+[^+]+\\+)?_(\\d+)`, 'g');
5
+ export class AssetProcessor {
6
+ static processLocalizedAsset(options) {
7
+ const assetSource = options.asset.source();
8
+ const parsedAsset = AssetProcessor._parseStringToReconstructionSequence(options.plugin, assetSource, this._getJsonpFunction(options.chunk, options.chunkHasLocalizedModules, options.noStringsLocaleName));
9
+ const reconstructedAsset = AssetProcessor._reconstructLocalized(parsedAsset.reconstructionSeries, options.locales, options.fillMissingTranslationStrings, options.defaultLocale, options.asset.size());
10
+ const parsedAssetName = AssetProcessor._parseStringToReconstructionSequence(options.plugin, options.assetName, () => {
11
+ throw new Error('unsupported');
12
+ });
13
+ const reconstructedAssetName = AssetProcessor._reconstructLocalized(parsedAssetName.reconstructionSeries, options.locales, options.fillMissingTranslationStrings, options.defaultLocale, options.assetName.length);
14
+ const result = new Map();
15
+ for (const [locale, { source, size }] of reconstructedAsset.result) {
16
+ const newAsset = { ...options.asset };
17
+ newAsset.source = () => source;
18
+ newAsset.size = () => size;
19
+ result.set(locale, {
20
+ filename: reconstructedAssetName.result.get(locale).source,
21
+ asset: newAsset
22
+ });
23
+ }
24
+ const issues = [
25
+ ...parsedAsset.issues,
26
+ ...reconstructedAsset.issues,
27
+ ...parsedAssetName.issues,
28
+ ...reconstructedAssetName.issues
29
+ ];
30
+ if (issues.length > 0) {
31
+ options.compilation.errors.push(Error(`localization:\n${issues.map((issue) => ` ${issue}`).join('\n')}`));
32
+ }
33
+ return result;
34
+ }
35
+ static processNonLocalizedAsset(options) {
36
+ const assetSource = options.asset.source();
37
+ const parsedAsset = AssetProcessor._parseStringToReconstructionSequence(options.plugin, assetSource, this._getJsonpFunction(options.chunk, options.chunkHasLocalizedModules, options.noStringsLocaleName));
38
+ const reconstructedAsset = AssetProcessor._reconstructNonLocalized(parsedAsset.reconstructionSeries, options.asset.size(), options.noStringsLocaleName);
39
+ const parsedAssetName = AssetProcessor._parseStringToReconstructionSequence(options.plugin, options.assetName, () => {
40
+ throw new Error('unsupported');
41
+ });
42
+ const reconstructedAssetName = AssetProcessor._reconstructNonLocalized(parsedAssetName.reconstructionSeries, options.assetName.length, options.noStringsLocaleName);
43
+ const issues = [
44
+ ...parsedAsset.issues,
45
+ ...reconstructedAsset.issues,
46
+ ...parsedAssetName.issues,
47
+ ...reconstructedAssetName.issues
48
+ ];
49
+ if (issues.length > 0) {
50
+ options.compilation.errors.push(Error(`localization:\n${issues.map((issue) => ` ${issue}`).join('\n')}`));
51
+ }
52
+ const newAsset = { ...options.asset };
53
+ newAsset.source = () => reconstructedAsset.result.source;
54
+ newAsset.size = () => reconstructedAsset.result.size;
55
+ return {
56
+ filename: reconstructedAssetName.result.source,
57
+ asset: newAsset
58
+ };
59
+ }
60
+ static _reconstructLocalized(reconstructionSeries, locales, fillMissingTranslationStrings, defaultLocale, initialSize) {
61
+ const localizedResults = new Map();
62
+ const issues = [];
63
+ for (const locale of locales) {
64
+ const reconstruction = [];
65
+ let sizeDiff = 0;
66
+ for (const element of reconstructionSeries) {
67
+ switch (element.kind) {
68
+ case 'static': {
69
+ reconstruction.push(element.staticString);
70
+ break;
71
+ }
72
+ case 'localized': {
73
+ const localizedElement = element;
74
+ let newValue = localizedElement.values[locale];
75
+ if (!newValue) {
76
+ if (fillMissingTranslationStrings) {
77
+ newValue = localizedElement.values[defaultLocale];
78
+ }
79
+ else {
80
+ issues.push(`The string "${localizedElement.stringName}" in "${localizedElement.locFilePath}" is missing in ` +
81
+ `the locale ${locale}`);
82
+ newValue = '-- MISSING STRING --';
83
+ }
84
+ }
85
+ const escapedBackslash = localizedElement.escapedBackslash || '\\';
86
+ // Replace backslashes with the properly escaped backslash
87
+ newValue = newValue.replace(/\\/g, escapedBackslash);
88
+ // @todo: look into using JSON.parse(...) to get the escaping characters
89
+ const escapingCharacterSequence = escapedBackslash.substr(escapedBackslash.length / 2);
90
+ // Ensure the the quotemark, apostrophe, tab, and newline characters are properly escaped
91
+ newValue = newValue.replace(/\r/g, `${escapingCharacterSequence}r`);
92
+ newValue = newValue.replace(/\n/g, `${escapingCharacterSequence}n`);
93
+ newValue = newValue.replace(/\t/g, `${escapingCharacterSequence}t`);
94
+ newValue = newValue.replace(/\"/g, `${escapingCharacterSequence}u0022`);
95
+ newValue = newValue.replace(/\'/g, `${escapingCharacterSequence}u0027`);
96
+ reconstruction.push(newValue);
97
+ sizeDiff += newValue.length - localizedElement.size;
98
+ break;
99
+ }
100
+ case 'dynamic': {
101
+ const dynamicElement = element;
102
+ const newValue = dynamicElement.valueFn(locale, dynamicElement.token);
103
+ reconstruction.push(newValue);
104
+ sizeDiff += newValue.length - dynamicElement.size;
105
+ break;
106
+ }
107
+ }
108
+ }
109
+ const newAssetSource = reconstruction.join('');
110
+ localizedResults.set(locale, {
111
+ source: newAssetSource,
112
+ size: initialSize + sizeDiff
113
+ });
114
+ }
115
+ return {
116
+ issues,
117
+ result: localizedResults
118
+ };
119
+ }
120
+ static _reconstructNonLocalized(reconstructionSeries, initialSize, noStringsLocaleName) {
121
+ const issues = [];
122
+ const reconstruction = [];
123
+ let sizeDiff = 0;
124
+ for (const element of reconstructionSeries) {
125
+ switch (element.kind) {
126
+ case 'static': {
127
+ reconstruction.push(element.staticString);
128
+ break;
129
+ }
130
+ case 'localized': {
131
+ const localizedElement = element;
132
+ issues.push(`The string "${localizedElement.stringName}" in "${localizedElement.locFilePath}" appeared in an asset ` +
133
+ 'that is not expected to contain localized resources.');
134
+ const newValue = '-- NOT EXPECTED TO BE LOCALIZED --';
135
+ reconstruction.push(newValue);
136
+ sizeDiff += newValue.length - localizedElement.size;
137
+ break;
138
+ }
139
+ case 'dynamic': {
140
+ const dynamicElement = element;
141
+ const newValue = dynamicElement.valueFn(noStringsLocaleName, dynamicElement.token);
142
+ reconstruction.push(newValue);
143
+ sizeDiff += newValue.length - dynamicElement.size;
144
+ break;
145
+ }
146
+ }
147
+ }
148
+ const newAssetSource = reconstruction.join('');
149
+ return {
150
+ issues,
151
+ result: {
152
+ source: newAssetSource,
153
+ size: initialSize + sizeDiff
154
+ }
155
+ };
156
+ }
157
+ static _parseStringToReconstructionSequence(plugin, source, jsonpFunction) {
158
+ const issues = [];
159
+ const reconstructionSeries = [];
160
+ let lastIndex = 0;
161
+ let regexResult;
162
+ while ((regexResult = PLACEHOLDER_REGEX.exec(source))) {
163
+ const staticElement = {
164
+ kind: 'static',
165
+ staticString: source.substring(lastIndex, regexResult.index)
166
+ };
167
+ reconstructionSeries.push(staticElement);
168
+ const [placeholder, escapedBackslash, elementLabel, token, placeholderSerialNumber] = regexResult;
169
+ let localizedReconstructionElement;
170
+ switch (elementLabel) {
171
+ case Constants.STRING_PLACEHOLDER_LABEL: {
172
+ const stringData = plugin.getDataForSerialNumber(placeholderSerialNumber);
173
+ if (!stringData) {
174
+ issues.push(`Missing placeholder ${placeholder}`);
175
+ const brokenLocalizedElement = {
176
+ kind: 'static',
177
+ staticString: placeholder
178
+ };
179
+ localizedReconstructionElement = brokenLocalizedElement;
180
+ }
181
+ else {
182
+ const localizedElement = {
183
+ kind: 'localized',
184
+ values: stringData.values,
185
+ size: placeholder.length,
186
+ locFilePath: stringData.locFilePath,
187
+ escapedBackslash: escapedBackslash,
188
+ stringName: stringData.stringName
189
+ };
190
+ localizedReconstructionElement = localizedElement;
191
+ }
192
+ break;
193
+ }
194
+ case Constants.LOCALE_NAME_PLACEHOLDER_LABEL: {
195
+ const dynamicElement = {
196
+ kind: 'dynamic',
197
+ valueFn: (locale) => locale,
198
+ size: placeholder.length,
199
+ escapedBackslash: escapedBackslash
200
+ };
201
+ localizedReconstructionElement = dynamicElement;
202
+ break;
203
+ }
204
+ case Constants.JSONP_PLACEHOLDER_LABEL: {
205
+ const dynamicElement = {
206
+ kind: 'dynamic',
207
+ valueFn: jsonpFunction,
208
+ size: placeholder.length,
209
+ escapedBackslash: escapedBackslash,
210
+ token: token.substring(1, token.length - 1)
211
+ };
212
+ localizedReconstructionElement = dynamicElement;
213
+ break;
214
+ }
215
+ default: {
216
+ throw new Error(`Unexpected label ${elementLabel}`);
217
+ }
218
+ }
219
+ reconstructionSeries.push(localizedReconstructionElement);
220
+ lastIndex = regexResult.index + placeholder.length;
221
+ }
222
+ const lastElement = {
223
+ kind: 'static',
224
+ staticString: source.substr(lastIndex)
225
+ };
226
+ reconstructionSeries.push(lastElement);
227
+ return {
228
+ issues,
229
+ reconstructionSeries
230
+ };
231
+ }
232
+ static _getJsonpFunction(chunk, chunkHasLocalizedModules, noStringsLocaleName) {
233
+ const idsWithStrings = new Set();
234
+ const idsWithoutStrings = new Set();
235
+ const asyncChunks = chunk.getAllAsyncChunks();
236
+ for (const asyncChunk of asyncChunks) {
237
+ const chunkId = asyncChunk.id;
238
+ if (chunkId === null || chunkId === undefined) {
239
+ throw new Error(`Chunk "${asyncChunk.name}"'s ID is null or undefined.`);
240
+ }
241
+ if (chunkHasLocalizedModules(asyncChunk)) {
242
+ idsWithStrings.add(chunkId);
243
+ }
244
+ else {
245
+ idsWithoutStrings.add(chunkId);
246
+ }
247
+ }
248
+ if (idsWithStrings.size === 0) {
249
+ return () => JSON.stringify(noStringsLocaleName);
250
+ }
251
+ else if (idsWithoutStrings.size === 0) {
252
+ return (locale) => JSON.stringify(locale);
253
+ }
254
+ else {
255
+ // Generate an array [<locale>, <nostrings locale>] and an object that is used as an indexer into that
256
+ // object that maps chunk IDs to 0s for chunks with localized strings and 1s for chunks without localized
257
+ // strings
258
+ //
259
+ // This can be improved in the future. We can maybe sort the chunks such that the chunks below a certain ID
260
+ // number are localized and the those above are not.
261
+ const chunkMapping = {};
262
+ for (const idWithStrings of idsWithStrings) {
263
+ chunkMapping[idWithStrings] = 0;
264
+ }
265
+ for (const idWithoutStrings of idsWithoutStrings) {
266
+ chunkMapping[idWithoutStrings] = 1;
267
+ }
268
+ return (locale, chunkIdToken) => {
269
+ if (!locale) {
270
+ throw new Error('Missing locale name.');
271
+ }
272
+ return `(${JSON.stringify([locale, noStringsLocaleName])})[${JSON.stringify(chunkMapping)}[${chunkIdToken}]]`;
273
+ };
274
+ }
275
+ }
276
+ }
277
+ //# sourceMappingURL=AssetProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AssetProcessor.js","sourceRoot":"","sources":["../src/AssetProcessor.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,2DAA2D;AAI3D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AA8ElD,MAAM,CAAC,MAAM,iBAAiB,GAAW,IAAI,MAAM,CACjD,GAAG,SAAS,CAAC,yBAAyB,uCAAuC,EAC7E,GAAG,CACJ,CAAC;AAEF,MAAM,OAAO,cAAc;IAClB,MAAM,CAAC,qBAAqB,CACjC,OAAsC;QAEtC,MAAM,WAAW,GAAW,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAEnD,MAAM,WAAW,GAAiB,cAAc,CAAC,oCAAoC,CACnF,OAAO,CAAC,MAAM,EACd,WAAW,EACX,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,wBAAwB,EAAE,OAAO,CAAC,mBAAmB,CAAC,CACrG,CAAC;QACF,MAAM,kBAAkB,GAAmC,cAAc,CAAC,qBAAqB,CAC7F,WAAW,CAAC,oBAAoB,EAChC,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,6BAA6B,EACrC,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CACrB,CAAC;QAEF,MAAM,eAAe,GAAiB,cAAc,CAAC,oCAAoC,CACvF,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,SAAS,EACjB,GAAG,EAAE;YACH,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC,CACF,CAAC;QACF,MAAM,sBAAsB,GAA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AAC;YAC9B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACnD,CAAC;aAAM,IAAI,iBAAiB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,sGAAsG;YACtG,yGAAyG;YACzG,UAAU;YACV,EAAE;YACF,2GAA2G;YAC3G,oDAAoD;YACpD,MAAM,YAAY,GAAkC,EAAE,CAAC;YACvD,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;gBAC3C,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YAClC,CAAC;YAED,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;gBACjD,YAAY,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACrC,CAAC;YAED,OAAO,CAAC,MAAc,EAAE,YAAgC,EAAE,EAAE;gBAC1D,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBAC1C,CAAC;gBAED,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CACzE,YAAY,CACb,IAAI,YAAY,IAAI,CAAC;YACxB,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as Webpack from 'webpack';\n\nimport { Constants } from './utilities/Constants';\nimport type { ILocaleElementMap } from './interfaces';\nimport type { LocalizationPlugin, IStringSerialNumberData as IStringData } from './LocalizationPlugin';\n\ninterface IReconstructionElement {\n kind: 'static' | 'localized' | 'dynamic';\n}\n\ninterface IStaticReconstructionElement extends IReconstructionElement {\n kind: 'static';\n staticString: string;\n}\n\ninterface ILocalizedReconstructionElement extends IReconstructionElement {\n kind: 'localized';\n values: ILocaleElementMap;\n size: number;\n stringName: string;\n escapedBackslash: string;\n locFilePath: string;\n}\n\ninterface IDynamicReconstructionElement extends IReconstructionElement {\n kind: 'dynamic';\n valueFn: (locale: string, token: string | undefined) => string;\n size: number;\n escapedBackslash: string;\n token?: string;\n}\n\ninterface IParseResult {\n issues: string[];\n reconstructionSeries: IReconstructionElement[];\n}\n\ninterface IReconstructedString {\n source: string;\n size: number;\n}\n\ninterface ILocalizedReconstructionResult {\n result: Map<string, IReconstructedString>;\n issues: string[];\n}\n\ninterface INonLocalizedReconstructionResult {\n result: IReconstructedString;\n issues: string[];\n}\n\nexport interface IProcessAssetOptionsBase {\n plugin: LocalizationPlugin;\n compilation: Webpack.compilation.Compilation;\n assetName: string;\n asset: IAsset;\n chunk: Webpack.compilation.Chunk;\n noStringsLocaleName: string;\n chunkHasLocalizedModules: (chunk: Webpack.compilation.Chunk) => boolean;\n}\n\nexport interface IProcessNonLocalizedAssetOptions extends IProcessAssetOptionsBase {}\n\nexport interface IProcessLocalizedAssetOptions extends IProcessAssetOptionsBase {\n locales: Set<string>;\n fillMissingTranslationStrings: boolean;\n defaultLocale: string;\n}\n\nexport interface IAsset {\n size(): number;\n source(): string;\n}\n\nexport interface IProcessAssetResult {\n filename: string;\n asset: IAsset;\n}\n\nexport const PLACEHOLDER_REGEX: RegExp = new RegExp(\n `${Constants.STRING_PLACEHOLDER_PREFIX}_(\\\\\\\\*)_([A-C])(\\\\+[^+]+\\\\+)?_(\\\\d+)`,\n 'g'\n);\n\nexport class AssetProcessor {\n public static processLocalizedAsset(\n options: IProcessLocalizedAssetOptions\n ): Map<string, IProcessAssetResult> {\n const assetSource: string = options.asset.source();\n\n const parsedAsset: IParseResult = AssetProcessor._parseStringToReconstructionSequence(\n options.plugin,\n assetSource,\n this._getJsonpFunction(options.chunk, options.chunkHasLocalizedModules, options.noStringsLocaleName)\n );\n const reconstructedAsset: ILocalizedReconstructionResult = AssetProcessor._reconstructLocalized(\n parsedAsset.reconstructionSeries,\n options.locales,\n options.fillMissingTranslationStrings,\n options.defaultLocale,\n options.asset.size()\n );\n\n const parsedAssetName: IParseResult = AssetProcessor._parseStringToReconstructionSequence(\n options.plugin,\n options.assetName,\n () => {\n throw new Error('unsupported');\n }\n );\n const reconstructedAssetName: ILocalizedReconstructionResult = AssetProcessor._reconstructLocalized(\n parsedAssetName.reconstructionSeries,\n options.locales,\n options.fillMissingTranslationStrings,\n options.defaultLocale,\n options.assetName.length\n );\n\n const result: Map<string, IProcessAssetResult> = new Map<string, IProcessAssetResult>();\n for (const [locale, { source, size }] of reconstructedAsset.result) {\n const newAsset: IAsset = { ...options.asset };\n newAsset.source = () => source;\n newAsset.size = () => size;\n\n result.set(locale, {\n filename: reconstructedAssetName.result.get(locale)!.source,\n asset: newAsset\n });\n }\n\n const issues: string[] = [\n ...parsedAsset.issues,\n ...reconstructedAsset.issues,\n ...parsedAssetName.issues,\n ...reconstructedAssetName.issues\n ];\n\n if (issues.length > 0) {\n options.compilation.errors.push(\n Error(`localization:\\n${issues.map((issue) => ` ${issue}`).join('\\n')}`)\n );\n }\n\n return result;\n }\n\n public static processNonLocalizedAsset(options: IProcessNonLocalizedAssetOptions): IProcessAssetResult {\n const assetSource: string = options.asset.source();\n\n const parsedAsset: IParseResult = AssetProcessor._parseStringToReconstructionSequence(\n options.plugin,\n assetSource,\n this._getJsonpFunction(options.chunk, options.chunkHasLocalizedModules, options.noStringsLocaleName)\n );\n const reconstructedAsset: INonLocalizedReconstructionResult = AssetProcessor._reconstructNonLocalized(\n parsedAsset.reconstructionSeries,\n options.asset.size(),\n options.noStringsLocaleName\n );\n\n const parsedAssetName: IParseResult = AssetProcessor._parseStringToReconstructionSequence(\n options.plugin,\n options.assetName,\n () => {\n throw new Error('unsupported');\n }\n );\n const reconstructedAssetName: INonLocalizedReconstructionResult = AssetProcessor._reconstructNonLocalized(\n parsedAssetName.reconstructionSeries,\n options.assetName.length,\n options.noStringsLocaleName\n );\n\n const issues: string[] = [\n ...parsedAsset.issues,\n ...reconstructedAsset.issues,\n ...parsedAssetName.issues,\n ...reconstructedAssetName.issues\n ];\n\n if (issues.length > 0) {\n options.compilation.errors.push(\n Error(`localization:\\n${issues.map((issue) => ` ${issue}`).join('\\n')}`)\n );\n }\n\n const newAsset: IAsset = { ...options.asset };\n newAsset.source = () => reconstructedAsset.result.source;\n newAsset.size = () => reconstructedAsset.result.size;\n return {\n filename: reconstructedAssetName.result.source,\n asset: newAsset\n };\n }\n\n private static _reconstructLocalized(\n reconstructionSeries: IReconstructionElement[],\n locales: Set<string>,\n fillMissingTranslationStrings: boolean,\n defaultLocale: string,\n initialSize: number\n ): ILocalizedReconstructionResult {\n const localizedResults: Map<string, IReconstructedString> = new Map<string, IReconstructedString>();\n const issues: string[] = [];\n\n for (const locale of locales) {\n const reconstruction: string[] = [];\n\n let sizeDiff: number = 0;\n for (const element of reconstructionSeries) {\n switch (element.kind) {\n case 'static': {\n reconstruction.push((element as IStaticReconstructionElement).staticString);\n break;\n }\n\n case 'localized': {\n const localizedElement: ILocalizedReconstructionElement =\n element as ILocalizedReconstructionElement;\n let newValue: string | undefined = localizedElement.values[locale];\n if (!newValue) {\n if (fillMissingTranslationStrings) {\n newValue = localizedElement.values[defaultLocale];\n } else {\n issues.push(\n `The string \"${localizedElement.stringName}\" in \"${localizedElement.locFilePath}\" is missing in ` +\n `the locale ${locale}`\n );\n\n newValue = '-- MISSING STRING --';\n }\n }\n\n const escapedBackslash: string = localizedElement.escapedBackslash || '\\\\';\n\n // Replace backslashes with the properly escaped backslash\n newValue = newValue.replace(/\\\\/g, escapedBackslash);\n\n // @todo: look into using JSON.parse(...) to get the escaping characters\n const escapingCharacterSequence: string = escapedBackslash.substr(escapedBackslash.length / 2);\n\n // Ensure the the quotemark, apostrophe, tab, and newline characters are properly escaped\n newValue = newValue.replace(/\\r/g, `${escapingCharacterSequence}r`);\n newValue = newValue.replace(/\\n/g, `${escapingCharacterSequence}n`);\n newValue = newValue.replace(/\\t/g, `${escapingCharacterSequence}t`);\n newValue = newValue.replace(/\\\"/g, `${escapingCharacterSequence}u0022`);\n newValue = newValue.replace(/\\'/g, `${escapingCharacterSequence}u0027`);\n\n reconstruction.push(newValue);\n sizeDiff += newValue.length - localizedElement.size;\n break;\n }\n\n case 'dynamic': {\n const dynamicElement: IDynamicReconstructionElement = element as IDynamicReconstructionElement;\n const newValue: string = dynamicElement.valueFn(locale, dynamicElement.token);\n reconstruction.push(newValue);\n sizeDiff += newValue.length - dynamicElement.size;\n break;\n }\n }\n }\n\n const newAssetSource: string = reconstruction.join('');\n localizedResults.set(locale, {\n source: newAssetSource,\n size: initialSize + sizeDiff\n });\n }\n\n return {\n issues,\n result: localizedResults\n };\n }\n\n private static _reconstructNonLocalized(\n reconstructionSeries: IReconstructionElement[],\n initialSize: number,\n noStringsLocaleName: string\n ): INonLocalizedReconstructionResult {\n const issues: string[] = [];\n\n const reconstruction: string[] = [];\n\n let sizeDiff: number = 0;\n for (const element of reconstructionSeries) {\n switch (element.kind) {\n case 'static': {\n reconstruction.push((element as IStaticReconstructionElement).staticString);\n break;\n }\n\n case 'localized': {\n const localizedElement: ILocalizedReconstructionElement =\n element as ILocalizedReconstructionElement;\n issues.push(\n `The string \"${localizedElement.stringName}\" in \"${localizedElement.locFilePath}\" appeared in an asset ` +\n 'that is not expected to contain localized resources.'\n );\n\n const newValue: string = '-- NOT EXPECTED TO BE LOCALIZED --';\n reconstruction.push(newValue);\n sizeDiff += newValue.length - localizedElement.size;\n break;\n }\n\n case 'dynamic': {\n const dynamicElement: IDynamicReconstructionElement = element as IDynamicReconstructionElement;\n const newValue: string = dynamicElement.valueFn(noStringsLocaleName, dynamicElement.token);\n reconstruction.push(newValue);\n sizeDiff += newValue.length - dynamicElement.size;\n break;\n }\n }\n }\n\n const newAssetSource: string = reconstruction.join('');\n return {\n issues,\n result: {\n source: newAssetSource,\n size: initialSize + sizeDiff\n }\n };\n }\n\n private static _parseStringToReconstructionSequence(\n plugin: LocalizationPlugin,\n source: string,\n jsonpFunction: (locale: string, chunkIdToken: string | undefined) => string\n ): IParseResult {\n const issues: string[] = [];\n const reconstructionSeries: IReconstructionElement[] = [];\n\n let lastIndex: number = 0;\n let regexResult: RegExpExecArray | null;\n while ((regexResult = PLACEHOLDER_REGEX.exec(source))) {\n const staticElement: IStaticReconstructionElement = {\n kind: 'static',\n staticString: source.substring(lastIndex, regexResult.index)\n };\n reconstructionSeries.push(staticElement);\n\n const [placeholder, escapedBackslash, elementLabel, token, placeholderSerialNumber] = regexResult;\n\n let localizedReconstructionElement: IReconstructionElement;\n switch (elementLabel) {\n case Constants.STRING_PLACEHOLDER_LABEL: {\n const stringData: IStringData | undefined = plugin.getDataForSerialNumber(placeholderSerialNumber);\n if (!stringData) {\n issues.push(`Missing placeholder ${placeholder}`);\n const brokenLocalizedElement: IStaticReconstructionElement = {\n kind: 'static',\n staticString: placeholder\n };\n localizedReconstructionElement = brokenLocalizedElement;\n } else {\n const localizedElement: ILocalizedReconstructionElement = {\n kind: 'localized',\n values: stringData.values,\n size: placeholder.length,\n locFilePath: stringData.locFilePath,\n escapedBackslash: escapedBackslash,\n stringName: stringData.stringName\n };\n localizedReconstructionElement = localizedElement;\n }\n break;\n }\n\n case Constants.LOCALE_NAME_PLACEHOLDER_LABEL: {\n const dynamicElement: IDynamicReconstructionElement = {\n kind: 'dynamic',\n valueFn: (locale: string) => locale,\n size: placeholder.length,\n escapedBackslash: escapedBackslash\n };\n localizedReconstructionElement = dynamicElement;\n break;\n }\n\n case Constants.JSONP_PLACEHOLDER_LABEL: {\n const dynamicElement: IDynamicReconstructionElement = {\n kind: 'dynamic',\n valueFn: jsonpFunction,\n size: placeholder.length,\n escapedBackslash: escapedBackslash,\n token: token.substring(1, token.length - 1)\n };\n localizedReconstructionElement = dynamicElement;\n break;\n }\n\n default: {\n throw new Error(`Unexpected label ${elementLabel}`);\n }\n }\n\n reconstructionSeries.push(localizedReconstructionElement);\n lastIndex = regexResult.index + placeholder.length;\n }\n\n const lastElement: IStaticReconstructionElement = {\n kind: 'static',\n staticString: source.substr(lastIndex)\n };\n reconstructionSeries.push(lastElement);\n\n return {\n issues,\n reconstructionSeries\n };\n }\n\n private static _getJsonpFunction(\n chunk: Webpack.compilation.Chunk,\n chunkHasLocalizedModules: (chunk: Webpack.compilation.Chunk) => boolean,\n noStringsLocaleName: string\n ): (locale: string, chunkIdToken: string | undefined) => string {\n const idsWithStrings: Set<number | string> = new Set<number | string>();\n const idsWithoutStrings: Set<number | string> = new Set<number | string>();\n\n const asyncChunks: Set<Webpack.compilation.Chunk> = chunk.getAllAsyncChunks();\n for (const asyncChunk of asyncChunks) {\n const chunkId: number | string | null = asyncChunk.id;\n\n if (chunkId === null || chunkId === undefined) {\n throw new Error(`Chunk \"${asyncChunk.name}\"'s ID is null or undefined.`);\n }\n\n if (chunkHasLocalizedModules(asyncChunk)) {\n idsWithStrings.add(chunkId);\n } else {\n idsWithoutStrings.add(chunkId);\n }\n }\n\n if (idsWithStrings.size === 0) {\n return () => JSON.stringify(noStringsLocaleName);\n } else if (idsWithoutStrings.size === 0) {\n return (locale: string) => JSON.stringify(locale);\n } else {\n // Generate an array [<locale>, <nostrings locale>] and an object that is used as an indexer into that\n // object that maps chunk IDs to 0s for chunks with localized strings and 1s for chunks without localized\n // strings\n //\n // This can be improved in the future. We can maybe sort the chunks such that the chunks below a certain ID\n // number are localized and the those above are not.\n const chunkMapping: { [chunkId: string]: number } = {};\n for (const idWithStrings of idsWithStrings) {\n chunkMapping[idWithStrings] = 0;\n }\n\n for (const idWithoutStrings of idsWithoutStrings) {\n chunkMapping[idWithoutStrings] = 1;\n }\n\n return (locale: string, chunkIdToken: string | undefined) => {\n if (!locale) {\n throw new Error('Missing locale name.');\n }\n\n return `(${JSON.stringify([locale, noStringsLocaleName])})[${JSON.stringify(\n chunkMapping\n )}[${chunkIdToken}]]`;\n };\n }\n }\n}\n"]}