Skip to content

Commit 7a06323

Browse files
clydindgp1130
authored andcommitted
fix(@angular-devkit/build-angular): explicitly send options to JS transformer workers
When using the experimental esbuild-based browser application builder, the JavaScript transformation workers will now only receive the explicit options expected. Previously, additional Angular compiler plugin options could have been serialized and sent as well. While these would be unused, there was no need to serialize/deserialize these option values.
1 parent 9771696 commit 7a06323

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ export interface JavaScriptTransformerOptions {
2626
*/
2727
export class JavaScriptTransformer {
2828
#workerPool: Piscina;
29+
#commonOptions: Required<JavaScriptTransformerOptions>;
2930

30-
constructor(private options: JavaScriptTransformerOptions, maxThreads?: number) {
31+
constructor(options: JavaScriptTransformerOptions, maxThreads?: number) {
3132
this.#workerPool = new Piscina({
3233
filename: require.resolve('./javascript-transformer-worker'),
3334
maxThreads,
3435
});
36+
37+
// Extract options to ensure only the named options are serialized and sent to the worker
38+
const { sourcemap, thirdPartySourcemaps = false, advancedOptimizations = false } = options;
39+
this.#commonOptions = {
40+
sourcemap,
41+
thirdPartySourcemaps,
42+
advancedOptimizations,
43+
};
3544
}
3645

3746
/**
@@ -45,7 +54,7 @@ export class JavaScriptTransformer {
4554
// they may need linking. The data is also not yet available to perform most transformation checks.
4655
return this.#workerPool.run({
4756
filename,
48-
...this.options,
57+
...this.#commonOptions,
4958
});
5059
}
5160

@@ -61,7 +70,7 @@ export class JavaScriptTransformer {
6170
// Perform a quick test to determine if the data needs any transformations.
6271
// This allows directly returning the data without the worker communication overhead.
6372
let forceAsyncTransformation;
64-
if (skipLinker && !this.options.advancedOptimizations) {
73+
if (skipLinker && !this.#commonOptions.advancedOptimizations) {
6574
// If the linker is being skipped and no optimizations are needed, only async transformation is left.
6675
// This checks for async generator functions. All other async transformation is handled by esbuild.
6776
forceAsyncTransformation = data.includes('async') && /async\s+function\s*\*/.test(data);
@@ -77,7 +86,7 @@ export class JavaScriptTransformer {
7786
// Send the async check result if present to avoid rechecking in the worker
7887
forceAsyncTransformation,
7988
skipLinker,
80-
...this.options,
89+
...this.#commonOptions,
8190
});
8291
}
8392

0 commit comments

Comments
 (0)