Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83e0e9b5dd | |||
| 094f9df55f | |||
| a6a006aaec | |||
| 9477875c1d | |||
| 2b73f3d582 | |||
| 0ffdcf852f | |||
| f8f20be4f4 | |||
| fb5421a8c4 | |||
| 79d48b0875 | |||
| 8977ff4525 | |||
| 9dc74fd392 | |||
| 85a33021e4 | |||
| e8e64a4ef3 |
42
changelog.md
42
changelog.md
@@ -1,5 +1,47 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-03-05 - 4.2.6 - fix(meta)
|
||||
no changes
|
||||
|
||||
- Current package version: 4.2.5
|
||||
- No code or file changes detected in this commit; no release required
|
||||
|
||||
## 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
|
||||
|
||||
- Comment-only change in ts/mod_fs/classes.fshelpers.ts; no runtime or API behavior changes
|
||||
- Bump patch version from 4.2.3 to 4.2.4
|
||||
|
||||
## 2026-03-05 - 4.2.3 - fix(compiler)
|
||||
defer unpacking until after all compilations and remove diagnostic filesystem syncs to avoid XFS metadata visibility issues
|
||||
|
||||
- Queue pending unpack operations during compilation and run them after all compile tasks complete to avoid modifying output directories while other compilations are writing.
|
||||
- Remove TypeScript sys interception, execSync('sync') calls, and per-unpack fs.fsyncSync usage that attempted to work around XFS delayed metadata commits; rely on performing all unpacks after compilation instead.
|
||||
- Clean up noisy diagnostic code (external 'ls' comparisons, readdir snapshots) and simplify logging of unpack results.
|
||||
- Remove unused imports (fs and child_process.execSync) from the compiler module.
|
||||
|
||||
## 2026-03-05 - 4.2.2 - fix(compiler)
|
||||
force global filesystem sync to flush XFS delayed logging and add diagnostics comparing Node's readdirSync with system ls to detect directory entry inconsistencies
|
||||
|
||||
- Replace per-directory fs.fsyncSync loop with execSync('sync') to ensure parent B+tree metadata is flushed on XFS
|
||||
- Import execSync from child_process
|
||||
- Add diagnostic comparison: run ls -1 and compare its entries to fs.readdirSync; log mismatches and full entry lists for debugging Node.js caching/readdir inconsistencies
|
||||
|
||||
## 2026-03-05 - 4.2.1 - fix(compiler)
|
||||
use TypeScript sys hooks instead of fs monkeypatching to detect writes/deletes in previous output directories
|
||||
|
||||
- Replace direct fs.* monkeypatching with interception of typescript.sys.writeFile, typescript.sys.deleteFile and typescript.sys.createDirectory
|
||||
- Add guards for optional sys.deleteFile before overriding it and preserve original sys methods to restore after compilation
|
||||
- Update diagnostic messages to reference TypeScript sys ops and add an informational message when no ops are observed
|
||||
- Reduce surface area of changes by avoiding global fs changes and focusing on TypeScript's sys API for safer interception
|
||||
|
||||
## 2026-03-05 - 4.2.0 - feat(mod_compiler)
|
||||
add diagnostic interception of fs operations to detect and report unexpected file system changes in previously compiled output directories during compilation
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tsbuild",
|
||||
"version": "4.2.0",
|
||||
"version": "4.2.6",
|
||||
"private": false,
|
||||
"description": "A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.",
|
||||
"main": "dist_ts/index.js",
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsbuild',
|
||||
version: '4.2.0',
|
||||
version: '4.2.6',
|
||||
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { CompilerOptions, Diagnostic, Program } from 'typescript';
|
||||
import typescript from 'typescript';
|
||||
import * as fs from 'fs';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
@@ -245,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<void>((resolve) => process.nextTick(resolve));
|
||||
|
||||
const emitErrorSummary = this.processDiagnostics(emitResult.diagnostics);
|
||||
|
||||
// Combine error summaries
|
||||
@@ -325,49 +330,42 @@ export class TsCompiler {
|
||||
console.log('');
|
||||
}
|
||||
|
||||
// Phase 1: Resolve glob patterns and clean ALL output directories upfront.
|
||||
// This ensures no rm/rmSync activity overlaps with TypeScript compilation,
|
||||
// preventing XFS metadata corruption from concurrent metadata operations.
|
||||
interface IResolvedTask {
|
||||
pattern: string;
|
||||
destPath: string;
|
||||
destDir: string;
|
||||
absoluteFiles: string[];
|
||||
}
|
||||
const resolvedTasks: IResolvedTask[] = [];
|
||||
|
||||
for (const pattern of Object.keys(globPatterns)) {
|
||||
const destPath = globPatterns[pattern];
|
||||
if (!pattern || !destPath) continue;
|
||||
|
||||
// Get files matching the glob pattern
|
||||
const files = await FsHelpers.listFilesWithGlob(this.cwd, pattern);
|
||||
|
||||
// Transform to absolute paths
|
||||
const absoluteFiles = smartpath.transform.toAbsolute(files, this.cwd) as string[];
|
||||
|
||||
// Get destination directory as absolute path
|
||||
const destDir = smartpath.transform.toAbsolute(destPath, this.cwd) as string;
|
||||
|
||||
// Diagnostic helper
|
||||
const diagSnap = (label: string) => {
|
||||
if (!isQuiet && !isJson) {
|
||||
for (const prevDir of successfulOutputDirs) {
|
||||
try {
|
||||
const entries = fs.readdirSync(prevDir);
|
||||
const dirs = entries.filter(e => { try { return fs.statSync(prevDir + '/' + e).isDirectory(); } catch { return false; } });
|
||||
const shortDir = prevDir.replace(this.cwd + '/', '');
|
||||
console.log(` 📋 [${label}] ${shortDir}: ${entries.length} entries, ${dirs.length} dirs [${entries.sort().join(', ')}]`);
|
||||
} catch {
|
||||
console.log(` 📋 [${label}] ${prevDir.replace(this.cwd + '/', '')}: MISSING!`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Clear the destination directory before compilation if it exists
|
||||
diagSnap('pre-clear');
|
||||
if (await FsHelpers.directoryExists(destDir)) {
|
||||
if (!isQuiet && !isJson) {
|
||||
console.log(`🧹 Clearing output directory: ${destPath}`);
|
||||
}
|
||||
await FsHelpers.removeDirectory(destDir);
|
||||
}
|
||||
diagSnap('post-clear');
|
||||
|
||||
// Update compiler options with the output directory
|
||||
resolvedTasks.push({ pattern, destPath, destDir, absoluteFiles });
|
||||
}
|
||||
|
||||
// Phase 2: Compile all tasks. No filesystem cleanup happens during this phase.
|
||||
const pendingUnpacks: Array<{ pattern: string; destDir: string }> = [];
|
||||
|
||||
for (const task of resolvedTasks) {
|
||||
const options: CompilerOptions = {
|
||||
...customOptions,
|
||||
outDir: destDir,
|
||||
outDir: task.destDir,
|
||||
listEmittedFiles: true,
|
||||
};
|
||||
|
||||
@@ -375,125 +373,26 @@ export class TsCompiler {
|
||||
const taskInfo: ITaskInfo = {
|
||||
taskNumber: currentTask,
|
||||
totalTasks,
|
||||
sourcePattern: pattern,
|
||||
destDir: destPath,
|
||||
fileCount: absoluteFiles.length,
|
||||
sourcePattern: task.pattern,
|
||||
destDir: task.destPath,
|
||||
fileCount: task.absoluteFiles.length,
|
||||
};
|
||||
|
||||
// Diagnostic: intercept fs operations during compilation to detect
|
||||
// any unexpected deletions in previously compiled output directories
|
||||
const watchedDirs = successfulOutputDirs.filter(d => d !== destDir);
|
||||
const origUnlink = fs.unlinkSync;
|
||||
const origRm = fs.rmSync;
|
||||
const origRmdir = fs.rmdirSync;
|
||||
const origRename = fs.renameSync;
|
||||
const origWriteFile = fs.writeFileSync;
|
||||
let interceptedOps: string[] = [];
|
||||
if (watchedDirs.length > 0 && !isQuiet && !isJson) {
|
||||
(fs as any).unlinkSync = (p: string, ...args: any[]) => {
|
||||
if (watchedDirs.some(d => String(p).startsWith(d + '/'))) {
|
||||
interceptedOps.push(`unlink: ${p}`);
|
||||
}
|
||||
return origUnlink.call(fs, p, ...args);
|
||||
};
|
||||
(fs as any).rmSync = (p: string, ...args: any[]) => {
|
||||
if (watchedDirs.some(d => String(p).startsWith(d + '/'))) {
|
||||
interceptedOps.push(`rm: ${p}`);
|
||||
}
|
||||
return origRm.call(fs, p, ...args);
|
||||
};
|
||||
(fs as any).rmdirSync = (p: string, ...args: any[]) => {
|
||||
if (watchedDirs.some(d => String(p).startsWith(d + '/'))) {
|
||||
interceptedOps.push(`rmdir: ${p}`);
|
||||
}
|
||||
return origRmdir.call(fs, p, ...args);
|
||||
};
|
||||
(fs as any).renameSync = (src: string, dest: string, ...args: any[]) => {
|
||||
if (watchedDirs.some(d => String(src).startsWith(d + '/') || String(dest).startsWith(d + '/'))) {
|
||||
interceptedOps.push(`rename: ${src} → ${dest}`);
|
||||
}
|
||||
return origRename.call(fs, src, dest, ...args);
|
||||
};
|
||||
(fs as any).writeFileSync = (p: string, ...args: any[]) => {
|
||||
if (watchedDirs.some(d => String(p).startsWith(d + '/'))) {
|
||||
interceptedOps.push(`write: ${p}`);
|
||||
}
|
||||
return origWriteFile.call(fs, p, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
const result = await this.compileFiles(absoluteFiles, options, taskInfo);
|
||||
const result = await this.compileFiles(task.absoluteFiles, options, taskInfo);
|
||||
emittedFiles.push(...result.emittedFiles);
|
||||
errorSummaries.push(result.errorSummary);
|
||||
|
||||
// Restore original fs methods and report any intercepted operations
|
||||
if (watchedDirs.length > 0 && !isQuiet && !isJson) {
|
||||
(fs as any).unlinkSync = origUnlink;
|
||||
(fs as any).rmSync = origRm;
|
||||
(fs as any).rmdirSync = origRmdir;
|
||||
(fs as any).renameSync = origRename;
|
||||
(fs as any).writeFileSync = origWriteFile;
|
||||
if (interceptedOps.length > 0) {
|
||||
console.log(` ⚠️ [diag] ${interceptedOps.length} ops on previous output dirs during compilation:`);
|
||||
for (const op of interceptedOps.slice(0, 30)) {
|
||||
console.log(` ${op.replace(this.cwd + '/', '')}`);
|
||||
}
|
||||
if (interceptedOps.length > 30) {
|
||||
console.log(` ... and ${interceptedOps.length - 30} more`);
|
||||
}
|
||||
}
|
||||
}
|
||||
diagSnap('post-compile');
|
||||
|
||||
// Diagnostic: log emitted files that went to unexpected directories
|
||||
if (!isQuiet && !isJson && result.emittedFiles.length > 0) {
|
||||
const unexpectedFiles = result.emittedFiles.filter(f => !f.startsWith(destDir + '/') && !f.startsWith(destDir + '\\'));
|
||||
if (unexpectedFiles.length > 0) {
|
||||
console.log(` ⚠️ [diag] ${unexpectedFiles.length} files emitted OUTSIDE ${destPath}:`);
|
||||
for (const f of unexpectedFiles.slice(0, 20)) {
|
||||
console.log(` ${f.replace(this.cwd + '/', '')}`);
|
||||
}
|
||||
if (unexpectedFiles.length > 20) {
|
||||
console.log(` ... and ${unexpectedFiles.length - 20} more`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform unpack if compilation succeeded
|
||||
if (result.errorSummary.totalErrors === 0) {
|
||||
await performUnpack(pattern, destDir, this.cwd);
|
||||
successfulOutputDirs.push(destDir);
|
||||
}
|
||||
|
||||
// Fsync all output directories to force XFS metadata commit
|
||||
// before the next compilation step. Without this, XFS delayed logging
|
||||
// can cause directory entries from previous compilations to become
|
||||
// invisible or corrupted during subsequent TypeScript emit operations.
|
||||
for (const dir of successfulOutputDirs) {
|
||||
try {
|
||||
const fd = fs.openSync(dir, 'r');
|
||||
fs.fsyncSync(fd);
|
||||
fs.closeSync(fd);
|
||||
} catch {
|
||||
// Directory might not exist yet
|
||||
}
|
||||
}
|
||||
|
||||
// Diagnostic: log all output directory states after each compilation
|
||||
if (!isQuiet && !isJson) {
|
||||
for (const prevDir of successfulOutputDirs) {
|
||||
try {
|
||||
const entries = fs.readdirSync(prevDir);
|
||||
const dirs = entries.filter(e => {
|
||||
try { return fs.statSync(prevDir + '/' + e).isDirectory(); } catch { return false; }
|
||||
});
|
||||
console.log(` 📋 [diag] ${prevDir.replace(this.cwd + '/', '')}: ${entries.length} entries, ${dirs.length} dirs`);
|
||||
} catch {
|
||||
console.log(` 📋 [diag] ${prevDir.replace(this.cwd + '/', '')}: MISSING!`);
|
||||
}
|
||||
}
|
||||
pendingUnpacks.push({ pattern: task.pattern, destDir: task.destDir });
|
||||
successfulOutputDirs.push(task.destDir);
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 3: Perform all unpacks after all compilations are done.
|
||||
// This ensures no output directory is modified while subsequent compilations
|
||||
// are performing heavy filesystem writes to sibling directories.
|
||||
for (const { pattern, destDir } of pendingUnpacks) {
|
||||
await performUnpack(pattern, destDir, this.cwd);
|
||||
}
|
||||
|
||||
// Rewrite import paths in all output directories to handle cross-module references
|
||||
@@ -508,21 +407,6 @@ export class TsCompiler {
|
||||
if (totalRewritten > 0 && !isQuiet && !isJson) {
|
||||
console.log(` 🔄 Rewrote import paths in ${totalRewritten} file${totalRewritten !== 1 ? 's' : ''}`);
|
||||
}
|
||||
|
||||
// Diagnostic: log output directory states after path rewriting
|
||||
if (!isQuiet && !isJson) {
|
||||
for (const dir of successfulOutputDirs) {
|
||||
try {
|
||||
const entries = fs.readdirSync(dir);
|
||||
const dirs = entries.filter(e => {
|
||||
try { return fs.statSync(dir + '/' + e).isDirectory(); } catch { return false; }
|
||||
});
|
||||
console.log(` 📋 [diag-post-rewrite] ${dir.replace(this.cwd + '/', '')}: ${entries.length} entries, ${dirs.length} dirs`);
|
||||
} catch {
|
||||
console.log(` 📋 [diag-post-rewrite] ${dir.replace(this.cwd + '/', '')}: MISSING!`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge all error summaries
|
||||
|
||||
@@ -123,9 +123,6 @@ export class FsHelpers {
|
||||
|
||||
/**
|
||||
* Remove a directory recursively.
|
||||
* Uses synchronous rm to avoid XFS metadata corruption observed with
|
||||
* async fs.promises.rm affecting sibling directory entries on the
|
||||
* libuv thread pool under signal pressure.
|
||||
*/
|
||||
public static async removeDirectory(dirPath: string): Promise<void> {
|
||||
fs.rmSync(dirPath, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
||||
|
||||
@@ -90,9 +90,9 @@ export class TsUnpacker {
|
||||
* 2. Moving contents of the nested source folder up to the dest dir
|
||||
* 3. Removing the now-empty nested source folder
|
||||
*
|
||||
* Uses synchronous fs operations to avoid race conditions with
|
||||
* async readdir returning partial/stale results under signal pressure
|
||||
* or XFS metadata lag (observed in process-group environments like gitzone).
|
||||
* Uses synchronous fs operations for reliability.
|
||||
* Called after all compilations are complete (not between compilations)
|
||||
* to avoid filesystem metadata issues on XFS.
|
||||
*
|
||||
* Returns true if unpacking was performed, false if skipped.
|
||||
*/
|
||||
@@ -107,17 +107,6 @@ export class TsUnpacker {
|
||||
|
||||
const nestedPath = this.getNestedPath();
|
||||
|
||||
// Force XFS to flush pending directory metadata before reading.
|
||||
// XFS delayed logging (CIL) can defer metadata commits, causing
|
||||
// readdirSync/opendirSync to return incomplete results immediately
|
||||
// after TypeScript's emit() creates files via writeFileSync.
|
||||
const destFd = fs.openSync(this.destDir, 'r');
|
||||
fs.fsyncSync(destFd);
|
||||
fs.closeSync(destFd);
|
||||
const nestedFd = fs.openSync(nestedPath, 'r');
|
||||
fs.fsyncSync(nestedFd);
|
||||
fs.closeSync(nestedFd);
|
||||
|
||||
// Step 1: Remove sibling entries (everything in dest except the source folder)
|
||||
const destEntries = fs.readdirSync(this.destDir);
|
||||
for (const entry of destEntries) {
|
||||
@@ -138,9 +127,7 @@ export class TsUnpacker {
|
||||
// Step 3: Remove the now-empty nested directory
|
||||
fs.rmdirSync(nestedPath);
|
||||
|
||||
// Diagnostic: verify final state
|
||||
const finalEntries = fs.readdirSync(this.destDir);
|
||||
console.log(` 📦 Unpacked ${this.sourceFolderName}: moved ${nestedEntries.length} entries, final: ${finalEntries.length} entries`);
|
||||
console.log(` 📦 Unpacked ${this.sourceFolderName}: ${nestedEntries.length} entries`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user