Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): use direct explicit external…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
clydin committed Dec 19, 2023
1 parent a1f3ae5 commit d263cb2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type BundleContextResult =
server?: Set<string>;
browser?: Set<string>;
};
externalConfiguration?: string[];
};

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

const outputFiles = [];
let externalConfiguration;
for (const result of individualResults) {
warnings.push(...result.warnings);
if (result.errors) {
Expand All @@ -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<string>();
for (const value of result.externalConfiguration) {
externalConfiguration.add(value);
}
}
}

if (errors !== undefined) {
Expand All @@ -158,6 +167,7 @@ export class BundlerContext {
browser: externalImportsBrowser,
server: externalImportsServer,
},
externalConfiguration: externalConfiguration ? [...externalConfiguration] : undefined,
};
}

Expand Down Expand Up @@ -349,6 +359,7 @@ export class BundlerContext {
externalImports: {
[platformIsServer ? 'server' : 'browser']: externalImports,
},
externalConfiguration: this.#esbuildOptions.external,
errors: undefined,
};
}
Expand Down

0 comments on commit d263cb2

Please sign in to comment.