Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): remove unintended files in esbuil…
Browse files Browse the repository at this point in the history
…d output stats table

When using the esbuild-based browser application builder, the stat output table was incorrectly
displaying source map files and internal component resource files such as inline stylesheets
as initial entries.
  • Loading branch information
clydin authored and angular-robot[bot] committed Apr 3, 2023
1 parent bff634f commit b8c9667
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,20 @@ export default createBuilder(buildEsbuildBrowser);

function logBuildStats(context: BuilderContext, metafile: Metafile) {
const stats: BundleStats[] = [];
for (const [file, { bytes, entryPoint }] of Object.entries(metafile.outputs)) {
for (const [file, output] of Object.entries(metafile.outputs)) {
// Skip sourcemaps
if (file.endsWith('.map')) {
continue;
}
// Skip internal component resources
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((output as any)['ng-component']) {
continue;
}

stats.push({
initial: !!entryPoint,
stats: [file, '', bytes, ''],
initial: !!output.entryPoint,
stats: [file, '', output.bytes, ''],
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,25 @@ export async function bundleComponentStylesheet(
}
}

let metafile;
if (!result.errors) {
metafile = result.metafile;
// Remove entryPoint fields from outputs to prevent the internal component styles from being
// treated as initial files. Also mark the entry as a component resource for stat reporting.
Object.values(metafile.outputs).forEach((output) => {
delete output.entryPoint;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(output as any)['ng-component'] = true;
});
}

return {
errors: result.errors,
warnings: result.warnings,
contents,
map,
path: outputPath,
resourceFiles,
metafile: result.errors ? undefined : result.metafile,
metafile,
};
}

0 comments on commit b8c9667

Please sign in to comment.