|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import { type PartialMessage, formatMessages } from 'esbuild'; |
10 | | -import { existsSync } from 'node:fs'; |
| 10 | +import { access, constants } from 'node:fs/promises'; |
11 | 11 | import { |
12 | 12 | type AngularCompilation, |
13 | 13 | DiagnosticModes, |
@@ -172,7 +172,7 @@ export async function compileLibrary( |
172 | 172 | const esmFiles = cached?.esmFiles ?? new Map<string, string>(); |
173 | 173 | const dtsFiles = cached?.dtsFiles ?? new Map<string, string>(); |
174 | 174 | const posixReferencedFiles = new Set(referencedFiles.map(toPosixPath)); |
175 | | - const { changedEsmFiles, changedDtsFiles } = updateEmittedFileCaches( |
| 175 | + const { changedEsmFiles, changedDtsFiles } = await updateEmittedFileCaches( |
176 | 176 | emittedFiles, |
177 | 177 | esmFiles, |
178 | 178 | dtsFiles, |
@@ -216,40 +216,49 @@ export async function compileLibrary( |
216 | 216 | * @param modifiedFiles Optional set of modified POSIX file paths in incremental builds. |
217 | 217 | * @returns Sets of changed ESM and DTS file paths. |
218 | 218 | */ |
219 | | -function updateEmittedFileCaches( |
| 219 | +async function updateEmittedFileCaches( |
220 | 220 | emittedFiles: Iterable<EmitFileResult>, |
221 | 221 | esmFiles: Map<string, string>, |
222 | 222 | dtsFiles: Map<string, string>, |
223 | 223 | posixReferencedFiles: ReadonlySet<string>, |
224 | 224 | modifiedFiles?: ReadonlySet<string>, |
225 | | -): { changedEsmFiles: Set<string>; changedDtsFiles: Set<string> } { |
| 225 | +): Promise<{ changedEsmFiles: Set<string>; changedDtsFiles: Set<string> }> { |
226 | 226 | const changedEsmFiles = new Set<string>(); |
227 | 227 | const changedDtsFiles = new Set<string>(); |
228 | 228 |
|
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 | + } |
239 | 234 |
|
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; |
252 | 238 | } |
| 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); |
253 | 262 | } |
254 | 263 |
|
255 | 264 | for (const { filename, contents } of emittedFiles) { |
@@ -301,9 +310,8 @@ async function runDiagnosticsAndFormat( |
301 | 310 | } catch (error) { |
302 | 311 | assertIsError(error); |
303 | 312 | errors.push({ |
304 | | - text: 'Angular compilation diagnostics failed.', |
| 313 | + text: error.message, |
305 | 314 | location: null, |
306 | | - notes: [{ text: error.stack ?? error.message, location: null }], |
307 | 315 | }); |
308 | 316 | } |
309 | 317 |
|
|
0 commit comments