@angular/build 22.2.0-next.3 → 22.2.0-next.5

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 (110) hide show
  1. package/package.json +10 -10
  2. package/src/builders/application/chunk-optimizer.d.ts +2 -2
  3. package/src/builders/application/chunk-optimizer.js +5 -5
  4. package/src/builders/application/chunk-optimizer.js.map +1 -1
  5. package/src/builders/application/execute-build.js +42 -17
  6. package/src/builders/application/execute-build.js.map +1 -1
  7. package/src/builders/application/execute-post-bundle.d.ts +2 -2
  8. package/src/builders/application/execute-post-bundle.js +4 -4
  9. package/src/builders/application/execute-post-bundle.js.map +1 -1
  10. package/src/builders/application/i18n.js +35 -2
  11. package/src/builders/application/i18n.js.map +1 -1
  12. package/src/builders/application/options.d.ts +14 -0
  13. package/src/builders/application/options.js +2 -1
  14. package/src/builders/application/options.js.map +1 -1
  15. package/src/builders/application/setup-bundling.js +3 -1
  16. package/src/builders/application/setup-bundling.js.map +1 -1
  17. package/src/builders/unit-test/runners/vitest/build-options.js +6 -0
  18. package/src/builders/unit-test/runners/vitest/build-options.js.map +1 -1
  19. package/src/tools/angular/angular-host.d.ts +1 -2
  20. package/src/tools/angular/angular-host.js +3 -3
  21. package/src/tools/angular/angular-host.js.map +1 -1
  22. package/src/tools/angular/compilation/angular-compilation.d.ts +23 -10
  23. package/src/tools/angular/compilation/angular-compilation.js +11 -1
  24. package/src/tools/angular/compilation/angular-compilation.js.map +1 -1
  25. package/src/tools/angular/compilation/aot-compilation.d.ts +4 -10
  26. package/src/tools/angular/compilation/aot-compilation.js +23 -14
  27. package/src/tools/angular/compilation/aot-compilation.js.map +1 -1
  28. package/src/tools/angular/compilation/factory.d.ts +5 -3
  29. package/src/tools/angular/compilation/factory.js +10 -5
  30. package/src/tools/angular/compilation/factory.js.map +1 -1
  31. package/src/tools/angular/compilation/index.d.ts +2 -2
  32. package/src/tools/angular/compilation/index.js.map +1 -1
  33. package/src/tools/angular/compilation/jit-compilation.d.ts +4 -7
  34. package/src/tools/angular/compilation/jit-compilation.js +14 -11
  35. package/src/tools/angular/compilation/jit-compilation.js.map +1 -1
  36. package/src/tools/angular/compilation/noop-compilation.d.ts +3 -8
  37. package/src/tools/angular/compilation/noop-compilation.js +1 -1
  38. package/src/tools/angular/compilation/noop-compilation.js.map +1 -1
  39. package/src/tools/angular/compilation/parallel-compilation.d.ts +2 -8
  40. package/src/tools/angular/compilation/parallel-compilation.js +43 -19
  41. package/src/tools/angular/compilation/parallel-compilation.js.map +1 -1
  42. package/src/tools/angular/compilation/parallel-worker.d.ts +3 -15
  43. package/src/tools/angular/compilation/parallel-worker.js +94 -66
  44. package/src/tools/angular/compilation/parallel-worker.js.map +1 -1
  45. package/src/tools/angular/linker/oxc-linker.d.ts +13 -17
  46. package/src/tools/angular/linker/oxc-linker.js +27 -89
  47. package/src/tools/angular/linker/oxc-linker.js.map +1 -1
  48. package/src/tools/esbuild/angular/compiler-plugin.js +51 -21
  49. package/src/tools/esbuild/angular/compiler-plugin.js.map +1 -1
  50. package/src/tools/esbuild/angular/component-stylesheets.d.ts +3 -3
  51. package/src/tools/esbuild/angular/component-stylesheets.js +43 -15
  52. package/src/tools/esbuild/angular/component-stylesheets.js.map +1 -1
  53. package/src/tools/esbuild/angular/source-file-cache.d.ts +1 -2
  54. package/src/tools/esbuild/angular/source-file-cache.js +1 -11
  55. package/src/tools/esbuild/angular/source-file-cache.js.map +1 -1
  56. package/src/tools/esbuild/application-code-bundle.js +10 -9
  57. package/src/tools/esbuild/application-code-bundle.js.map +1 -1
  58. package/src/tools/esbuild/budget-stats.js +3 -3
  59. package/src/tools/esbuild/budget-stats.js.map +1 -1
  60. package/src/tools/esbuild/bundler-context.d.ts +23 -7
  61. package/src/tools/esbuild/bundler-context.js +108 -42
  62. package/src/tools/esbuild/bundler-context.js.map +1 -1
  63. package/src/tools/esbuild/cache.d.ts +10 -0
  64. package/src/tools/esbuild/cache.js +18 -0
  65. package/src/tools/esbuild/cache.js.map +1 -1
  66. package/src/tools/esbuild/i18n-inliner-worker.d.ts +59 -6
  67. package/src/tools/esbuild/i18n-inliner-worker.js +252 -71
  68. package/src/tools/esbuild/i18n-inliner-worker.js.map +1 -1
  69. package/src/tools/esbuild/i18n-inliner.d.ts +39 -5
  70. package/src/tools/esbuild/i18n-inliner.js +209 -83
  71. package/src/tools/esbuild/i18n-inliner.js.map +1 -1
  72. package/src/tools/esbuild/i18n-locale-plugin.d.ts +32 -0
  73. package/src/tools/esbuild/i18n-locale-plugin.js +112 -103
  74. package/src/tools/esbuild/i18n-locale-plugin.js.map +1 -1
  75. package/src/tools/esbuild/i18n-translation-encoder.d.ts +20 -0
  76. package/src/tools/esbuild/i18n-translation-encoder.js +92 -0
  77. package/src/tools/esbuild/i18n-translation-encoder.js.map +1 -0
  78. package/src/tools/esbuild/i18n-translation-reader.d.ts +40 -0
  79. package/src/tools/esbuild/i18n-translation-reader.js +164 -0
  80. package/src/tools/esbuild/i18n-translation-reader.js.map +1 -0
  81. package/src/tools/esbuild/javascript-transformer-worker.js +36 -46
  82. package/src/tools/esbuild/javascript-transformer-worker.js.map +1 -1
  83. package/src/tools/esbuild/license-extractor.d.ts +1 -1
  84. package/src/tools/esbuild/license-extractor.js +89 -86
  85. package/src/tools/esbuild/license-extractor.js.map +1 -1
  86. package/src/tools/esbuild/load-result-cache.d.ts +1 -0
  87. package/src/tools/esbuild/load-result-cache.js +24 -11
  88. package/src/tools/esbuild/load-result-cache.js.map +1 -1
  89. package/src/tools/esbuild/utils.d.ts +2 -2
  90. package/src/tools/esbuild/utils.js +9 -6
  91. package/src/tools/esbuild/utils.js.map +1 -1
  92. package/src/tools/oxc/oxc-transform.d.ts +3 -0
  93. package/src/tools/oxc/oxc-transform.js +53 -32
  94. package/src/tools/oxc/oxc-transform.js.map +1 -1
  95. package/src/utils/i18n-options.d.ts +1 -0
  96. package/src/utils/i18n-options.js.map +1 -1
  97. package/src/utils/index-file/auto-csp.js +36 -17
  98. package/src/utils/index-file/auto-csp.js.map +1 -1
  99. package/src/utils/normalize-cache.js +1 -1
  100. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +1 -1
  101. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +12 -9
  102. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js.map +1 -1
  103. package/src/utils/server-rendering/esm-in-memory-loader/utils.d.ts +8 -0
  104. package/src/utils/server-rendering/esm-in-memory-loader/utils.js +30 -0
  105. package/src/utils/server-rendering/esm-in-memory-loader/utils.js.map +1 -1
  106. package/src/utils/server-rendering/prerender.js +70 -30
  107. package/src/utils/server-rendering/prerender.js.map +1 -1
  108. package/src/utils/server-rendering/render-worker.d.ts +7 -4
  109. package/src/utils/server-rendering/render-worker.js +29 -7
  110. package/src/utils/server-rendering/render-worker.js.map +1 -1
@@ -20,10 +20,10 @@ interface InlineFileRequest {
20
20
  locale: string;
21
21
  /**
22
22
  * The serialized translation messages for the locale that should be used during the inlining
23
- * process of the file. A Blob is used so that the messages are shared with the Worker by
24
- * reference instead of being copied into it for every request.
23
+ * process of the file. A SharedArrayBuffer or Blob is used so that the messages are shared with
24
+ * the Worker by reference instead of being copied into it for every request.
25
25
  */
26
- translation?: Blob;
26
+ translation?: Blob | SharedArrayBuffer;
27
27
  }
28
28
  /**
29
29
  * The options passed to the inliner for each code request
@@ -43,10 +43,56 @@ interface InlineCodeRequest {
43
43
  locale: string;
44
44
  /**
45
45
  * The serialized translation messages for the locale that should be used during the inlining
46
- * process of the file. A Blob is used so that the messages are shared with the Worker by
47
- * reference instead of being copied into it for every request.
46
+ * process of the file. A SharedArrayBuffer or Blob is used so that the messages are shared with
47
+ * the Worker by reference instead of being copied into it for every request.
48
48
  */
49
- translation?: Blob;
49
+ translation?: Blob | SharedArrayBuffer;
50
+ }
51
+ /**
52
+ * The options passed to the inliner for a batch file request
53
+ */
54
+ interface InlineFileBatchRequest {
55
+ /**
56
+ * The filename that should be processed. The data for the file is provided to the Worker
57
+ * during Worker initialization.
58
+ */
59
+ filename: string;
60
+ /**
61
+ * The locale specifiers or locale objects that should be used during the inlining process of the file.
62
+ */
63
+ locales: (string | {
64
+ locale: string;
65
+ translation?: Blob | SharedArrayBuffer;
66
+ })[];
67
+ /**
68
+ * Whether the file data should be treated as ephemeral and not cached long-term in the Worker.
69
+ * Typically true when all remaining locales for the file are processed in a single batch.
70
+ */
71
+ ephemeral?: boolean;
72
+ /**
73
+ * The list of active locales in the current inlining window. Any cached translation dictionaries
74
+ * not present in this list will be evicted from the Worker's memory cache.
75
+ */
76
+ activeLocales?: string[];
77
+ }
78
+ /**
79
+ * The result for a single locale within a batch file request.
80
+ */
81
+ interface InlineLocaleResult {
82
+ locale: string;
83
+ code: string;
84
+ map?: string;
85
+ messages: {
86
+ type: 'error' | 'warning';
87
+ message: string;
88
+ }[];
89
+ }
90
+ /**
91
+ * The response returned from a batch file request.
92
+ */
93
+ interface InlineFileBatchResult {
94
+ file: string;
95
+ results: InlineLocaleResult[];
50
96
  }
51
97
  /**
52
98
  * Inlines the provided locale and translation into a JavaScript file that contains `$localize` usage.
@@ -64,6 +110,13 @@ export default function inlineFile(request: InlineFileRequest): Promise<{
64
110
  message: string;
65
111
  }[];
66
112
  }>;
113
+ /**
114
+ * Inlines multiple locales and translations into a JavaScript file that contains `$localize` usage.
115
+ *
116
+ * @param request An InlineFileBatchRequest object representing the options for inlining.
117
+ * @returns An object containing the inlined results for each requested locale.
118
+ */
119
+ export declare function inlineFileBatch(request: InlineFileBatchRequest): Promise<InlineFileBatchResult>;
67
120
  /**
68
121
  * Inlines the provided locale and translation into JavaScript code that contains `$localize` usage.
69
122
  * This function is a secondary entry primarily for use with component HMR update modules.
@@ -44,6 +44,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.default = inlineFile;
47
+ exports.inlineFileBatch = inlineFileBatch;
47
48
  exports.inlineCode = inlineCode;
48
49
  const remapping_1 = __importDefault(require("@ampproject/remapping"));
49
50
  const magic_string_1 = require("magic-string");
@@ -51,36 +52,77 @@ const node_assert_1 = __importDefault(require("node:assert"));
51
52
  const node_v8_1 = require("node:v8");
52
53
  const node_worker_threads_1 = require("node:worker_threads");
53
54
  const oxc_parser_1 = require("oxc-parser");
55
+ const i18n_locale_plugin_1 = require("./i18n-locale-plugin");
56
+ const i18n_translation_reader_1 = require("./i18n-translation-reader");
54
57
  // Extract the application files and common options used for inline requests from the Worker context
55
- const { files, missingTranslation, shouldOptimize } = (node_worker_threads_1.workerData || {});
58
+ const { files, missingTranslation, translations } = (node_worker_threads_1.workerData || {});
56
59
  /**
57
- * The translation messages deserialized for the locale most recently requested of this Worker.
58
- * Locales are inlined one at a time, so retaining only the active locale is enough to avoid
59
- * deserializing the messages once per file while holding at most one set of messages in memory.
60
+ * Cache of file data promises keyed by filename.
60
61
  */
61
- let activeTranslation;
62
+ const fileDataCache = new Map();
62
63
  /**
63
- * Deserializes the translation messages for an inline request, reusing the result for any
64
+ * Cache of deserialized translation messages keyed by locale.
65
+ */
66
+ const deserializedTranslations = new Map();
67
+ /**
68
+ * Retrieves the file data for a filename, loading and extracting localization metadata.
69
+ * If `cache` is true, the result is cached in `fileDataCache` across requests in this Worker.
70
+ * If `cache` is false (ephemeral), the result is not retained in `fileDataCache`, allowing it
71
+ * to be garbage-collected once the batch request finishes.
72
+ *
73
+ * @param filename The name of the file to load.
74
+ * @param cache Whether to cache the loaded file data in the Worker's long-term cache.
75
+ * @returns The cached or newly extracted code and localization metadata.
76
+ */
77
+ function loadFileData(filename, cache = true) {
78
+ const existing = fileDataCache.get(filename);
79
+ if (existing) {
80
+ return existing;
81
+ }
82
+ const fileDataPromise = (async () => {
83
+ const data = files.get(filename);
84
+ (0, node_assert_1.default)(data !== undefined, `Invalid inline request for file '${filename}'.`);
85
+ const code = await data.text();
86
+ const metadata = extractLocalizeMetadata(filename, code);
87
+ return { code, metadata };
88
+ })();
89
+ if (cache) {
90
+ fileDataPromise.catch(() => {
91
+ fileDataCache.delete(filename);
92
+ });
93
+ fileDataCache.set(filename, fileDataPromise);
94
+ }
95
+ return fileDataPromise;
96
+ }
97
+ /**
98
+ * Deserializes or wraps the translation messages for a locale, reusing the result for any
64
99
  * subsequent request that targets the same locale.
65
- * @param request An inline request containing the locale and its serialized messages.
100
+ * @param locale The locale identifier.
101
+ * @param translation Optional serialized translation messages (SharedArrayBuffer or Blob).
66
102
  * @returns The translation messages, or undefined if the locale has no translations.
67
103
  */
68
- function loadTranslation(request) {
69
- const { locale, translation } = request;
70
- if (!translation) {
104
+ function loadTranslation(locale, translation) {
105
+ const translationData = translation ?? translations?.get(locale);
106
+ if (!translationData) {
71
107
  return undefined;
72
108
  }
73
- if (activeTranslation?.locale !== locale) {
74
- activeTranslation = {
75
- locale,
76
- // Deserializing within the stored promise ensures that concurrent requests for a locale
77
- // share the one deserialization instead of each performing their own.
78
- messages: translation
109
+ let messagesPromise = deserializedTranslations.get(locale);
110
+ if (!messagesPromise) {
111
+ if (translationData instanceof Blob) {
112
+ messagesPromise = translationData
79
113
  .arrayBuffer()
80
- .then((buffer) => (0, node_v8_1.deserialize)(new Uint8Array(buffer))),
81
- };
114
+ .then((buffer) => (0, node_v8_1.deserialize)(new Uint8Array(buffer)))
115
+ .catch((error) => {
116
+ deserializedTranslations.delete(locale);
117
+ throw error;
118
+ });
119
+ }
120
+ else {
121
+ messagesPromise = Promise.resolve((0, i18n_translation_reader_1.createSharedTranslationProxy)(translationData));
122
+ }
123
+ deserializedTranslations.set(locale, messagesPromise);
82
124
  }
83
- return activeTranslation.messages;
125
+ return messagesPromise;
84
126
  }
85
127
  /**
86
128
  * Inlines the provided locale and translation into a JavaScript file that contains `$localize` usage.
@@ -90,11 +132,12 @@ function loadTranslation(request) {
90
132
  * @returns An object containing the inlined file and optional map content.
91
133
  */
92
134
  async function inlineFile(request) {
93
- const data = files.get(request.filename);
94
- (0, node_assert_1.default)(data !== undefined, `Invalid inline request for file '${request.filename}'.`);
95
- const code = await data.text();
96
- const map = await files.get(request.filename + '.map')?.text();
97
- const result = await transformWithOxc(code, map && JSON.parse(map), request, await loadTranslation(request));
135
+ const { code, metadata } = await loadFileData(request.filename, true);
136
+ // Sourcemaps are parsed on demand per request rather than cached long-term to prevent
137
+ // monotonic memory growth as a worker processes multiple files across the build.
138
+ const rawMap = await files.get(request.filename + '.map')?.text();
139
+ const map = rawMap ? JSON.parse(rawMap) : undefined;
140
+ const result = await inlineLocalize(code, map, metadata, request.locale, await loadTranslation(request.locale, request.translation), request.filename);
98
141
  return {
99
142
  file: request.filename,
100
143
  code: result.code,
@@ -102,6 +145,42 @@ async function inlineFile(request) {
102
145
  messages: result.diagnostics.messages,
103
146
  };
104
147
  }
148
+ /**
149
+ * Inlines multiple locales and translations into a JavaScript file that contains `$localize` usage.
150
+ *
151
+ * @param request An InlineFileBatchRequest object representing the options for inlining.
152
+ * @returns An object containing the inlined results for each requested locale.
153
+ */
154
+ async function inlineFileBatch(request) {
155
+ if (request.activeLocales) {
156
+ const activeSet = new Set(request.activeLocales);
157
+ for (const locale of deserializedTranslations.keys()) {
158
+ if (!activeSet.has(locale)) {
159
+ deserializedTranslations.delete(locale);
160
+ }
161
+ }
162
+ }
163
+ const { code, metadata } = await loadFileData(request.filename, !request.ephemeral);
164
+ // Parse the sourcemap once for the entire batch.
165
+ // It will naturally be garbage-collected after this batch action returns.
166
+ const rawMap = await files.get(request.filename + '.map')?.text();
167
+ const map = rawMap ? JSON.parse(rawMap) : undefined;
168
+ const results = await Promise.all(request.locales.map(async (entry) => {
169
+ const locale = typeof entry === 'string' ? entry : entry.locale;
170
+ const translation = typeof entry === 'string' ? undefined : entry.translation;
171
+ const result = await inlineLocalize(code, map, metadata, locale, await loadTranslation(locale, translation), request.filename);
172
+ return {
173
+ locale,
174
+ code: result.code,
175
+ map: result.map,
176
+ messages: result.diagnostics.messages,
177
+ };
178
+ }));
179
+ return {
180
+ file: request.filename,
181
+ results,
182
+ };
183
+ }
105
184
  /**
106
185
  * Inlines the provided locale and translation into JavaScript code that contains `$localize` usage.
107
186
  * This function is a secondary entry primarily for use with component HMR update modules.
@@ -110,7 +189,8 @@ async function inlineFile(request) {
110
189
  * @returns An object containing the inlined code.
111
190
  */
112
191
  async function inlineCode(request) {
113
- const result = await transformWithOxc(request.code, undefined, request, await loadTranslation(request));
192
+ const metadata = extractLocalizeMetadata(request.filename, request.code);
193
+ const result = await inlineLocalize(request.code, undefined, metadata, request.locale, await loadTranslation(request.locale, request.translation), request.filename);
114
194
  return {
115
195
  output: result.code,
116
196
  messages: result.diagnostics.messages,
@@ -134,63 +214,164 @@ async function loadLocalizeTools() {
134
214
  return localizeToolsModule;
135
215
  }
136
216
  /**
137
- * Transforms a JavaScript file using OXC and Magic-String to inline the request locale and translation.
138
- * @param code A string containing the JavaScript code to transform.
139
- * @param map A sourcemap object for the provided JavaScript code.
140
- * @param options The inline request options to use.
141
- * @param translation The translation messages to inline, or undefined for an untranslated locale.
142
- * @returns An object containing the code, map, and diagnostics from the transformation.
217
+ * Traverses ESTree AST nodes in post-order (bottom-up) without recursion.
218
+ * Bottom-up traversal ensures that nested `$localize` expressions are transformed and
219
+ * written to MagicString before outer containing templates are evaluated.
220
+ *
221
+ * @param root The root AST node to traverse.
222
+ * @param onExit Callback invoked on each AST node in post-order.
143
223
  */
144
- async function transformWithOxc(code, map, options, translation) {
145
- const { program } = (0, oxc_parser_1.parseSync)(options.filename, code, {
224
+ function walkAstPostOrder(root, onExit) {
225
+ const traverseStack = [root];
226
+ const postOrderNodes = [];
227
+ while (traverseStack.length > 0) {
228
+ const current = traverseStack.pop();
229
+ if (!current) {
230
+ continue;
231
+ }
232
+ postOrderNodes.push(current);
233
+ const keys = oxc_parser_1.visitorKeys[current.type];
234
+ if (!keys) {
235
+ continue;
236
+ }
237
+ for (let i = 0; i < keys.length; i++) {
238
+ const child = current[keys[i]];
239
+ if (!child) {
240
+ continue;
241
+ }
242
+ if (Array.isArray(child)) {
243
+ for (const item of child) {
244
+ if (item) {
245
+ traverseStack.push(item);
246
+ }
247
+ }
248
+ }
249
+ else {
250
+ traverseStack.push(child);
251
+ }
252
+ }
253
+ }
254
+ // Process collected nodes in reverse order to achieve bottom-up (post-order) traversal
255
+ for (let i = postOrderNodes.length - 1; i >= 0; i--) {
256
+ onExit(postOrderNodes[i]);
257
+ }
258
+ }
259
+ /**
260
+ * Extracts localization call sites and locale insertion points from JavaScript code using OXC.
261
+ *
262
+ * @param filename The name of the file being processed.
263
+ * @param code The JavaScript source code.
264
+ * @returns The extracted localization metadata.
265
+ */
266
+ function extractLocalizeMetadata(filename, code) {
267
+ const { program } = (0, oxc_parser_1.parseSync)(filename, code, {
146
268
  sourceType: 'unambiguous',
147
269
  });
148
270
  if (!program) {
149
- throw new Error(`Unknown error occurred parsing file "${options.filename}" with OXC.`);
271
+ throw new Error(`Unknown error occurred parsing file "${filename}" with OXC.`);
150
272
  }
151
- const magicString = new magic_string_1.MagicString(code);
152
- const { Diagnostics, translate } = await loadLocalizeTools();
153
- const diagnostics = new Diagnostics();
154
- const visitor = new oxc_parser_1.Visitor({
155
- Literal(node) {
273
+ const callSites = [];
274
+ const localeInsertSites = [];
275
+ let diagnostics;
276
+ walkAstPostOrder(program, (node) => {
277
+ if (node.type === 'Literal') {
156
278
  if (typeof node.value === 'string' && node.value === '___NG_LOCALE_INSERT___') {
157
- magicString.overwrite(node.start, node.end, JSON.stringify(options.locale));
279
+ localeInsertSites.push({ start: node.start, end: node.end });
158
280
  }
159
- },
160
- 'TaggedTemplateExpression:exit'(node) {
281
+ }
282
+ else if (node.type === 'TaggedTemplateExpression') {
161
283
  if (node.tag.type === 'Identifier' && node.tag.name === '$localize') {
162
- const cooked = node.quasi.quasis.map((q) => q.value.cooked);
163
- const raw = node.quasi.quasis.map((q) => q.value.raw);
164
- const messageParts = Object.assign(cooked, { raw });
165
- const [translatedParts, translatedSubstitutions] = translate(diagnostics, translation || {}, messageParts, node.quasi.expressions.map((_, index) => index), translation === undefined ? 'ignore' : missingTranslation);
166
- // Reconstruct the new template/string literal replacement
167
- let replacement;
168
- if (translatedSubstitutions.length === 0) {
169
- replacement = JSON.stringify(translatedParts[0]);
170
- }
171
- else {
172
- replacement = '`';
173
- for (let i = 0; i < translatedParts.length; i++) {
174
- const escapedPart = JSON.stringify(translatedParts[i])
175
- .slice(1, -1)
176
- .replace(/\\"/g, '"')
177
- .replace(/`/g, '\\`')
178
- .replace(/\$\{/g, '\\${');
179
- replacement += escapedPart;
180
- if (i < translatedSubstitutions.length) {
181
- const originalIndex = translatedSubstitutions[i];
182
- const exprNode = node.quasi.expressions[originalIndex];
183
- const exprCode = magicString.slice(exprNode.start, exprNode.end);
184
- replacement += '${' + exprCode + '}';
185
- }
284
+ const cooked = [];
285
+ const raw = [];
286
+ let hasMalformedEscape = false;
287
+ for (const q of node.quasi.quasis) {
288
+ if (q.value.cooked === null || q.value.cooked === undefined) {
289
+ hasMalformedEscape = true;
290
+ (diagnostics ??= []).push(`Malformed escape sequence in $localize template literal in file "${filename}".`);
291
+ break;
186
292
  }
187
- replacement += '`';
293
+ cooked.push(q.value.cooked);
294
+ raw.push(q.value.raw);
295
+ }
296
+ if (!hasMalformedEscape) {
297
+ const messageParts = Object.assign(cooked, { raw });
298
+ const expressions = node.quasi.expressions.map((expr) => ({
299
+ start: expr.start,
300
+ end: expr.end,
301
+ }));
302
+ callSites.push({
303
+ start: node.start,
304
+ end: node.end,
305
+ messageParts,
306
+ expressions,
307
+ });
188
308
  }
189
- magicString.overwrite(node.start, node.end, replacement);
190
309
  }
191
- },
310
+ }
192
311
  });
193
- visitor.visit(program);
312
+ return { callSites, localeInsertSites, diagnostics };
313
+ }
314
+ /**
315
+ * Inlines translations into code using previously extracted localization metadata.
316
+ *
317
+ * @param code The source code to transform.
318
+ * @param map Optional source map for the source code.
319
+ * @param metadata Extracted localization metadata.
320
+ * @param locale The target locale identifier.
321
+ * @param translation The translation messages dictionary, or undefined for untranslated locale.
322
+ * @param filename The name of the file being transformed.
323
+ * @returns The transformed code, optional remapped source map, and diagnostics.
324
+ */
325
+ async function inlineLocalize(code, map, metadata, locale, translation, filename) {
326
+ const magicString = new magic_string_1.MagicString(code);
327
+ const { Diagnostics, translate } = await loadLocalizeTools();
328
+ const diagnostics = new Diagnostics();
329
+ if (metadata.diagnostics) {
330
+ for (const message of metadata.diagnostics) {
331
+ diagnostics.error(message);
332
+ }
333
+ }
334
+ if (metadata.localeInsertSites.length > 0) {
335
+ const localeData = await (0, i18n_locale_plugin_1.loadLocaleData)(locale);
336
+ if (localeData.error) {
337
+ diagnostics.error(localeData.error);
338
+ }
339
+ else if (localeData.warning) {
340
+ diagnostics.warn(localeData.warning);
341
+ }
342
+ let injected = false;
343
+ for (const site of metadata.localeInsertSites) {
344
+ magicString.overwrite(site.start, site.end, JSON.stringify(locale) + (localeData.code && !injected ? `;\n${localeData.code}\n;` : ''));
345
+ injected = true;
346
+ }
347
+ }
348
+ for (const callSite of metadata.callSites) {
349
+ const [translatedParts, translatedSubstitutions] = translate(diagnostics, translation || {}, callSite.messageParts, callSite.expressions.map((_, index) => index), translation === undefined ? 'ignore' : missingTranslation);
350
+ // Reconstruct the new template/string literal replacement
351
+ let replacement;
352
+ if (translatedSubstitutions.length === 0) {
353
+ replacement = JSON.stringify(translatedParts[0]);
354
+ }
355
+ else {
356
+ replacement = '`';
357
+ for (let i = 0; i < translatedParts.length; i++) {
358
+ const escapedPart = JSON.stringify(translatedParts[i])
359
+ .slice(1, -1)
360
+ .replace(/\\"/g, '"')
361
+ .replace(/`/g, '\\`')
362
+ .replace(/\$\{/g, '\\${');
363
+ replacement += escapedPart;
364
+ if (i < translatedSubstitutions.length) {
365
+ const originalIndex = translatedSubstitutions[i];
366
+ const expr = callSite.expressions[originalIndex];
367
+ const exprCode = magicString.slice(expr.start, expr.end);
368
+ replacement += '${' + exprCode + '}';
369
+ }
370
+ }
371
+ replacement += '`';
372
+ }
373
+ magicString.overwrite(callSite.start, callSite.end, replacement);
374
+ }
194
375
  const outputCode = magicString.toString();
195
376
  let outputMap;
196
377
  if (map && magicString.hasChanged()) {
@@ -198,7 +379,7 @@ async function transformWithOxc(code, map, options, translation) {
198
379
  // inputs. Encoding the mappings only for remapping to immediately decode them again doubles
199
380
  // the peak memory of the largest structure involved in inlining a file.
200
381
  const rawMap = magicString.generateDecodedMap({
201
- source: options.filename,
382
+ source: filename,
202
383
  includeContent: true,
203
384
  hires: 'boundary',
204
385
  });
@@ -1 +1 @@
1
- {"version":3,"file":"i18n-inliner-worker.js","sourceRoot":"","sources":["i18n-inliner-worker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GH,6BAoBC;AASD,gCAYC;AAnJD,sEAA8F;AAC9F,+CAA2C;AAC3C,8DAAiC;AACjC,qCAAsC;AACtC,6DAAiD;AACjD,2CAAgD;AAoDhD,oGAAoG;AACpG,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,GAAG,CAAC,gCAAU,IAAI,EAAE,CAItE,CAAC;AAEF;;;;GAIG;AACH,IAAI,iBAA6F,CAAC;AAElG;;;;;GAKG;AACH,SAAS,eAAe,CACtB,OAA8C;IAE9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACxC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,iBAAiB,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;QACzC,iBAAiB,GAAG;YAClB,MAAM;YACN,wFAAwF;YACxF,sEAAsE;YACtE,QAAQ,EAAE,WAAW;iBAClB,WAAW,EAAE;iBACb,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,qBAAW,EAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAA4B,CAAC;SACpF,CAAC;IACJ,CAAC;IAED,OAAO,iBAAiB,CAAC,QAAQ,CAAC;AACpC,CAAC;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AAM,EAAE,CAAC;oBACvC,MAAM,aAAa,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAAC;oBACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;oBACjD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;oBACzD,WAAW,IAAI,IAAI,GAAG,QAAQ,GAAG,GAAG,CAAC;gBACvC,CAAC;YACH,CAAC;YACD,WAAW,IAAI,GAAG,CAAC;QACrB,CAAC;QAED,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC1C,IAAI,SAAS,CAAC;IACd,IAAI,GAAG,IAAI,WAAW,CAAC,UAAU,EAAE,EAAE,CAAC;QACpC,2FAA2F;QAC3F,4FAA4F;QAC5F,wEAAwE;QACxE,MAAM,MAAM,GAAG,WAAW,CAAC,kBAAkB,CAAC;YAC5C,MAAM,EAAE,QAAQ;YAChB,cAAc,EAAE,IAAI;YACpB,KAAK,EAAE,UAAU;SAClB,CAAC,CAAC;QACH,SAAS,GAAG,IAAA,mBAAS,EAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,EAA6B,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACjG,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;QAC3C,WAAW;KACZ,CAAC;AACJ,CAAC"}
@@ -14,6 +14,33 @@ export interface I18nInlinerOptions {
14
14
  outputFiles: BuildOutputFile[];
15
15
  shouldOptimize?: boolean;
16
16
  persistentCachePath?: string;
17
+ localizeVersion?: string;
18
+ translations?: ReadonlyMap<string, Blob | SharedArrayBuffer>;
19
+ }
20
+ /**
21
+ * Options for inlining a specific locale.
22
+ */
23
+ export interface LocaleInlineOptions {
24
+ /**
25
+ * The locale specifier string.
26
+ */
27
+ locale: string;
28
+ /**
29
+ * The translation messages for the locale, or undefined for the source/untranslated locale.
30
+ */
31
+ translation?: Record<string, unknown>;
32
+ /**
33
+ * An optional content integrity hash of the translation file(s) for fast cache key calculation.
34
+ */
35
+ translationIntegrity?: string;
36
+ }
37
+ /**
38
+ * Result of inlining for a specific locale.
39
+ */
40
+ export interface LocaleInlineResult {
41
+ outputFiles: BuildOutputFile[];
42
+ errors: string[];
43
+ warnings: string[];
17
44
  }
18
45
  /**
19
46
  * A class that performs i18n translation inlining of JavaScript code.
@@ -25,19 +52,26 @@ export declare class I18nInliner {
25
52
  #private;
26
53
  private readonly options;
27
54
  constructor(options: I18nInlinerOptions, maxThreads?: number);
55
+ /**
56
+ * Performs inlining of translations across multiple locales in parallel.
57
+ *
58
+ * An adaptive 2D task-partitioning algorithm distributes (files x locales) work units
59
+ * across all worker threads while caching AST metadata and sourcemaps in worker memory.
60
+ *
61
+ * @param locales The locales and translations to inline.
62
+ * @returns A map of locale names to their inlined output files and diagnostics.
63
+ */
64
+ inlineAll(locales: Iterable<LocaleInlineOptions>): Promise<Map<string, LocaleInlineResult>>;
28
65
  /**
29
66
  * Performs inlining of translations for the provided locale and translations. The files that
30
67
  * are processed originate from the files passed to the class constructor and filter by presence
31
68
  * of the localize function keyword.
32
69
  * @param locale The string representing the locale to inline.
33
70
  * @param translation The translation messages to use when inlining.
71
+ * @param translationIntegrity An optional integrity value for the translation messages to use for caching.
34
72
  * @returns A promise that resolves to an array of OutputFiles representing a translated result.
35
73
  */
36
- inlineForLocale(locale: string, translation: Record<string, unknown> | undefined): Promise<{
37
- outputFiles: BuildOutputFile[];
38
- errors: string[];
39
- warnings: string[];
40
- }>;
74
+ inlineForLocale(locale: string, translation: Record<string, unknown> | undefined, translationIntegrity?: string): Promise<LocaleInlineResult>;
41
75
  inlineTemplateUpdate(locale: string, translation: Record<string, unknown> | undefined, templateCode: string, templateId: string): Promise<{
42
76
  code: string;
43
77
  errors: string[];