Skip to content

Commit d263cb2

Browse files
committedDec 19, 2023
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.
1 parent a1f3ae5 commit d263cb2

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
 

‎packages/angular_devkit/build_angular/src/builders/application/execute-build.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,14 @@ export async function executeBuild(
177177
}
178178

179179
// Analyze external imports if external options are enabled
180-
if (options.externalPackages || options.externalDependencies?.length) {
180+
if (options.externalPackages || bundlingResult.externalConfiguration) {
181181
const { browser = new Set(), server = new Set() } = bundlingResult.externalImports;
182-
// TODO: Filter externalImports to generate second argument to support wildcard externalDependency values
183-
executionResult.setExternalMetadata([...browser], [...server], options.externalDependencies);
182+
// TODO: Filter externalImports to generate third argument to support wildcard externalConfiguration values
183+
executionResult.setExternalMetadata(
184+
[...browser],
185+
[...server],
186+
bundlingResult.externalConfiguration,
187+
);
184188
}
185189

186190
const { metafile, initialFiles, outputFiles } = bundlingResult;

‎packages/angular_devkit/build_angular/src/tools/esbuild/bundler-context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type BundleContextResult =
3434
server?: Set<string>;
3535
browser?: Set<string>;
3636
};
37+
externalConfiguration?: string[];
3738
};
3839

3940
export interface InitialFileRecord {
@@ -124,6 +125,7 @@ export class BundlerContext {
124125
const externalImportsServer = new Set<string>();
125126

126127
const outputFiles = [];
128+
let externalConfiguration;
127129
for (const result of individualResults) {
128130
warnings.push(...result.warnings);
129131
if (result.errors) {
@@ -142,6 +144,13 @@ export class BundlerContext {
142144
outputFiles.push(...result.outputFiles);
143145
result.externalImports.browser?.forEach((value) => externalImportsBrowser.add(value));
144146
result.externalImports.server?.forEach((value) => externalImportsServer.add(value));
147+
148+
if (result.externalConfiguration) {
149+
externalConfiguration ??= new Set<string>();
150+
for (const value of result.externalConfiguration) {
151+
externalConfiguration.add(value);
152+
}
153+
}
145154
}
146155

147156
if (errors !== undefined) {
@@ -158,6 +167,7 @@ export class BundlerContext {
158167
browser: externalImportsBrowser,
159168
server: externalImportsServer,
160169
},
170+
externalConfiguration: externalConfiguration ? [...externalConfiguration] : undefined,
161171
};
162172
}
163173

@@ -349,6 +359,7 @@ export class BundlerContext {
349359
externalImports: {
350360
[platformIsServer ? 'server' : 'browser']: externalImports,
351361
},
362+
externalConfiguration: this.#esbuildOptions.external,
352363
errors: undefined,
353364
};
354365
}

0 commit comments

Comments
 (0)