From d263cb2783a002861c56a5e624825a0f9cba91eb Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:38:46 -0500 Subject: [PATCH] refactor(@angular-devkit/build-angular): use direct explicit external configuration for metadata The metadata used by the development server to determine the prebundling and externalization behavior is now created using the external configurations of each bundling operation context directly instead of the higher level `externalDependencies` build option. This better captures the explicitly defined external values as each bundling operation configuration could contain additional values based on the needs and/or customization of each. This will have no current noticeable behavior change as the default behavior currently does not differ from the higher level option. --- .../src/builders/application/execute-build.ts | 10 +++++++--- .../src/tools/esbuild/bundler-context.ts | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/builders/application/execute-build.ts b/packages/angular_devkit/build_angular/src/builders/application/execute-build.ts index 25391649f751..e6544ffb254b 100644 --- a/packages/angular_devkit/build_angular/src/builders/application/execute-build.ts +++ b/packages/angular_devkit/build_angular/src/builders/application/execute-build.ts @@ -177,10 +177,14 @@ export async function executeBuild( } // Analyze external imports if external options are enabled - if (options.externalPackages || options.externalDependencies?.length) { + if (options.externalPackages || bundlingResult.externalConfiguration) { const { browser = new Set(), server = new Set() } = bundlingResult.externalImports; - // TODO: Filter externalImports to generate second argument to support wildcard externalDependency values - executionResult.setExternalMetadata([...browser], [...server], options.externalDependencies); + // TODO: Filter externalImports to generate third argument to support wildcard externalConfiguration values + executionResult.setExternalMetadata( + [...browser], + [...server], + bundlingResult.externalConfiguration, + ); } const { metafile, initialFiles, outputFiles } = bundlingResult; diff --git a/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts b/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts index 55a471764561..bc7484c48e74 100644 --- a/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts +++ b/packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts @@ -34,6 +34,7 @@ export type BundleContextResult = server?: Set; browser?: Set; }; + externalConfiguration?: string[]; }; export interface InitialFileRecord { @@ -124,6 +125,7 @@ export class BundlerContext { const externalImportsServer = new Set(); const outputFiles = []; + let externalConfiguration; for (const result of individualResults) { warnings.push(...result.warnings); if (result.errors) { @@ -142,6 +144,13 @@ export class BundlerContext { outputFiles.push(...result.outputFiles); result.externalImports.browser?.forEach((value) => externalImportsBrowser.add(value)); result.externalImports.server?.forEach((value) => externalImportsServer.add(value)); + + if (result.externalConfiguration) { + externalConfiguration ??= new Set(); + for (const value of result.externalConfiguration) { + externalConfiguration.add(value); + } + } } if (errors !== undefined) { @@ -158,6 +167,7 @@ export class BundlerContext { browser: externalImportsBrowser, server: externalImportsServer, }, + externalConfiguration: externalConfiguration ? [...externalConfiguration] : undefined, }; } @@ -349,6 +359,7 @@ export class BundlerContext { externalImports: { [platformIsServer ? 'server' : 'browser']: externalImports, }, + externalConfiguration: this.#esbuildOptions.external, errors: undefined, }; }