Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 33 additions & 0 deletions src/tools/esbuild/angular-esbuild-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,39 @@ describe('createAngularBuildAdapter', () => {
expect(fs.writeFileSync).toHaveBeenCalledWith('/out/logo.png', png);
});

// #195: @angular/build 22.2.5 also bundles an empty external stylesheet, so a component with
// inline styles and an empty styleUrl emits two `app.component.css.map` outputs. Core rejects
// two results for one name once `entry` is set.
it('reports a path written twice once, with the last contents on disk', async () => {
const ctx = makeCtx();
const inlineMap = new TextEncoder().encode('{"sources":["inline"]}');
const emptyMap = new TextEncoder().encode('{"sources":[]}');
ctx.rebuild.mockResolvedValue({
outputFiles: [
{ path: '/ws/app.component.css.map', contents: inlineMap },
{ path: '/ws/app.component.css.map', contents: emptyMap },
{ path: '/ws/dist/main.js', contents: new Uint8Array() },
],
});
vi.mocked(createAngularEsbuildContext).mockResolvedValue({
ctx,
pluginDisposed: Promise.resolve(),
} as never);
const adapter = await createAngularBuildAdapter(ngBuilderOptions, context);
await adapter.setup('remote', {} as never);

const result = await adapter.build('remote');

expect(result).toEqual([
{ fileName: '/out/app.component.css.map' },
{ fileName: '/out/main.js' },
]);
expect(vi.mocked(fs.writeFileSync).mock.calls.at(1)).toEqual([
'/out/app.component.css.map',
emptyMap,
]);
});

it('invalidates the bundler cache for modified files before rebuilding', async () => {
const normalized = normalizedWith();
vi.mocked(normalizeContextOptions).mockReturnValue(normalized as never);
Expand Down
8 changes: 5 additions & 3 deletions src/tools/esbuild/angular-esbuild-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ function writeOutputs(
outdir: string,
entryByOutputName: Map<string, string>
): NFBuildAdapterResult[] {
const writtenFiles: NFBuildAdapterResult[] = [];
// Component stylesheets with the same basename each emit `<name>.css.map` (#195); report the
// path once, as the file the last write left on disk.
const writtenFiles = new Map<string, NFBuildAdapterResult>();

for (const outFile of result.outputFiles ?? []) {
const fileName = path.basename(outFile.path);
const filePath = path.join(outdir, fileName);
fs.writeFileSync(filePath, outFile.contents);
const entry = entryByOutputName.get(fileName);
writtenFiles.push(entry ? { fileName: filePath, entry } : { fileName: filePath });
writtenFiles.set(filePath, entry ? { fileName: filePath, entry } : { fileName: filePath });
}

return writtenFiles;
return [...writtenFiles.values()];
}

export interface AngularBuildAdapter extends NFBuildAdapter {
Expand Down
Loading