Skip to content

Commit eb6d6df

Browse files
committed
fixup! fix(@angular/build): improve library compilation diagnostics and stylesheet reference tracking
1 parent de9eae8 commit eb6d6df

2 files changed

Lines changed: 36 additions & 29 deletions

File tree

‎packages/angular/build/src/builders/library/pipeline/compilation.ts‎

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { type PartialMessage, formatMessages } from 'esbuild';
10-
import { existsSync } from 'node:fs';
10+
import { access, constants } from 'node:fs/promises';
1111
import {
1212
type AngularCompilation,
1313
DiagnosticModes,
@@ -172,7 +172,7 @@ export async function compileLibrary(
172172
const esmFiles = cached?.esmFiles ?? new Map<string, string>();
173173
const dtsFiles = cached?.dtsFiles ?? new Map<string, string>();
174174
const posixReferencedFiles = new Set(referencedFiles.map(toPosixPath));
175-
const { changedEsmFiles, changedDtsFiles } = updateEmittedFileCaches(
175+
const { changedEsmFiles, changedDtsFiles } = await updateEmittedFileCaches(
176176
emittedFiles,
177177
esmFiles,
178178
dtsFiles,
@@ -216,40 +216,49 @@ export async function compileLibrary(
216216
* @param modifiedFiles Optional set of modified POSIX file paths in incremental builds.
217217
* @returns Sets of changed ESM and DTS file paths.
218218
*/
219-
function updateEmittedFileCaches(
219+
async function updateEmittedFileCaches(
220220
emittedFiles: Iterable<EmitFileResult>,
221221
esmFiles: Map<string, string>,
222222
dtsFiles: Map<string, string>,
223223
posixReferencedFiles: ReadonlySet<string>,
224224
modifiedFiles?: ReadonlySet<string>,
225-
): { changedEsmFiles: Set<string>; changedDtsFiles: Set<string> } {
225+
): Promise<{ changedEsmFiles: Set<string>; changedDtsFiles: Set<string> }> {
226226
const changedEsmFiles = new Set<string>();
227227
const changedDtsFiles = new Set<string>();
228228

229-
if (modifiedFiles) {
230-
for (const modifiedFile of modifiedFiles) {
231-
if (posixReferencedFiles.has(modifiedFile)) {
232-
continue;
233-
}
234-
235-
const basePathWithoutExt = modifiedFile.replace(/(?:\.d\.[cm]?ts|\.[cm]?[jt]sx?)$/i, '');
236-
if (basePathWithoutExt === modifiedFile || existsSync(modifiedFile)) {
237-
continue;
238-
}
229+
const removalChecks: Promise<void>[] = [];
230+
for (const modifiedFile of modifiedFiles ?? []) {
231+
if (posixReferencedFiles.has(modifiedFile)) {
232+
continue;
233+
}
239234

240-
for (const ext of EMITTED_EXTENSIONS) {
241-
const outputPath = `${basePathWithoutExt}${ext}`;
242-
const mapPath = `${outputPath}.map`;
243-
if (esmFiles.delete(outputPath)) {
244-
changedEsmFiles.add(outputPath);
245-
}
246-
if (dtsFiles.delete(outputPath)) {
247-
changedDtsFiles.add(outputPath);
248-
}
249-
esmFiles.delete(mapPath);
250-
dtsFiles.delete(mapPath);
251-
}
235+
const basePathWithoutExt = modifiedFile.replace(/(?:\.d\.[cm]?ts|\.[cm]?[jt]sx?)$/i, '');
236+
if (basePathWithoutExt === modifiedFile) {
237+
continue;
252238
}
239+
240+
removalChecks.push(
241+
access(modifiedFile, constants.F_OK).then(
242+
() => {},
243+
() => {
244+
for (const ext of EMITTED_EXTENSIONS) {
245+
const outputPath = `${basePathWithoutExt}${ext}`;
246+
const mapPath = `${outputPath}.map`;
247+
if (esmFiles.delete(outputPath)) {
248+
changedEsmFiles.add(outputPath);
249+
}
250+
if (dtsFiles.delete(outputPath)) {
251+
changedDtsFiles.add(outputPath);
252+
}
253+
esmFiles.delete(mapPath);
254+
dtsFiles.delete(mapPath);
255+
}
256+
},
257+
),
258+
);
259+
}
260+
if (removalChecks.length > 0) {
261+
await Promise.all(removalChecks);
253262
}
254263

255264
for (const { filename, contents } of emittedFiles) {
@@ -301,9 +310,8 @@ async function runDiagnosticsAndFormat(
301310
} catch (error) {
302311
assertIsError(error);
303312
errors.push({
304-
text: 'Angular compilation diagnostics failed.',
313+
text: error.message,
305314
location: null,
306-
notes: [{ text: error.stack ?? error.message, location: null }],
307315
});
308316
}
309317

‎packages/angular/build/src/builders/library/pipeline/compilation_spec.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ describe('compileLibrary pipeline', () => {
212212

213213
const errorsText = state.executionResult.errors.join('\n');
214214
expect(errorsText).toContain('Sass syntax error');
215-
expect(errorsText).toContain('Angular compilation diagnostics failed.');
216215
expect(errorsText).toContain('Diagnostic crash');
217216
});
218217

0 commit comments

Comments
 (0)