From 7a063238b83eea8b5b3237fed12db5528d1f6912 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 5 Dec 2022 14:16:38 -0500 Subject: [PATCH] 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. --- .../browser-esbuild/javascript-transformer.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts index 382bcc0fc436..e08a2b4a151f 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts @@ -26,12 +26,21 @@ export interface JavaScriptTransformerOptions { */ export class JavaScriptTransformer { #workerPool: Piscina; + #commonOptions: Required; - constructor(private options: JavaScriptTransformerOptions, maxThreads?: number) { + constructor(options: JavaScriptTransformerOptions, maxThreads?: number) { this.#workerPool = new Piscina({ filename: require.resolve('./javascript-transformer-worker'), maxThreads, }); + + // Extract options to ensure only the named options are serialized and sent to the worker + const { sourcemap, thirdPartySourcemaps = false, advancedOptimizations = false } = options; + this.#commonOptions = { + sourcemap, + thirdPartySourcemaps, + advancedOptimizations, + }; } /** @@ -45,7 +54,7 @@ export class JavaScriptTransformer { // they may need linking. The data is also not yet available to perform most transformation checks. return this.#workerPool.run({ filename, - ...this.options, + ...this.#commonOptions, }); } @@ -61,7 +70,7 @@ export class JavaScriptTransformer { // Perform a quick test to determine if the data needs any transformations. // This allows directly returning the data without the worker communication overhead. let forceAsyncTransformation; - if (skipLinker && !this.options.advancedOptimizations) { + if (skipLinker && !this.#commonOptions.advancedOptimizations) { // If the linker is being skipped and no optimizations are needed, only async transformation is left. // This checks for async generator functions. All other async transformation is handled by esbuild. forceAsyncTransformation = data.includes('async') && /async\s+function\s*\*/.test(data); @@ -77,7 +86,7 @@ export class JavaScriptTransformer { // Send the async check result if present to avoid rechecking in the worker forceAsyncTransformation, skipLinker, - ...this.options, + ...this.#commonOptions, }); }