@angular/build 22.2.0-next.2 → 22.2.0-next.4
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 +11 -9
- package/src/builders/application/build-action.js +14 -3
- package/src/builders/application/build-action.js.map +1 -1
- package/src/builders/application/chunk-optimizer.d.ts +2 -2
- package/src/builders/application/chunk-optimizer.js +6 -5
- package/src/builders/application/chunk-optimizer.js.map +1 -1
- package/src/builders/application/execute-build.js +44 -18
- package/src/builders/application/execute-build.js.map +1 -1
- package/src/builders/application/execute-post-bundle.d.ts +2 -2
- package/src/builders/application/execute-post-bundle.js +4 -4
- package/src/builders/application/execute-post-bundle.js.map +1 -1
- package/src/builders/application/i18n.js +22 -1
- package/src/builders/application/i18n.js.map +1 -1
- package/src/builders/application/options.d.ts +14 -0
- package/src/builders/application/options.js +2 -1
- package/src/builders/application/options.js.map +1 -1
- package/src/builders/application/setup-bundling.js +2 -2
- package/src/builders/application/setup-bundling.js.map +1 -1
- package/src/builders/dev-server/internal.d.ts +1 -1
- package/src/builders/dev-server/internal.js +2 -2
- package/src/builders/dev-server/internal.js.map +1 -1
- package/src/builders/dev-server/vite/server.js +6 -2
- package/src/builders/dev-server/vite/server.js.map +1 -1
- package/src/builders/unit-test/options.js +1 -1
- package/src/builders/unit-test/options.js.map +1 -1
- package/src/builders/unit-test/runners/vitest/build-options.js +6 -0
- package/src/builders/unit-test/runners/vitest/build-options.js.map +1 -1
- package/src/builders/unit-test/test-discovery.js +3 -2
- package/src/builders/unit-test/test-discovery.js.map +1 -1
- package/src/private.d.ts +1 -1
- package/src/private.js +2 -2
- package/src/private.js.map +1 -1
- package/src/tools/angular/angular-host.d.ts +1 -2
- package/src/tools/angular/angular-host.js +6 -6
- package/src/tools/angular/angular-host.js.map +1 -1
- package/src/tools/angular/compilation/angular-compilation.d.ts +23 -10
- package/src/tools/angular/compilation/angular-compilation.js +11 -1
- package/src/tools/angular/compilation/angular-compilation.js.map +1 -1
- package/src/tools/angular/compilation/aot-compilation.d.ts +4 -10
- package/src/tools/angular/compilation/aot-compilation.js +23 -14
- package/src/tools/angular/compilation/aot-compilation.js.map +1 -1
- package/src/tools/angular/compilation/factory.d.ts +5 -3
- package/src/tools/angular/compilation/factory.js +10 -5
- package/src/tools/angular/compilation/factory.js.map +1 -1
- package/src/tools/angular/compilation/index.d.ts +2 -2
- package/src/tools/angular/compilation/index.js.map +1 -1
- package/src/tools/angular/compilation/jit-compilation.d.ts +4 -7
- package/src/tools/angular/compilation/jit-compilation.js +14 -11
- package/src/tools/angular/compilation/jit-compilation.js.map +1 -1
- package/src/tools/angular/compilation/noop-compilation.d.ts +3 -8
- package/src/tools/angular/compilation/noop-compilation.js +1 -1
- package/src/tools/angular/compilation/noop-compilation.js.map +1 -1
- package/src/tools/angular/compilation/parallel-compilation.d.ts +2 -8
- package/src/tools/angular/compilation/parallel-compilation.js.map +1 -1
- package/src/tools/angular/compilation/parallel-worker.d.ts +3 -15
- package/src/tools/angular/compilation/parallel-worker.js +11 -6
- package/src/tools/angular/compilation/parallel-worker.js.map +1 -1
- package/src/tools/angular/linker/oxc-linker.d.ts +2 -1
- package/src/tools/angular/linker/oxc-linker.js +2 -10
- package/src/tools/angular/linker/oxc-linker.js.map +1 -1
- package/src/tools/esbuild/angular/compiler-plugin.js +55 -28
- package/src/tools/esbuild/angular/compiler-plugin.js.map +1 -1
- package/src/tools/esbuild/angular/component-stylesheets.js +7 -7
- package/src/tools/esbuild/angular/component-stylesheets.js.map +1 -1
- package/src/tools/esbuild/angular/source-file-cache.d.ts +1 -2
- package/src/tools/esbuild/angular/source-file-cache.js +1 -11
- package/src/tools/esbuild/angular/source-file-cache.js.map +1 -1
- package/src/tools/esbuild/application-code-bundle.js +7 -2
- package/src/tools/esbuild/application-code-bundle.js.map +1 -1
- package/src/tools/esbuild/budget-stats.js +3 -3
- package/src/tools/esbuild/budget-stats.js.map +1 -1
- package/src/tools/esbuild/bundler-context.d.ts +20 -4
- package/src/tools/esbuild/bundler-context.js +15 -15
- package/src/tools/esbuild/bundler-context.js.map +1 -1
- package/src/tools/esbuild/bundler-files.js +3 -5
- package/src/tools/esbuild/bundler-files.js.map +1 -1
- package/src/tools/esbuild/i18n-inliner-worker.d.ts +8 -4
- package/src/tools/esbuild/i18n-inliner-worker.js +201 -55
- package/src/tools/esbuild/i18n-inliner-worker.js.map +1 -1
- package/src/tools/esbuild/i18n-inliner.d.ts +3 -1
- package/src/tools/esbuild/i18n-inliner.js +45 -11
- package/src/tools/esbuild/i18n-inliner.js.map +1 -1
- package/src/tools/esbuild/javascript-transformer-worker.d.ts +0 -4
- package/src/tools/esbuild/javascript-transformer-worker.js +105 -54
- package/src/tools/esbuild/javascript-transformer-worker.js.map +1 -1
- package/src/tools/esbuild/javascript-transformer.d.ts +1 -1
- package/src/tools/esbuild/javascript-transformer.js +63 -37
- package/src/tools/esbuild/javascript-transformer.js.map +1 -1
- package/src/tools/esbuild/license-extractor.d.ts +1 -1
- package/src/tools/esbuild/license-extractor.js +89 -86
- package/src/tools/esbuild/license-extractor.js.map +1 -1
- package/src/tools/esbuild/persistent-load-result-cache.js +11 -13
- package/src/tools/esbuild/persistent-load-result-cache.js.map +1 -1
- package/src/tools/esbuild/sqlite-cache-store.js +51 -1
- package/src/tools/esbuild/sqlite-cache-store.js.map +1 -1
- package/src/tools/esbuild/stylesheets/stylesheet-cache-key.js +4 -8
- package/src/tools/esbuild/stylesheets/stylesheet-cache-key.js.map +1 -1
- package/src/tools/esbuild/target.d.ts +29 -0
- package/src/tools/esbuild/target.js +105 -0
- package/src/tools/esbuild/target.js.map +1 -0
- package/src/tools/esbuild/utils.d.ts +2 -12
- package/src/tools/esbuild/utils.js +9 -64
- package/src/tools/esbuild/utils.js.map +1 -1
- package/src/tools/esbuild/watcher.d.ts +21 -2
- package/src/tools/esbuild/watcher.js +483 -60
- package/src/tools/esbuild/watcher.js.map +1 -1
- package/src/tools/oxc/oxc-transform.d.ts +2 -1
- package/src/tools/oxc/oxc-transform.js +5 -16
- package/src/tools/oxc/oxc-transform.js.map +1 -1
- package/src/tools/sass/rebasing-importer.d.ts +5 -5
- package/src/tools/sass/rebasing-importer.js +5 -2
- package/src/tools/sass/rebasing-importer.js.map +1 -1
- package/src/tools/sass/worker.d.ts +1 -1
- package/src/tools/sass/worker.js.map +1 -1
- package/src/tools/vite/middlewares/assets-middleware.js +3 -3
- package/src/tools/vite/middlewares/assets-middleware.js.map +1 -1
- package/src/tools/vite/utils.d.ts +2 -1
- package/src/tools/vite/utils.js +2 -1
- package/src/tools/vite/utils.js.map +1 -1
- package/src/utils/bundle-calculator.js +12 -3
- package/src/utils/bundle-calculator.js.map +1 -1
- package/src/utils/hash.d.ts +24 -0
- package/src/utils/hash.js +94 -0
- package/src/utils/hash.js.map +1 -0
- package/src/utils/i18n-options.d.ts +1 -0
- package/src/utils/i18n-options.js.map +1 -1
- package/src/utils/index-file/auto-csp.js +36 -17
- package/src/utils/index-file/auto-csp.js.map +1 -1
- package/src/utils/index-file/inline-critical-css.js +153 -109
- package/src/utils/index-file/inline-critical-css.js.map +1 -1
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/server-rendering/manifest.js +9 -4
- package/src/utils/server-rendering/manifest.js.map +1 -1
- package/src/utils/source-map.d.ts +26 -2
- package/src/utils/source-map.js +172 -85
- package/src/utils/source-map.js.map +1 -1
|
@@ -14,6 +14,7 @@ export interface I18nInlinerOptions {
|
|
|
14
14
|
outputFiles: BuildOutputFile[];
|
|
15
15
|
shouldOptimize?: boolean;
|
|
16
16
|
persistentCachePath?: string;
|
|
17
|
+
localizeVersion?: string;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* A class that performs i18n translation inlining of JavaScript code.
|
|
@@ -31,9 +32,10 @@ export declare class I18nInliner {
|
|
|
31
32
|
* of the localize function keyword.
|
|
32
33
|
* @param locale The string representing the locale to inline.
|
|
33
34
|
* @param translation The translation messages to use when inlining.
|
|
35
|
+
* @param translationIntegrity An optional integrity value for the translation messages to use for caching.
|
|
34
36
|
* @returns A promise that resolves to an array of OutputFiles representing a translated result.
|
|
35
37
|
*/
|
|
36
|
-
inlineForLocale(locale: string, translation: Record<string, unknown> | undefined): Promise<{
|
|
38
|
+
inlineForLocale(locale: string, translation: Record<string, unknown> | undefined, translationIntegrity?: string): Promise<{
|
|
37
39
|
outputFiles: BuildOutputFile[];
|
|
38
40
|
errors: string[];
|
|
39
41
|
warnings: string[];
|
|
@@ -12,8 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.I18nInliner = void 0;
|
|
14
14
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
15
|
-
const node_crypto_1 = require("node:crypto");
|
|
16
15
|
const node_path_1 = require("node:path");
|
|
16
|
+
const node_v8_1 = require("node:v8");
|
|
17
|
+
const hash_1 = require("../../utils/hash");
|
|
17
18
|
const worker_pool_1 = require("../../utils/worker-pool");
|
|
18
19
|
const bundler_files_1 = require("./bundler-files");
|
|
19
20
|
const cache_1 = require("./cache");
|
|
@@ -22,6 +23,19 @@ const cache_1 = require("./cache");
|
|
|
22
23
|
* This keyword is used to avoid processing files that would not otherwise need i18n processing.
|
|
23
24
|
*/
|
|
24
25
|
const LOCALIZE_KEYWORD = '$localize';
|
|
26
|
+
/**
|
|
27
|
+
* Serializes the translation messages for a locale for transfer to an inliner Worker.
|
|
28
|
+
*
|
|
29
|
+
* A Blob is used because cloning one shares its data by reference, whereas sending the messages
|
|
30
|
+
* themselves copies them into a Worker for every request that carries them. A locale can contain
|
|
31
|
+
* tens of thousands of messages, which makes that copy the dominant cost of inlining a locale.
|
|
32
|
+
*
|
|
33
|
+
* @param translation The translation messages for a locale, if the locale has any.
|
|
34
|
+
* @returns A Blob containing the serialized messages, or undefined if the locale has none.
|
|
35
|
+
*/
|
|
36
|
+
function serializeTranslation(translation) {
|
|
37
|
+
return translation && new Blob([(0, node_v8_1.serialize)(translation)]);
|
|
38
|
+
}
|
|
25
39
|
/**
|
|
26
40
|
* A class that performs i18n translation inlining of JavaScript code.
|
|
27
41
|
* A worker pool is used to distribute the transformation actions and allow
|
|
@@ -98,11 +112,14 @@ class I18nInliner {
|
|
|
98
112
|
* of the localize function keyword.
|
|
99
113
|
* @param locale The string representing the locale to inline.
|
|
100
114
|
* @param translation The translation messages to use when inlining.
|
|
115
|
+
* @param translationIntegrity An optional integrity value for the translation messages to use for caching.
|
|
101
116
|
* @returns A promise that resolves to an array of OutputFiles representing a translated result.
|
|
102
117
|
*/
|
|
103
|
-
async inlineForLocale(locale, translation) {
|
|
118
|
+
async inlineForLocale(locale, translation, translationIntegrity) {
|
|
104
119
|
await this.initCache();
|
|
105
120
|
const { shouldOptimize, missingTranslation } = this.options;
|
|
121
|
+
// Serialized once here and then shared by the request for every file of this locale
|
|
122
|
+
const translationBlob = serializeTranslation(translation);
|
|
106
123
|
// Request inlining for each file that contains localize calls
|
|
107
124
|
const requests = [];
|
|
108
125
|
let fileCacheKeyBase;
|
|
@@ -113,14 +130,22 @@ class I18nInliner {
|
|
|
113
130
|
}
|
|
114
131
|
let cacheResultPromise = Promise.resolve(null);
|
|
115
132
|
if (this.#cache) {
|
|
116
|
-
|
|
133
|
+
// The options are digested here so that each file's key is derived from a fixed number
|
|
134
|
+
// of bytes. Hashing the options directly would re-hash the full set of messages, which
|
|
135
|
+
// can be several megabytes, once for every file.
|
|
136
|
+
fileCacheKeyBase ??= (0, hash_1.calculateHash)(JSON.stringify({
|
|
137
|
+
locale,
|
|
138
|
+
translation: translationIntegrity ?? translation,
|
|
139
|
+
missingTranslation,
|
|
140
|
+
shouldOptimize,
|
|
141
|
+
localizeVersion: this.options.localizeVersion,
|
|
142
|
+
}));
|
|
117
143
|
// NOTE: If additional options are added, this may need to be updated.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.digest('hex');
|
|
144
|
+
const hasher = (0, hash_1.createContentHash)();
|
|
145
|
+
hasher.update(file.hash);
|
|
146
|
+
hasher.update(filename);
|
|
147
|
+
hasher.update(fileCacheKeyBase);
|
|
148
|
+
cacheKey = hasher.digest();
|
|
124
149
|
// Failure to get the value should not fail the transform
|
|
125
150
|
cacheResultPromise = this.#cache.get(cacheKey).catch(() => null);
|
|
126
151
|
}
|
|
@@ -128,7 +153,11 @@ class I18nInliner {
|
|
|
128
153
|
if (cachedResult) {
|
|
129
154
|
return cachedResult;
|
|
130
155
|
}
|
|
131
|
-
const result = await this.#workerPool.run({
|
|
156
|
+
const result = await this.#workerPool.run({
|
|
157
|
+
filename,
|
|
158
|
+
locale,
|
|
159
|
+
translation: translationBlob,
|
|
160
|
+
});
|
|
132
161
|
if (this.#cache && cacheKey) {
|
|
133
162
|
try {
|
|
134
163
|
// Failure to set the value should not fail the transform
|
|
@@ -180,7 +209,12 @@ class I18nInliner {
|
|
|
180
209
|
warnings: [],
|
|
181
210
|
};
|
|
182
211
|
}
|
|
183
|
-
const { output, messages } = await this.#workerPool.run({
|
|
212
|
+
const { output, messages } = await this.#workerPool.run({
|
|
213
|
+
code: templateCode,
|
|
214
|
+
filename: templateId,
|
|
215
|
+
locale,
|
|
216
|
+
translation: serializeTranslation(translation),
|
|
217
|
+
}, { name: 'inlineCode' });
|
|
184
218
|
const errors = [];
|
|
185
219
|
const warnings = [];
|
|
186
220
|
for (const message of messages) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-inliner.js","sourceRoot":"","sources":["i18n-inliner.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,8DAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"i18n-inliner.js","sourceRoot":"","sources":["i18n-inliner.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;AAEH,8DAAiC;AACjC,yCAA0C;AAC1C,qCAAoC;AACpC,2CAAoE;AACpE,yDAAqD;AACrD,mDAA8F;AAC9F,mCAAgF;AAE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CAAC,MAAM,GAAG,MAAM,IAAA,kCAA0B,EAAC,IAAA,gBAAI,EAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC,CAAC;QAC5F,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAE7B,sCAAsC;YACtC,OAAO,CAAC,IAAI,CACV,kDAAkD;gBAChD,gFAAgF,CACnF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAjRD,kCAiRC"}
|
|
@@ -8,12 +8,8 @@
|
|
|
8
8
|
interface JavaScriptTransformRequest {
|
|
9
9
|
filename: string;
|
|
10
10
|
data: string | Uint8Array;
|
|
11
|
-
sourcemap: boolean;
|
|
12
|
-
thirdPartySourcemaps: boolean;
|
|
13
|
-
advancedOptimizations: boolean;
|
|
14
11
|
skipLinker?: boolean;
|
|
15
12
|
sideEffects?: boolean;
|
|
16
|
-
jit: boolean;
|
|
17
13
|
instrumentForCoverage?: boolean;
|
|
18
14
|
}
|
|
19
15
|
export default function transformJavaScript(request: JavaScriptTransformRequest): Promise<unknown>;
|
|
@@ -44,20 +44,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.default = transformJavaScript;
|
|
47
|
+
const remapping_1 = __importDefault(require("@ampproject/remapping"));
|
|
47
48
|
const core_1 = require("@babel/core");
|
|
48
49
|
const node_module_1 = require("node:module");
|
|
50
|
+
const node_worker_threads_1 = require("node:worker_threads");
|
|
49
51
|
const piscina_1 = __importDefault(require("piscina"));
|
|
50
52
|
const environment_options_js_1 = require("../../utils/environment-options.js");
|
|
51
53
|
const source_map_1 = require("../../utils/source-map");
|
|
54
|
+
const oxc_linker_js_1 = require("../angular/linker/oxc-linker.js");
|
|
55
|
+
const oxc_transform_js_1 = require("../oxc/oxc-transform.js");
|
|
56
|
+
const { sourcemap = false, thirdPartySourcemaps = false, advancedOptimizations = false, jit = false, } = (node_worker_threads_1.workerData || {});
|
|
52
57
|
const textDecoder = new TextDecoder();
|
|
53
58
|
const textEncoder = new TextEncoder();
|
|
54
|
-
/**
|
|
55
|
-
* The function name prefix for all Angular partial compilation functions.
|
|
56
|
-
* Used to determine if linking of a JavaScript file is required.
|
|
57
|
-
* If any additional declarations are added or otherwise changed in the linker,
|
|
58
|
-
* the names MUST begin with this prefix.
|
|
59
|
-
*/
|
|
60
|
-
const LINKER_DECLARATION_PREFIX = 'ɵɵngDeclare';
|
|
61
59
|
async function instrumentCoverage(filename, data, useInputSourcemap) {
|
|
62
60
|
try {
|
|
63
61
|
let resolvedPath = 'istanbul-lib-instrument';
|
|
@@ -75,12 +73,13 @@ async function instrumentCoverage(filename, data, useInputSourcemap) {
|
|
|
75
73
|
});
|
|
76
74
|
const inputSourceMap = useInputSourcemap ? (0, source_map_1.loadInputSourceMap)(filename, data) : undefined;
|
|
77
75
|
const instrumentedCode = instrumenter.instrumentSync(data, filename, inputSourceMap);
|
|
78
|
-
const lastMap =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const lastMap = useInputSourcemap
|
|
77
|
+
? instrumenter.lastSourceMap()
|
|
78
|
+
: undefined;
|
|
79
|
+
return {
|
|
80
|
+
code: instrumentedCode,
|
|
81
|
+
map: lastMap ?? undefined,
|
|
82
|
+
};
|
|
84
83
|
}
|
|
85
84
|
catch (error) {
|
|
86
85
|
throw new Error(`The 'istanbul-lib-instrument' package is required for code coverage but was not found. Please install the package.`, { cause: error });
|
|
@@ -88,22 +87,71 @@ async function instrumentCoverage(filename, data, useInputSourcemap) {
|
|
|
88
87
|
}
|
|
89
88
|
async function transformJavaScript(request) {
|
|
90
89
|
const { filename, data, ...options } = request;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
const useInputSourcemap = sourcemap && (!!thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
|
|
91
|
+
let textData;
|
|
92
|
+
let inputSourceMap;
|
|
93
|
+
let isAlreadyStripped = false;
|
|
94
|
+
if (typeof data !== 'string') {
|
|
95
|
+
const trailing = (0, source_map_1.findTrailingSourceMapComment)(data);
|
|
96
|
+
if (trailing === null) {
|
|
97
|
+
// 0 comments: fast path, no sourcemap to load or strip
|
|
98
|
+
textData = textDecoder.decode(data);
|
|
99
|
+
isAlreadyStripped = true;
|
|
100
|
+
}
|
|
101
|
+
else if (trailing !== undefined) {
|
|
102
|
+
if (useInputSourcemap) {
|
|
103
|
+
inputSourceMap = (0, source_map_1.loadInputSourceMapFromUrl)(filename, trailing.urlLine);
|
|
104
|
+
if (inputSourceMap !== undefined) {
|
|
105
|
+
// Valid trailing sourcemap comment confirmed: safe to slice code buffer for transformation passes.
|
|
106
|
+
// Note: If no passes modify the code, the untouched original `data` buffer is returned below.
|
|
107
|
+
textData = textDecoder.decode(trailing.code);
|
|
108
|
+
isAlreadyStripped = true;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Not a valid trailing sourcemap (e.g. inside template literal): fallback to full decode
|
|
112
|
+
textData = textDecoder.decode(data);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if ((0, source_map_1.isTrailingSourceMapComment)(trailing.urlLine)) {
|
|
116
|
+
// Valid trailing sourcemap comment confirmed: safe to slice code buffer
|
|
117
|
+
textData = textDecoder.decode(trailing.code);
|
|
118
|
+
isAlreadyStripped = true;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Fallback to full decode and state-machine stripping
|
|
122
|
+
textData = textDecoder.decode(data);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Multiple comments or comment not at line start: fall back to full decode and string parser
|
|
127
|
+
textData = textDecoder.decode(data);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
textData = data;
|
|
132
|
+
}
|
|
133
|
+
const transformedData = await transformJavaScriptImpl(filename, textData, {
|
|
134
|
+
...options,
|
|
135
|
+
inputSourceMap,
|
|
136
|
+
isAlreadyStripped,
|
|
137
|
+
});
|
|
138
|
+
// If no transformations modified the code, return the original untouched data buffer via `move`.
|
|
139
|
+
// This preserves any original trailing sourcemap comment and avoids re-encoding.
|
|
140
|
+
if (transformedData === textData && typeof data !== 'string') {
|
|
141
|
+
return piscina_1.default.move(data);
|
|
142
|
+
}
|
|
94
143
|
return piscina_1.default.move(textEncoder.encode(transformedData));
|
|
95
144
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Cached instance of the OXC linker module.
|
|
98
|
-
*/
|
|
99
|
-
let oxcLinkerModule;
|
|
100
145
|
async function transformJavaScriptImpl(filename, data, options) {
|
|
101
|
-
const shouldLink = !options.skipLinker
|
|
102
|
-
const useInputSourcemap =
|
|
103
|
-
(!!options.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
|
|
146
|
+
const shouldLink = !options.skipLinker;
|
|
147
|
+
const useInputSourcemap = sourcemap && (!!thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
|
|
104
148
|
let code = data;
|
|
149
|
+
const maps = [];
|
|
150
|
+
let coverageMap;
|
|
105
151
|
if (options.instrumentForCoverage) {
|
|
106
|
-
|
|
152
|
+
const result = await instrumentCoverage(filename, code, useInputSourcemap);
|
|
153
|
+
code = result.code;
|
|
154
|
+
coverageMap = result.map;
|
|
107
155
|
}
|
|
108
156
|
if (shouldLink) {
|
|
109
157
|
if (environment_options_js_1.useBabelLinker) {
|
|
@@ -111,8 +159,8 @@ async function transformJavaScriptImpl(filename, data, options) {
|
|
|
111
159
|
const { ConsoleLogger, LogLevel } = await Promise.resolve().then(() => __importStar(require('@angular/compiler-cli')));
|
|
112
160
|
const result = await (0, core_1.transformAsync)(code, {
|
|
113
161
|
filename,
|
|
114
|
-
inputSourceMap:
|
|
115
|
-
sourceMaps: useInputSourcemap
|
|
162
|
+
inputSourceMap: false,
|
|
163
|
+
sourceMaps: !!useInputSourcemap,
|
|
116
164
|
compact: false,
|
|
117
165
|
configFile: false,
|
|
118
166
|
babelrc: false,
|
|
@@ -127,60 +175,63 @@ async function transformJavaScriptImpl(filename, data, options) {
|
|
|
127
175
|
relative: (_from, to) => to,
|
|
128
176
|
},
|
|
129
177
|
logger: new ConsoleLogger(LogLevel.info),
|
|
130
|
-
linkerJitMode:
|
|
178
|
+
linkerJitMode: jit,
|
|
131
179
|
// This is a workaround until https://github.com/angular/angular/issues/42769 is fixed.
|
|
132
180
|
sourceMapping: false,
|
|
133
181
|
}),
|
|
134
182
|
],
|
|
135
183
|
});
|
|
136
184
|
code = result?.code ?? code;
|
|
185
|
+
if (result?.map) {
|
|
186
|
+
maps.push(result.map);
|
|
187
|
+
}
|
|
137
188
|
}
|
|
138
189
|
else {
|
|
139
|
-
|
|
140
|
-
const result = oxcLinkerModule.linkWithOxc(filename, code, {
|
|
190
|
+
const result = (0, oxc_linker_js_1.linkWithOxc)(filename, code, {
|
|
141
191
|
sourcemap: useInputSourcemap,
|
|
142
|
-
jit
|
|
192
|
+
jit,
|
|
143
193
|
skipCheck: true,
|
|
144
194
|
});
|
|
145
195
|
code = result.code;
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
const base64Map = Buffer.from(result.map).toString('base64');
|
|
149
|
-
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
196
|
+
if (result.map) {
|
|
197
|
+
maps.push(result.map);
|
|
150
198
|
}
|
|
151
199
|
}
|
|
152
200
|
}
|
|
153
201
|
// Run advanced optimizations using our fast oxc-transform
|
|
154
|
-
if (
|
|
155
|
-
const { transform } = await Promise.resolve().then(() => __importStar(require('../oxc/oxc-transform.js')));
|
|
202
|
+
if (advancedOptimizations) {
|
|
156
203
|
const sideEffectFree = options.sideEffects === false;
|
|
157
204
|
const safeAngularPackage = sideEffectFree && /[\\/]node_modules[\\/]@angular[\\/]/.test(filename);
|
|
158
205
|
const topLevelSafeMode = !safeAngularPackage;
|
|
159
|
-
const result = transform(filename, code, {
|
|
206
|
+
const result = (0, oxc_transform_js_1.transform)(filename, code, {
|
|
160
207
|
sourcemap: useInputSourcemap,
|
|
161
208
|
sideEffects: options.sideEffects,
|
|
162
209
|
topLevelSafeMode,
|
|
163
210
|
});
|
|
164
211
|
code = result.code;
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
code = (0, source_map_1.removeSourceMappingURL)(code);
|
|
168
|
-
const base64Map = Buffer.from(result.map).toString('base64');
|
|
169
|
-
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
212
|
+
if (result.map) {
|
|
213
|
+
maps.push(result.map);
|
|
170
214
|
}
|
|
171
215
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
216
|
+
if (useInputSourcemap) {
|
|
217
|
+
const baseMap = coverageMap ?? options.inputSourceMap ?? (0, source_map_1.loadInputSourceMap)(filename, data);
|
|
218
|
+
if (maps.length > 0 || coverageMap) {
|
|
219
|
+
if (!options.isAlreadyStripped) {
|
|
220
|
+
code = (0, source_map_1.removeSourceMappingURL)(code);
|
|
221
|
+
}
|
|
222
|
+
const remappingChain = maps.reverse();
|
|
223
|
+
if (baseMap) {
|
|
224
|
+
remappingChain.push(baseMap);
|
|
225
|
+
}
|
|
226
|
+
if (remappingChain.length > 0) {
|
|
227
|
+
const finalMap = (0, remapping_1.default)(remappingChain, () => null).toString();
|
|
228
|
+
const base64Map = Buffer.from(finalMap).toString('base64');
|
|
229
|
+
code += `\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return code;
|
|
180
233
|
}
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
// and the result would be an unnecessary no-op additional plugin pass.
|
|
184
|
-
return source.includes(LINKER_DECLARATION_PREFIX);
|
|
234
|
+
// Strip sourcemaps if they should not be used
|
|
235
|
+
return options.isAlreadyStripped ? code : (0, source_map_1.removeSourceMappingURL)(code);
|
|
185
236
|
}
|
|
186
237
|
//# sourceMappingURL=javascript-transformer-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript-transformer-worker.js","sourceRoot":"","sources":["javascript-transformer-worker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"javascript-transformer-worker.js","sourceRoot":"","sources":["javascript-transformer-worker.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFH,sCA2DC;AA/ID,sEAAgG;AAChG,sCAA8D;AAC9D,6CAA4C;AAC5C,6DAAiD;AACjD,sDAA8B;AAC9B,+EAAoE;AACpE,uDAMgC;AAChC,mEAA8D;AAC9D,8DAAwE;AAgBxE,MAAM,EACJ,SAAS,GAAG,KAAK,EACjB,oBAAoB,GAAG,KAAK,EAC5B,qBAAqB,GAAG,KAAK,EAC7B,GAAG,GAAG,KAAK,GACZ,GAAG,CAAC,gCAAU,IAAI,EAAE,CAA0C,CAAC;AAEhE,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,KAAK,UAAU,kBAAkB,CAC/B,QAAgB,EAChB,IAAY,EACZ,iBAA0B;IAE1B,IAAI,CAAC;QACH,IAAI,YAAY,GAAG,yBAAyB,CAAC;QAC7C,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAA,2BAAa,EAAC,QAAQ,CAAC,CAAC;YAC1C,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC9D,CAAC;QAAC,MAAM,CAAC;YACP,2CAA2C;QAC7C,CAAC;QAED,MAAM,EAAE,kBAAkB,EAAE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AAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAC3D,IAAI,IAAI,qEAAqE,SAAS,EAAE,CAAC;YAC3F,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8CAA8C;IAC9C,OAAO,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,mCAAsB,EAAC,IAAI,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -45,7 +45,7 @@ export declare class JavaScriptTransformer {
|
|
|
45
45
|
* @param sideEffects If false, and `advancedOptimizations` is enabled tslib decorators are wrapped.
|
|
46
46
|
* @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
|
|
47
47
|
*/
|
|
48
|
-
transformData(filename: string, data: string, skipLinker: boolean, sideEffects?: boolean, instrumentForCoverage?: boolean): Promise<Uint8Array>;
|
|
48
|
+
transformData(filename: string, data: string | Uint8Array, skipLinker: boolean, sideEffects?: boolean, instrumentForCoverage?: boolean): Promise<Uint8Array>;
|
|
49
49
|
/**
|
|
50
50
|
* Stops all active transformation tasks and shuts down all workers.
|
|
51
51
|
* @returns A void promise that resolves when closing is complete.
|
|
@@ -8,11 +8,34 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.JavaScriptTransformer = void 0;
|
|
11
|
-
const node_crypto_1 = require("node:crypto");
|
|
12
11
|
const promises_1 = require("node:fs/promises");
|
|
12
|
+
const hash_1 = require("../../utils/hash");
|
|
13
13
|
const utils_1 = require("../../utils/server-rendering/esm-in-memory-loader/utils");
|
|
14
14
|
const source_map_1 = require("../../utils/source-map");
|
|
15
15
|
const worker_pool_1 = require("../../utils/worker-pool");
|
|
16
|
+
const LINKER_DECLARATION_PREFIX = 'ɵɵngDeclare';
|
|
17
|
+
const LINKER_DECLARATION_PREFIX_BYTES = Buffer.from(LINKER_DECLARATION_PREFIX, 'utf-8');
|
|
18
|
+
/**
|
|
19
|
+
* Determines whether JavaScript code requires Angular linker processing.
|
|
20
|
+
*
|
|
21
|
+
* @param path The full path to the file.
|
|
22
|
+
* @param data The data (string or Buffer) of the file.
|
|
23
|
+
* @returns True if the code contains an Angular partial declaration; otherwise false.
|
|
24
|
+
*/
|
|
25
|
+
function requiresLinking(path, data) {
|
|
26
|
+
// @angular/core and @angular/compiler will cause false positives
|
|
27
|
+
// Also, TypeScript files do not require linking
|
|
28
|
+
if (/[\\/]@angular[\\/](?:compiler|core)[\\/]|\.[cm]?tsx?$/.test(path)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (typeof data === 'string') {
|
|
32
|
+
return data.includes(LINKER_DECLARATION_PREFIX);
|
|
33
|
+
}
|
|
34
|
+
const dataBuffer = Buffer.isBuffer(data)
|
|
35
|
+
? data
|
|
36
|
+
: Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
37
|
+
return dataBuffer.includes(LINKER_DECLARATION_PREFIX_BYTES);
|
|
38
|
+
}
|
|
16
39
|
/**
|
|
17
40
|
* A class that performs transformation of JavaScript files and raw data.
|
|
18
41
|
* A worker pool is used to distribute the transformation actions and allow
|
|
@@ -46,6 +69,7 @@ class JavaScriptTransformer {
|
|
|
46
69
|
jit,
|
|
47
70
|
};
|
|
48
71
|
this.#fileCacheKeyBase = Buffer.from(JSON.stringify(this.#commonOptions), 'utf-8');
|
|
72
|
+
this.#workerPool = this.#ensureWorkerPool();
|
|
49
73
|
}
|
|
50
74
|
/**
|
|
51
75
|
* Executes a transformation action using a semaphore-based backpressure throttle.
|
|
@@ -82,6 +106,8 @@ class JavaScriptTransformer {
|
|
|
82
106
|
const workerPoolOptions = {
|
|
83
107
|
filename: require.resolve('./javascript-transformer-worker'),
|
|
84
108
|
maxThreads: this.maxThreads,
|
|
109
|
+
minThreads: this.maxThreads,
|
|
110
|
+
workerData: this.#commonOptions,
|
|
85
111
|
};
|
|
86
112
|
// Prevent passing SSR `--import` (loader-hooks) from parent to child worker.
|
|
87
113
|
const filteredExecArgv = process.execArgv.filter((v) => v !== utils_1.IMPORT_EXEC_ARGV);
|
|
@@ -102,46 +128,32 @@ class JavaScriptTransformer {
|
|
|
102
128
|
async transformFile(filename, skipLinker, sideEffects, instrumentForCoverage) {
|
|
103
129
|
return this.#runWithThrottle(async () => {
|
|
104
130
|
const data = await (0, promises_1.readFile)(filename);
|
|
105
|
-
let result;
|
|
106
131
|
let cacheKey;
|
|
107
132
|
if (this.cache) {
|
|
108
133
|
// Create a cache key from the file data and options that effect the output.
|
|
109
134
|
// NOTE: If additional options are added, this may need to be updated.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
cacheKey = hash.digest('hex');
|
|
135
|
+
const hasher = (0, hash_1.createContentHash)();
|
|
136
|
+
hasher.update(`${!!skipLinker}--${!!sideEffects}`);
|
|
137
|
+
hasher.update(data);
|
|
138
|
+
hasher.update(this.#fileCacheKeyBase);
|
|
139
|
+
cacheKey = hasher.digest();
|
|
116
140
|
try {
|
|
117
|
-
|
|
141
|
+
const cached = await this.cache.get(cacheKey);
|
|
142
|
+
if (cached !== undefined) {
|
|
143
|
+
return cached;
|
|
144
|
+
}
|
|
118
145
|
}
|
|
119
146
|
catch {
|
|
120
147
|
// Failure to get the value should not fail the transform
|
|
121
148
|
}
|
|
122
149
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
instrumentForCoverage,
|
|
131
|
-
...this.#commonOptions,
|
|
132
|
-
}, {
|
|
133
|
-
// The below is disable as with Yarn PNP this causes build failures with the below message
|
|
134
|
-
// `Unable to deserialize cloned data`.
|
|
135
|
-
transferList: process.versions.pnp ? undefined : [data.buffer],
|
|
136
|
-
}));
|
|
137
|
-
// If there is a cache then store the result
|
|
138
|
-
if (this.cache && cacheKey) {
|
|
139
|
-
try {
|
|
140
|
-
await this.cache.put(cacheKey, result);
|
|
141
|
-
}
|
|
142
|
-
catch {
|
|
143
|
-
// Failure to store the value in the cache should not fail the transform
|
|
144
|
-
}
|
|
150
|
+
const result = await this.transformData(filename, data, !!skipLinker, sideEffects, instrumentForCoverage);
|
|
151
|
+
if (this.cache && cacheKey) {
|
|
152
|
+
try {
|
|
153
|
+
await this.cache.put(cacheKey, result);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Failure to store the value in the cache should not fail the transform
|
|
145
157
|
}
|
|
146
158
|
}
|
|
147
159
|
return result;
|
|
@@ -157,21 +169,35 @@ class JavaScriptTransformer {
|
|
|
157
169
|
* @returns A promise that resolves to a UTF-8 encoded Uint8Array containing the result.
|
|
158
170
|
*/
|
|
159
171
|
async transformData(filename, data, skipLinker, sideEffects, instrumentForCoverage) {
|
|
172
|
+
const shouldLink = !skipLinker && requiresLinking(filename, data);
|
|
160
173
|
// Perform a quick test to determine if the data needs any transformations.
|
|
161
174
|
// This allows directly returning the data without the worker communication overhead.
|
|
162
|
-
if (
|
|
175
|
+
if (!shouldLink && !this.#commonOptions.advancedOptimizations && !instrumentForCoverage) {
|
|
163
176
|
const keepSourcemap = this.#commonOptions.sourcemap &&
|
|
164
177
|
(!!this.#commonOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
|
|
165
|
-
|
|
178
|
+
if (typeof data === 'string') {
|
|
179
|
+
return Buffer.from(keepSourcemap ? data : (0, source_map_1.removeSourceMappingURL)(data), 'utf-8');
|
|
180
|
+
}
|
|
181
|
+
return keepSourcemap ? data : (0, source_map_1.removeSourceMappingURL)(data);
|
|
166
182
|
}
|
|
167
|
-
|
|
183
|
+
// Only standalone (non-pooled) ArrayBuffers can be transferred across worker threads.
|
|
184
|
+
// Node.js shares an internal 8KB ArrayBuffer pool for small buffers, and transferring
|
|
185
|
+
// a pooled buffer will throw a DataCloneError because detaching it invalidates other slices.
|
|
186
|
+
// In addition, SharedArrayBuffers cannot be transferred, and Yarn PnP has deserialization issues.
|
|
187
|
+
const isTransferable = typeof data !== 'string' &&
|
|
188
|
+
data.buffer instanceof ArrayBuffer &&
|
|
189
|
+
data.byteOffset === 0 &&
|
|
190
|
+
data.byteLength === data.buffer.byteLength &&
|
|
191
|
+
!process.versions.pnp;
|
|
192
|
+
return this.#ensureWorkerPool().run({
|
|
168
193
|
filename,
|
|
169
194
|
data,
|
|
170
|
-
skipLinker,
|
|
195
|
+
skipLinker: !shouldLink,
|
|
171
196
|
sideEffects,
|
|
172
197
|
instrumentForCoverage,
|
|
173
|
-
|
|
174
|
-
|
|
198
|
+
}, {
|
|
199
|
+
transferList: isTransferable ? [data.buffer] : undefined,
|
|
200
|
+
});
|
|
175
201
|
}
|
|
176
202
|
/**
|
|
177
203
|
* Stops all active transformation tasks and shuts down all workers.
|