From 2b73f3d5820def4ff9c7ece5769fcfd2c35b0fbc Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 5 Mar 2026 16:03:49 +0000 Subject: [PATCH] fix(compiler): yield to the event loop after TypeScript emit to allow pending microtasks and I/O to settle before reading or modifying the output directory --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/mod_compiler/classes.tscompiler.ts | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d3dd682..18f2ae6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-03-05 - 4.2.5 - fix(compiler) +yield to the event loop after TypeScript emit to allow pending microtasks and I/O to settle before reading or modifying the output directory + +- Added await new Promise(resolve => process.nextTick(resolve)) immediately after program.emit() +- Prevents race conditions by allowing libuv write completions and other deferred callbacks to complete before accessing the output directory +- File changed: ts/mod_compiler/classes.tscompiler.ts + ## 2026-03-05 - 4.2.4 - fix(fshelpers) remove outdated comment about using synchronous rm to avoid XFS metadata corruption diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2e881d3..3e13296 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbuild', - version: '4.2.4', + version: '4.2.5', description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.' } diff --git a/ts/mod_compiler/classes.tscompiler.ts b/ts/mod_compiler/classes.tscompiler.ts index 9ef550c..a76d188 100644 --- a/ts/mod_compiler/classes.tscompiler.ts +++ b/ts/mod_compiler/classes.tscompiler.ts @@ -244,6 +244,12 @@ export class TsCompiler { // If no pre-emit errors, proceed with emit const emitResult = program.emit(); + + // Yield to the event loop so any pending microtasks, nextTick callbacks, + // or deferred I/O from TypeScript's emit (e.g. libuv write completions) + // can settle before we read or modify the output directory. + await new Promise((resolve) => process.nextTick(resolve)); + const emitErrorSummary = this.processDiagnostics(emitResult.diagnostics); // Combine error summaries