@angular/build 22.2.0-next.4 → 22.2.0-next.6
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/package.json +13 -12
- package/src/builders/application/build-action.js +47 -39
- package/src/builders/application/build-action.js.map +1 -1
- package/src/builders/application/execute-build.js +1 -1
- package/src/builders/application/execute-build.js.map +1 -1
- package/src/builders/application/execute-post-bundle.js +2 -5
- package/src/builders/application/execute-post-bundle.js.map +1 -1
- package/src/builders/application/i18n.js +20 -10
- package/src/builders/application/i18n.js.map +1 -1
- package/src/builders/application/index.js +2 -2
- package/src/builders/application/index.js.map +1 -1
- package/src/builders/application/results.d.ts +3 -2
- package/src/builders/application/setup-bundling.js +3 -1
- package/src/builders/application/setup-bundling.js.map +1 -1
- package/src/builders/dev-server/vite/index.js +4 -7
- package/src/builders/dev-server/vite/index.js.map +1 -1
- package/src/builders/dev-server/vite/server.js +1 -1
- package/src/builders/dev-server/vite/server.js.map +1 -1
- package/src/builders/dev-server/vite/utils.d.ts +1 -1
- package/src/builders/dev-server/vite/utils.js +9 -4
- package/src/builders/dev-server/vite/utils.js.map +1 -1
- package/src/builders/extract-i18n/application-extraction.js +6 -5
- package/src/builders/extract-i18n/application-extraction.js.map +1 -1
- package/src/builders/karma/application_builder.js +1 -1
- package/src/builders/karma/application_builder.js.map +1 -1
- package/src/builders/karma/assets-middleware.d.ts +2 -2
- package/src/builders/karma/assets-middleware.js +5 -2
- package/src/builders/karma/assets-middleware.js.map +1 -1
- package/src/builders/karma/progress-reporter.js +7 -5
- package/src/builders/karma/progress-reporter.js.map +1 -1
- package/src/builders/karma/utils.d.ts +2 -1
- package/src/builders/karma/utils.js +2 -2
- package/src/builders/karma/utils.js.map +1 -1
- package/src/builders/unit-test/builder.js +1 -1
- package/src/builders/unit-test/options.d.ts +1 -0
- package/src/builders/unit-test/options.js +2 -1
- package/src/builders/unit-test/options.js.map +1 -1
- package/src/builders/unit-test/runners/vitest/build-options.js +5 -6
- package/src/builders/unit-test/runners/vitest/build-options.js.map +1 -1
- package/src/builders/unit-test/runners/vitest/executor.js +4 -4
- package/src/builders/unit-test/runners/vitest/executor.js.map +1 -1
- package/src/builders/unit-test/schema.d.ts +7 -0
- package/src/builders/unit-test/schema.js.map +1 -1
- package/src/builders/unit-test/schema.json +5 -0
- package/src/private.d.ts +1 -1
- package/src/private.js +4 -3
- package/src/private.js.map +1 -1
- package/src/tools/angular/compilation/angular-compilation.d.ts +3 -8
- package/src/tools/angular/compilation/angular-compilation.js +2 -88
- package/src/tools/angular/compilation/angular-compilation.js.map +1 -1
- package/src/tools/angular/compilation/aot-compilation.d.ts +5 -5
- package/src/tools/angular/compilation/aot-compilation.js +9 -13
- package/src/tools/angular/compilation/aot-compilation.js.map +1 -1
- package/src/tools/angular/compilation/compiler-options.d.ts +24 -0
- package/src/tools/angular/compilation/compiler-options.js +135 -0
- package/src/tools/angular/compilation/compiler-options.js.map +1 -0
- package/src/tools/angular/compilation/index.d.ts +1 -1
- package/src/tools/angular/compilation/index.js +1 -3
- package/src/tools/angular/compilation/index.js.map +1 -1
- package/src/tools/angular/compilation/jit-compilation.d.ts +5 -5
- package/src/tools/angular/compilation/jit-compilation.js +8 -15
- package/src/tools/angular/compilation/jit-compilation.js.map +1 -1
- package/src/tools/angular/compilation/parallel-compilation.d.ts +2 -7
- package/src/tools/angular/compilation/parallel-compilation.js +39 -41
- package/src/tools/angular/compilation/parallel-compilation.js.map +1 -1
- package/src/tools/angular/compilation/parallel-worker.d.ts +2 -2
- package/src/tools/angular/compilation/parallel-worker.js +79 -63
- package/src/tools/angular/compilation/parallel-worker.js.map +1 -1
- package/src/tools/angular/compilation/typescript-compilation.d.ts +24 -0
- package/src/tools/angular/compilation/typescript-compilation.js +107 -0
- package/src/tools/angular/compilation/typescript-compilation.js.map +1 -0
- package/src/tools/angular/linker/oxc-linker.d.ts +13 -17
- package/src/tools/angular/linker/oxc-linker.js +27 -89
- package/src/tools/angular/linker/oxc-linker.js.map +1 -1
- package/src/tools/esbuild/angular/compilation-state.d.ts +23 -3
- package/src/tools/esbuild/angular/compilation-state.js +51 -13
- package/src/tools/esbuild/angular/compilation-state.js.map +1 -1
- package/src/tools/esbuild/angular/compiler-plugin.js +36 -101
- package/src/tools/esbuild/angular/compiler-plugin.js.map +1 -1
- package/src/tools/esbuild/angular/component-stylesheets.d.ts +3 -3
- package/src/tools/esbuild/angular/component-stylesheets.js +42 -15
- package/src/tools/esbuild/angular/component-stylesheets.js.map +1 -1
- package/src/tools/esbuild/application-code-bundle.js +5 -9
- package/src/tools/esbuild/application-code-bundle.js.map +1 -1
- package/src/tools/esbuild/bundler-context.d.ts +4 -4
- package/src/tools/esbuild/bundler-context.js +93 -27
- package/src/tools/esbuild/bundler-context.js.map +1 -1
- package/src/tools/esbuild/bundler-execution-result.d.ts +1 -0
- package/src/tools/esbuild/bundler-execution-result.js +2 -2
- package/src/tools/esbuild/bundler-execution-result.js.map +1 -1
- package/src/tools/esbuild/cache.d.ts +10 -0
- package/src/tools/esbuild/cache.js +18 -0
- package/src/tools/esbuild/cache.js.map +1 -1
- package/src/tools/esbuild/i18n-inliner-worker.d.ts +82 -37
- package/src/tools/esbuild/i18n-inliner-worker.js +134 -97
- package/src/tools/esbuild/i18n-inliner-worker.js.map +1 -1
- package/src/tools/esbuild/i18n-inliner.d.ts +42 -11
- package/src/tools/esbuild/i18n-inliner.js +335 -121
- package/src/tools/esbuild/i18n-inliner.js.map +1 -1
- package/src/tools/esbuild/i18n-locale-plugin.d.ts +32 -0
- package/src/tools/esbuild/i18n-locale-plugin.js +112 -103
- package/src/tools/esbuild/i18n-locale-plugin.js.map +1 -1
- package/src/tools/esbuild/i18n-translation-encoder.d.ts +21 -0
- package/src/tools/esbuild/i18n-translation-encoder.js +92 -0
- package/src/tools/esbuild/i18n-translation-encoder.js.map +1 -0
- package/src/tools/esbuild/i18n-translation-reader.d.ts +41 -0
- package/src/tools/esbuild/i18n-translation-reader.js +164 -0
- package/src/tools/esbuild/i18n-translation-reader.js.map +1 -0
- package/src/tools/esbuild/javascript-transformer-worker.js +41 -47
- package/src/tools/esbuild/javascript-transformer-worker.js.map +1 -1
- package/src/tools/esbuild/javascript-transformer.js +53 -1
- package/src/tools/esbuild/javascript-transformer.js.map +1 -1
- package/src/tools/esbuild/load-result-cache.d.ts +1 -0
- package/src/tools/esbuild/load-result-cache.js +24 -11
- package/src/tools/esbuild/load-result-cache.js.map +1 -1
- package/src/tools/esbuild/sqlite-cache-store.d.ts +8 -0
- package/src/tools/esbuild/sqlite-cache-store.js +19 -7
- package/src/tools/esbuild/sqlite-cache-store.js.map +1 -1
- package/src/tools/esbuild/stylesheets/sass-language.js +19 -14
- package/src/tools/esbuild/stylesheets/sass-language.js.map +1 -1
- package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +1 -1
- package/src/tools/esbuild/utils.d.ts +1 -1
- package/src/tools/esbuild/utils.js.map +1 -1
- package/src/tools/oxc/oxc-transform.d.ts +3 -0
- package/src/tools/oxc/oxc-transform.js +103 -124
- package/src/tools/oxc/oxc-transform.js.map +1 -1
- package/src/tools/oxc/traversal.d.ts +32 -0
- package/src/tools/oxc/traversal.js +299 -0
- package/src/tools/oxc/traversal.js.map +1 -0
- package/src/tools/sass/rebasing-importer.d.ts +8 -14
- package/src/tools/sass/rebasing-importer.js +18 -24
- package/src/tools/sass/rebasing-importer.js.map +1 -1
- package/src/tools/sass/sass-service.d.ts +11 -38
- package/src/tools/sass/sass-service.js +124 -187
- package/src/tools/sass/sass-service.js.map +1 -1
- package/src/utils/environment-options.d.ts +12 -0
- package/src/utils/environment-options.js +20 -12
- package/src/utils/environment-options.js.map +1 -1
- package/src/utils/i18n-options.d.ts +2 -1
- package/src/utils/i18n-options.js.map +1 -1
- package/src/utils/normalize-cache.d.ts +11 -1
- package/src/utils/normalize-cache.js +6 -3
- package/src/utils/normalize-cache.js.map +1 -1
- package/src/utils/purge-cache.js +24 -13
- package/src/utils/purge-cache.js.map +1 -1
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +1 -1
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +12 -9
- package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js.map +1 -1
- package/src/utils/server-rendering/esm-in-memory-loader/utils.d.ts +8 -0
- package/src/utils/server-rendering/esm-in-memory-loader/utils.js +30 -0
- package/src/utils/server-rendering/esm-in-memory-loader/utils.js.map +1 -1
- package/src/utils/server-rendering/prerender.d.ts +2 -1
- package/src/utils/server-rendering/prerender.js +83 -30
- package/src/utils/server-rendering/prerender.js.map +1 -1
- package/src/utils/server-rendering/render-worker.d.ts +10 -5
- package/src/utils/server-rendering/render-worker.js +31 -7
- package/src/utils/server-rendering/render-worker.js.map +1 -1
- package/src/utils/test-files.d.ts +2 -2
- package/src/utils/test-files.js +3 -3
- package/src/utils/test-files.js.map +1 -1
- package/src/tools/angular/compilation/noop-compilation.d.ts +0 -15
- package/src/tools/angular/compilation/noop-compilation.js +0 -27
- package/src/tools/angular/compilation/noop-compilation.js.map +0 -1
- package/src/tools/sass/worker.d.ts +0 -63
- package/src/tools/sass/worker.js +0 -202
- package/src/tools/sass/worker.js.map +0 -1
- /package/src/tools/{esbuild/angular → angular/compilation}/diagnostics.d.ts +0 -0
- /package/src/tools/{esbuild/angular → angular/compilation}/diagnostics.js +0 -0
- /package/src/tools/{esbuild/angular → angular/compilation}/diagnostics.js.map +0 -0
|
@@ -43,16 +43,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.
|
|
46
|
+
exports.inlineFileBatch = inlineFileBatch;
|
|
47
47
|
exports.inlineCode = inlineCode;
|
|
48
48
|
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
49
49
|
const magic_string_1 = require("magic-string");
|
|
50
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
51
50
|
const node_v8_1 = require("node:v8");
|
|
52
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
53
51
|
const oxc_parser_1 = require("oxc-parser");
|
|
54
|
-
|
|
55
|
-
const
|
|
52
|
+
const traversal_1 = require("../oxc/traversal");
|
|
53
|
+
const i18n_locale_plugin_1 = require("./i18n-locale-plugin");
|
|
54
|
+
const i18n_translation_reader_1 = require("./i18n-translation-reader");
|
|
56
55
|
/**
|
|
57
56
|
* Cache of file data promises keyed by filename.
|
|
58
57
|
*/
|
|
@@ -62,66 +61,121 @@ const fileDataCache = new Map();
|
|
|
62
61
|
*/
|
|
63
62
|
const deserializedTranslations = new Map();
|
|
64
63
|
/**
|
|
65
|
-
*
|
|
64
|
+
* The current inlining generation for this worker.
|
|
65
|
+
*/
|
|
66
|
+
let currentGeneration;
|
|
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.
|
|
66
72
|
*
|
|
67
73
|
* @param filename The name of the file to load.
|
|
68
|
-
* @
|
|
74
|
+
* @param codeBlob The source code file as a Blob.
|
|
75
|
+
* @param cache Whether to cache the loaded file data in the Worker's long-term cache.
|
|
76
|
+
* @returns The cached or newly extracted code and localization metadata.
|
|
69
77
|
*/
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
function loadFileData(filename, codeBlob, cache = true) {
|
|
79
|
+
const existing = fileDataCache.get(filename);
|
|
80
|
+
if (existing) {
|
|
81
|
+
if (!cache) {
|
|
82
|
+
fileDataCache.delete(filename);
|
|
83
|
+
}
|
|
84
|
+
return existing;
|
|
85
|
+
}
|
|
86
|
+
const fileDataPromise = (async () => {
|
|
87
|
+
const code = await codeBlob.text();
|
|
88
|
+
const metadata = extractLocalizeMetadata(filename, code);
|
|
89
|
+
return { code, metadata };
|
|
90
|
+
})();
|
|
91
|
+
if (cache) {
|
|
92
|
+
fileDataPromise.catch(() => {
|
|
93
|
+
fileDataCache.delete(filename);
|
|
94
|
+
});
|
|
80
95
|
fileDataCache.set(filename, fileDataPromise);
|
|
81
96
|
}
|
|
82
97
|
return fileDataPromise;
|
|
83
98
|
}
|
|
84
99
|
/**
|
|
85
|
-
* Deserializes the translation messages for
|
|
100
|
+
* Deserializes or wraps the translation messages for a locale, reusing the result for any
|
|
86
101
|
* subsequent request that targets the same locale.
|
|
87
|
-
* @param
|
|
102
|
+
* @param locale The locale identifier.
|
|
103
|
+
* @param translation Optional serialized translation messages (SharedArrayBuffer or Blob).
|
|
88
104
|
* @returns The translation messages, or undefined if the locale has no translations.
|
|
89
105
|
*/
|
|
90
|
-
function loadTranslation(
|
|
91
|
-
const { locale, translation } = request;
|
|
106
|
+
function loadTranslation(locale, translation) {
|
|
92
107
|
if (!translation) {
|
|
93
108
|
return undefined;
|
|
94
109
|
}
|
|
95
110
|
let messagesPromise = deserializedTranslations.get(locale);
|
|
96
111
|
if (!messagesPromise) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
112
|
+
if (translation instanceof Blob) {
|
|
113
|
+
messagesPromise = translation
|
|
114
|
+
.arrayBuffer()
|
|
115
|
+
.then((buffer) => (0, node_v8_1.deserialize)(new Uint8Array(buffer)))
|
|
116
|
+
.catch((error) => {
|
|
117
|
+
deserializedTranslations.delete(locale);
|
|
118
|
+
throw error;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
messagesPromise = Promise.resolve((0, i18n_translation_reader_1.createSharedTranslationProxy)(translation));
|
|
123
|
+
}
|
|
100
124
|
deserializedTranslations.set(locale, messagesPromise);
|
|
101
125
|
}
|
|
102
126
|
return messagesPromise;
|
|
103
127
|
}
|
|
104
128
|
/**
|
|
105
|
-
* Inlines
|
|
106
|
-
* This function is the main entry for the Worker's action that is called by the worker pool.
|
|
129
|
+
* Inlines multiple locales and translations into a JavaScript file that contains `$localize` usage.
|
|
107
130
|
*
|
|
108
|
-
* @param request An
|
|
109
|
-
* @returns An object containing the inlined
|
|
131
|
+
* @param request An InlineFileBatchRequest object representing the options for inlining.
|
|
132
|
+
* @returns An object containing the inlined results for each requested locale.
|
|
110
133
|
*/
|
|
111
|
-
async function
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
async function inlineFileBatch(request) {
|
|
135
|
+
if (request.generation !== undefined && request.generation !== currentGeneration) {
|
|
136
|
+
currentGeneration = request.generation;
|
|
137
|
+
fileDataCache.clear();
|
|
138
|
+
deserializedTranslations.clear();
|
|
139
|
+
}
|
|
140
|
+
if (request.activeLocales) {
|
|
141
|
+
const activeSet = new Set(request.activeLocales);
|
|
142
|
+
for (const locale of deserializedTranslations.keys()) {
|
|
143
|
+
if (!activeSet.has(locale)) {
|
|
144
|
+
deserializedTranslations.delete(locale);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const { code, metadata } = await loadFileData(request.filename, request.code, !request.ephemeral);
|
|
149
|
+
// Fast path: file has no $localize call sites or locale insert sites
|
|
150
|
+
if (metadata.callSites.length === 0 && metadata.localeInsertSites.length === 0) {
|
|
151
|
+
return {
|
|
152
|
+
file: request.filename,
|
|
153
|
+
unmodified: true,
|
|
154
|
+
messages: (metadata.diagnostics ?? []).map((message) => ({
|
|
155
|
+
type: 'error',
|
|
156
|
+
message,
|
|
157
|
+
})),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Parse the sourcemap once for the entire batch if provided.
|
|
161
|
+
// It will naturally be garbage-collected after this batch action returns.
|
|
162
|
+
let map;
|
|
163
|
+
if (request.map) {
|
|
164
|
+
const rawMap = await request.map.text();
|
|
165
|
+
map = rawMap ? JSON.parse(rawMap) : undefined;
|
|
166
|
+
}
|
|
167
|
+
const results = await Promise.all(Array.from(request.locales, async ([locale, translation]) => {
|
|
168
|
+
const result = await inlineLocalize(code, map, metadata, locale, await loadTranslation(locale, translation), request.filename, request.missingTranslation);
|
|
169
|
+
return {
|
|
170
|
+
locale,
|
|
171
|
+
code: result.code,
|
|
172
|
+
map: result.map,
|
|
173
|
+
messages: result.diagnostics.messages,
|
|
174
|
+
};
|
|
175
|
+
}));
|
|
120
176
|
return {
|
|
121
177
|
file: request.filename,
|
|
122
|
-
|
|
123
|
-
map: result.map,
|
|
124
|
-
messages: result.diagnostics.messages,
|
|
178
|
+
results,
|
|
125
179
|
};
|
|
126
180
|
}
|
|
127
181
|
/**
|
|
@@ -133,9 +187,9 @@ async function inlineFile(request) {
|
|
|
133
187
|
*/
|
|
134
188
|
async function inlineCode(request) {
|
|
135
189
|
const metadata = extractLocalizeMetadata(request.filename, request.code);
|
|
136
|
-
const result = await inlineLocalize(request.code, undefined, metadata, request.locale, await loadTranslation(request), request.filename);
|
|
190
|
+
const result = await inlineLocalize(request.code, undefined, metadata, request.locale, await loadTranslation(request.locale, request.translation), request.filename, request.missingTranslation);
|
|
137
191
|
return {
|
|
138
|
-
output: result.code,
|
|
192
|
+
output: result.code ?? request.code,
|
|
139
193
|
messages: result.diagnostics.messages,
|
|
140
194
|
};
|
|
141
195
|
}
|
|
@@ -156,49 +210,6 @@ async function loadLocalizeTools() {
|
|
|
156
210
|
localizeToolsModule ??= await Promise.resolve().then(() => __importStar(require('@angular/localize/tools')));
|
|
157
211
|
return localizeToolsModule;
|
|
158
212
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Traverses ESTree AST nodes in post-order (bottom-up) without recursion.
|
|
161
|
-
* Bottom-up traversal ensures that nested `$localize` expressions are transformed and
|
|
162
|
-
* written to MagicString before outer containing templates are evaluated.
|
|
163
|
-
*
|
|
164
|
-
* @param root The root AST node to traverse.
|
|
165
|
-
* @param onExit Callback invoked on each AST node in post-order.
|
|
166
|
-
*/
|
|
167
|
-
function walkAstPostOrder(root, onExit) {
|
|
168
|
-
const traverseStack = [root];
|
|
169
|
-
const postOrderNodes = [];
|
|
170
|
-
while (traverseStack.length > 0) {
|
|
171
|
-
const current = traverseStack.pop();
|
|
172
|
-
if (!current) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
postOrderNodes.push(current);
|
|
176
|
-
const keys = oxc_parser_1.visitorKeys[current.type];
|
|
177
|
-
if (!keys) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
for (let i = 0; i < keys.length; i++) {
|
|
181
|
-
const child = current[keys[i]];
|
|
182
|
-
if (!child) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (Array.isArray(child)) {
|
|
186
|
-
for (const item of child) {
|
|
187
|
-
if (item) {
|
|
188
|
-
traverseStack.push(item);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
traverseStack.push(child);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
// Process collected nodes in reverse order to achieve bottom-up (post-order) traversal
|
|
198
|
-
for (let i = postOrderNodes.length - 1; i >= 0; i--) {
|
|
199
|
-
onExit(postOrderNodes[i]);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
213
|
/**
|
|
203
214
|
* Extracts localization call sites and locale insertion points from JavaScript code using OXC.
|
|
204
215
|
*
|
|
@@ -216,7 +227,7 @@ function extractLocalizeMetadata(filename, code) {
|
|
|
216
227
|
const callSites = [];
|
|
217
228
|
const localeInsertSites = [];
|
|
218
229
|
let diagnostics;
|
|
219
|
-
|
|
230
|
+
(0, traversal_1.traversePostOrder)(program, (node) => {
|
|
220
231
|
if (node.type === 'Literal') {
|
|
221
232
|
if (typeof node.value === 'string' && node.value === '___NG_LOCALE_INSERT___') {
|
|
222
233
|
localeInsertSites.push({ start: node.start, end: node.end });
|
|
@@ -242,11 +253,13 @@ function extractLocalizeMetadata(filename, code) {
|
|
|
242
253
|
start: expr.start,
|
|
243
254
|
end: expr.end,
|
|
244
255
|
}));
|
|
256
|
+
const expressionIndexes = expressions.map((_, index) => index);
|
|
245
257
|
callSites.push({
|
|
246
258
|
start: node.start,
|
|
247
259
|
end: node.end,
|
|
248
260
|
messageParts,
|
|
249
261
|
expressions,
|
|
262
|
+
expressionIndexes,
|
|
250
263
|
});
|
|
251
264
|
}
|
|
252
265
|
}
|
|
@@ -254,6 +267,16 @@ function extractLocalizeMetadata(filename, code) {
|
|
|
254
267
|
});
|
|
255
268
|
return { callSites, localeInsertSites, diagnostics };
|
|
256
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Escapes a template literal string part for insertion into an ES template literal (backticks).
|
|
272
|
+
* Uses JSON.stringify for base escaping of control characters and backslashes, then unescapes
|
|
273
|
+
* double quotes and escapes backticks and `${` expression delimiters in a single pass.
|
|
274
|
+
*/
|
|
275
|
+
function escapeTemplatePart(part) {
|
|
276
|
+
return JSON.stringify(part)
|
|
277
|
+
.slice(1, -1)
|
|
278
|
+
.replace(/\\"|`|\$\{/g, (match) => (match === '\\"' ? '"' : '\\' + match));
|
|
279
|
+
}
|
|
257
280
|
/**
|
|
258
281
|
* Inlines translations into code using previously extracted localization metadata.
|
|
259
282
|
*
|
|
@@ -263,9 +286,10 @@ function extractLocalizeMetadata(filename, code) {
|
|
|
263
286
|
* @param locale The target locale identifier.
|
|
264
287
|
* @param translation The translation messages dictionary, or undefined for untranslated locale.
|
|
265
288
|
* @param filename The name of the file being transformed.
|
|
289
|
+
* @param missingTranslation How to handle missing translations.
|
|
266
290
|
* @returns The transformed code, optional remapped source map, and diagnostics.
|
|
267
291
|
*/
|
|
268
|
-
async function inlineLocalize(code, map, metadata, locale, translation, filename) {
|
|
292
|
+
async function inlineLocalize(code, map, metadata, locale, translation, filename, missingTranslation = 'warning') {
|
|
269
293
|
const magicString = new magic_string_1.MagicString(code);
|
|
270
294
|
const { Diagnostics, translate } = await loadLocalizeTools();
|
|
271
295
|
const diagnostics = new Diagnostics();
|
|
@@ -274,11 +298,22 @@ async function inlineLocalize(code, map, metadata, locale, translation, filename
|
|
|
274
298
|
diagnostics.error(message);
|
|
275
299
|
}
|
|
276
300
|
}
|
|
277
|
-
|
|
278
|
-
|
|
301
|
+
if (metadata.localeInsertSites.length > 0) {
|
|
302
|
+
const localeData = await (0, i18n_locale_plugin_1.loadLocaleData)(locale);
|
|
303
|
+
if (localeData.error) {
|
|
304
|
+
diagnostics.error(localeData.error);
|
|
305
|
+
}
|
|
306
|
+
else if (localeData.warning) {
|
|
307
|
+
diagnostics.warn(localeData.warning);
|
|
308
|
+
}
|
|
309
|
+
let injected = false;
|
|
310
|
+
for (const site of metadata.localeInsertSites) {
|
|
311
|
+
magicString.overwrite(site.start, site.end, JSON.stringify(locale) + (localeData.code && !injected ? `;\n${localeData.code}\n;` : ''));
|
|
312
|
+
injected = true;
|
|
313
|
+
}
|
|
279
314
|
}
|
|
280
315
|
for (const callSite of metadata.callSites) {
|
|
281
|
-
const [translatedParts, translatedSubstitutions] = translate(diagnostics, translation || {}, callSite.messageParts, callSite.
|
|
316
|
+
const [translatedParts, translatedSubstitutions] = translate(diagnostics, translation || {}, callSite.messageParts, callSite.expressionIndexes, translation === undefined ? 'ignore' : missingTranslation);
|
|
282
317
|
// Reconstruct the new template/string literal replacement
|
|
283
318
|
let replacement;
|
|
284
319
|
if (translatedSubstitutions.length === 0) {
|
|
@@ -287,12 +322,7 @@ async function inlineLocalize(code, map, metadata, locale, translation, filename
|
|
|
287
322
|
else {
|
|
288
323
|
replacement = '`';
|
|
289
324
|
for (let i = 0; i < translatedParts.length; i++) {
|
|
290
|
-
|
|
291
|
-
.slice(1, -1)
|
|
292
|
-
.replace(/\\"/g, '"')
|
|
293
|
-
.replace(/`/g, '\\`')
|
|
294
|
-
.replace(/\$\{/g, '\\${');
|
|
295
|
-
replacement += escapedPart;
|
|
325
|
+
replacement += escapeTemplatePart(translatedParts[i]);
|
|
296
326
|
if (i < translatedSubstitutions.length) {
|
|
297
327
|
const originalIndex = translatedSubstitutions[i];
|
|
298
328
|
const expr = callSite.expressions[originalIndex];
|
|
@@ -304,9 +334,16 @@ async function inlineLocalize(code, map, metadata, locale, translation, filename
|
|
|
304
334
|
}
|
|
305
335
|
magicString.overwrite(callSite.start, callSite.end, replacement);
|
|
306
336
|
}
|
|
337
|
+
if (!magicString.hasChanged()) {
|
|
338
|
+
return {
|
|
339
|
+
code: undefined,
|
|
340
|
+
map: undefined,
|
|
341
|
+
diagnostics,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
307
344
|
const outputCode = magicString.toString();
|
|
308
345
|
let outputMap;
|
|
309
|
-
if (map
|
|
346
|
+
if (map) {
|
|
310
347
|
// A decoded map is generated here rather than an encoded one because remapping decodes its
|
|
311
348
|
// inputs. Encoding the mappings only for remapping to immediately decode them again doubles
|
|
312
349
|
// the peak memory of the largest structure involved in inlining a file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-inliner-worker.js","sourceRoot":"","sources":["i18n-inliner-worker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"i18n-inliner-worker.js","sourceRoot":"","sources":["i18n-inliner-worker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmOH,0CAiEC;AASD,gCAgBC;AA3TD,sEAA8F;AAG9F,+CAA2C;AAE3C,qCAAsC;AACtC,2CAAuC;AACvC,gDAAqD;AACrD,6DAAsD;AACtD,uEAAyE;AA2HzE;;GAEG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmC,CAAC;AAEjE;;GAEG;AACH,MAAM,wBAAwB,GAA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AQ,EAAE,CAAC;IAC1C,IAAI,SAAS,CAAC;IACd,IAAI,GAAG,EAAE,CAAC;QACR,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"}
|
|
@@ -5,17 +5,41 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
|
+
import type { ɵParsedTranslation } from '@angular/localize';
|
|
8
9
|
import { type BuildOutputFile } from './bundler-files';
|
|
9
10
|
/**
|
|
10
11
|
* Inlining options that should apply to all transformed code.
|
|
11
12
|
*/
|
|
12
13
|
export interface I18nInlinerOptions {
|
|
13
14
|
missingTranslation: 'error' | 'warning' | 'ignore';
|
|
14
|
-
outputFiles: BuildOutputFile[];
|
|
15
|
-
shouldOptimize?: boolean;
|
|
16
15
|
persistentCachePath?: string;
|
|
17
16
|
localizeVersion?: string;
|
|
18
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for inlining a specific locale.
|
|
20
|
+
*/
|
|
21
|
+
export interface LocaleInlineOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The locale specifier string.
|
|
24
|
+
*/
|
|
25
|
+
locale: string;
|
|
26
|
+
/**
|
|
27
|
+
* The translation messages for the locale, or undefined for the source/untranslated locale.
|
|
28
|
+
*/
|
|
29
|
+
translation?: Record<string, ɵParsedTranslation>;
|
|
30
|
+
/**
|
|
31
|
+
* An optional content integrity hash of the translation file(s) for fast cache key calculation.
|
|
32
|
+
*/
|
|
33
|
+
translationIntegrity?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Result of inlining for a specific locale.
|
|
37
|
+
*/
|
|
38
|
+
export interface LocaleInlineResult {
|
|
39
|
+
outputFiles: BuildOutputFile[];
|
|
40
|
+
errors: string[];
|
|
41
|
+
warnings: string[];
|
|
42
|
+
}
|
|
19
43
|
/**
|
|
20
44
|
* A class that performs i18n translation inlining of JavaScript code.
|
|
21
45
|
* A worker pool is used to distribute the transformation actions and allow
|
|
@@ -27,20 +51,27 @@ export declare class I18nInliner {
|
|
|
27
51
|
private readonly options;
|
|
28
52
|
constructor(options: I18nInlinerOptions, maxThreads?: number);
|
|
29
53
|
/**
|
|
30
|
-
* Performs inlining of translations
|
|
31
|
-
*
|
|
32
|
-
*
|
|
54
|
+
* Performs inlining of translations across multiple locales in parallel.
|
|
55
|
+
*
|
|
56
|
+
* An adaptive 2D task-partitioning algorithm distributes (files x locales) work units
|
|
57
|
+
* across all worker threads while caching AST metadata and sourcemaps in worker memory.
|
|
58
|
+
*
|
|
59
|
+
* @param files The build output files to transform.
|
|
60
|
+
* @param locales The locales and translations to inline.
|
|
61
|
+
* @returns A map of locale names to their inlined output files and diagnostics.
|
|
62
|
+
*/
|
|
63
|
+
inlineAll(files: Iterable<BuildOutputFile>, locales: Iterable<LocaleInlineOptions>): Promise<Map<string, LocaleInlineResult>>;
|
|
64
|
+
/**
|
|
65
|
+
* Performs inlining of translations for the provided locale and translations.
|
|
66
|
+
*
|
|
67
|
+
* @param files The build output files to transform.
|
|
33
68
|
* @param locale The string representing the locale to inline.
|
|
34
69
|
* @param translation The translation messages to use when inlining.
|
|
35
70
|
* @param translationIntegrity An optional integrity value for the translation messages to use for caching.
|
|
36
71
|
* @returns A promise that resolves to an array of OutputFiles representing a translated result.
|
|
37
72
|
*/
|
|
38
|
-
inlineForLocale(locale: string, translation: Record<string,
|
|
39
|
-
|
|
40
|
-
errors: string[];
|
|
41
|
-
warnings: string[];
|
|
42
|
-
}>;
|
|
43
|
-
inlineTemplateUpdate(locale: string, translation: Record<string, unknown> | undefined, templateCode: string, templateId: string): Promise<{
|
|
73
|
+
inlineForLocale(files: Iterable<BuildOutputFile>, locale: string, translation: Record<string, ɵParsedTranslation> | undefined, translationIntegrity?: string): Promise<LocaleInlineResult>;
|
|
74
|
+
inlineTemplateUpdate(locale: string, translation: Record<string, ɵParsedTranslation> | undefined, templateCode: string, templateId: string, translationIntegrity?: string): Promise<{
|
|
44
75
|
code: string;
|
|
45
76
|
errors: string[];
|
|
46
77
|
warnings: string[];
|