Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,60 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
harness.expectFile('dist/server-stats.json').toNotExist();
});

it('attributes a shared component stylesheet output to the same input on every build', async () => {
// Two components in different directories with byte-identical stylesheets of the same
// file name bundle to the same output file. The merged metafile must attribute that output
// to the same input regardless of which stylesheet bundle finishes first.
const component = (dir: string) => `
import { Component } from '@angular/core';
@Component({
selector: 'app-shared-${dir}',
template: '<p>${dir}</p>',
styleUrl: './shared.css',
})
export class Shared${dir.toUpperCase()}Component {}
`;
await harness.writeFiles({
'src/app/a/shared.component.ts': component('a'),
'src/app/a/shared.css': 'p { color: red; }',
'src/app/b/shared.component.ts': component('b'),
'src/app/b/shared.css': 'p { color: red; }',
});
await harness.writeFile(
'src/app/app.module.ts',
`
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { SharedAComponent } from './a/shared.component';
import { SharedBComponent } from './b/shared.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, SharedAComponent, SharedBComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
`,
);
await harness.writeFile(
'src/app/app.component.html',
'<app-shared-a></app-shared-a><app-shared-b></app-shared-b>',
);

harness.useTarget('build', {
...BASE_OPTIONS,
statsJson: true,
});

for (let i = 0; i < 2; i++) {
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

const stats = JSON.parse(harness.readFile('dist/browser-stats.json'));
expect(Object.keys(stats.outputs['shared.css'].inputs)).toEqual(['src/app/b/shared.css']);
Comment thread
alan-agius4 marked this conversation as resolved.
Outdated
}
});

describe('server build', () => {
beforeEach(async () => {
await harness.modifyFile('src/tsconfig.app.json', (content) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,12 @@ export function createCompilerPlugin(
angularCompilationContext.markAsReady(hasCompilationErrors);
}

for (const { outputFiles, metafile } of additionalResults.values()) {
// Merge in key order: the map fills in completion order, and when two entries share an
// output file the last one merged wins, so the metafile would otherwise vary between builds.
const sortedResults = [...additionalResults].sort(([a], [b]) =>
a < b ? -1 : a > b ? 1 : 0,
);
for (const [, { outputFiles, metafile }] of sortedResults) {
// Add any additional output files to the main output files
if (outputFiles?.length) {
result.outputFiles?.push(...outputFiles);
Expand Down
Loading