Compare commits

..

10 Commits

5 changed files with 93 additions and 10 deletions

View File

@@ -1,5 +1,41 @@
# Changelog # Changelog
## 2026-03-05 - 4.1.24 - fix(mod_unpack)
iterate directories with opendirSync/readSync to avoid missing entries on XFS and ensure directory handles are closed
- Replaced readdirSync loops with opendirSync + readSync for destination and nested directories to provide a single stable directory handle during iteration
- Added explicit closeSync() calls to close directory handles and avoid resource leaks
- Avoids partial results/missed entries that can occur when repeatedly calling readdirSync (observed on XFS with delayed metadata)
- Preserves existing renameSync move logic and increments moved counter while cleaning up the now-empty nested directory
## 2026-03-05 - 4.1.23 - fix(mod_unpack)
handle partial readdirSync results when moving nested directory entries and add diagnostic log
- Loop over readdirSync results until the nested directory is empty to avoid missing entries from partial reads
- Count moved entries and print a diagnostic message with the final destination entry count
- Keep removal of the now-empty nested directory (fs.rmdirSync) after moving contents
## 2026-03-05 - 4.1.22 - fix(mod_compiler)
improve logging of successful output directories to include a sorted list of entries and use a shortened relative path
- Adds shortDir variable to display relative path instead of repeating inline replace(this.cwd + '/')
- Appends a sorted, comma-separated list of directory entries to the log output for easier inspection
- Change located in ts/mod_compiler/classes.tscompiler.ts
## 2026-03-05 - 4.1.21 - fix(compiler)
log emitted files written outside expected destination directory for diagnostics
- Adds diagnostic logging for emitted files that are not under the configured destDir, listing up to 20 example paths and reporting the remaining count.
- Logging is conditional: only when not in quiet mode and not emitting JSON.
- Diagnostic runs after compilation (post-compile) and before unpacking of outputs; paths are trimmed using the process cwd for readability.
## 2026-03-05 - 4.1.20 - fix(mod_compiler)
add diagnostic snapshots for output directories around clear and compile steps
- Introduce diagSnap helper to log entry and directory counts for successful output directories when not in quiet or JSON mode
- Call diagSnap before clearing the destination directory, after clearing, and after compilation to aid debugging of missing or unexpected outputs
- Behavior for emitted files and unpacking is unchanged; this is observational/logging-only instrumentation
## 2026-03-05 - 4.1.19 - fix(mod_fs) ## 2026-03-05 - 4.1.19 - fix(mod_fs)
use synchronous rm to avoid XFS metadata corruption when removing directories use synchronous rm to avoid XFS metadata corruption when removing directories

View File

@@ -1,6 +1,6 @@
{ {
"name": "@git.zone/tsbuild", "name": "@git.zone/tsbuild",
"version": "4.1.19", "version": "4.1.24",
"private": false, "private": false,
"description": "A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.", "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", "main": "dist_ts/index.js",

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tsbuild', name: '@git.zone/tsbuild',
version: '4.1.19', version: '4.1.24',
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.' description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
} }

View File

@@ -338,13 +338,31 @@ export class TsCompiler {
// Get destination directory as absolute path // Get destination directory as absolute path
const destDir = smartpath.transform.toAbsolute(destPath, this.cwd) as string; 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 // Clear the destination directory before compilation if it exists
diagSnap('pre-clear');
if (await FsHelpers.directoryExists(destDir)) { if (await FsHelpers.directoryExists(destDir)) {
if (!isQuiet && !isJson) { if (!isQuiet && !isJson) {
console.log(`🧹 Clearing output directory: ${destPath}`); console.log(`🧹 Clearing output directory: ${destPath}`);
} }
await FsHelpers.removeDirectory(destDir); await FsHelpers.removeDirectory(destDir);
} }
diagSnap('post-clear');
// Update compiler options with the output directory // Update compiler options with the output directory
const options: CompilerOptions = { const options: CompilerOptions = {
@@ -365,6 +383,21 @@ export class TsCompiler {
const result = await this.compileFiles(absoluteFiles, options, taskInfo); const result = await this.compileFiles(absoluteFiles, options, taskInfo);
emittedFiles.push(...result.emittedFiles); emittedFiles.push(...result.emittedFiles);
errorSummaries.push(result.errorSummary); errorSummaries.push(result.errorSummary);
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 // Perform unpack if compilation succeeded
if (result.errorSummary.totalErrors === 0) { if (result.errorSummary.totalErrors === 0) {

View File

@@ -108,25 +108,39 @@ export class TsUnpacker {
const nestedPath = this.getNestedPath(); const nestedPath = this.getNestedPath();
// Step 1: Remove sibling entries (everything in dest except the source folder) // Step 1: Remove sibling entries (everything in dest except the source folder)
const destEntries = fs.readdirSync(this.destDir); // Use opendirSync to keep a single directory handle open for reliable iteration
for (const entry of destEntries) { const destDir = fs.opendirSync(this.destDir);
if (entry !== this.sourceFolderName) { let destEntry;
fs.rmSync(path.join(this.destDir, entry), { recursive: true, force: true }); while ((destEntry = destDir.readSync()) !== null) {
if (destEntry.name !== this.sourceFolderName) {
fs.rmSync(path.join(this.destDir, destEntry.name), { recursive: true, force: true });
} }
} }
destDir.closeSync();
// Step 2: Move all contents from nested dir up to dest dir // Step 2: Move all contents from nested dir up to dest dir
const nestedEntries = fs.readdirSync(nestedPath); // Use opendirSync to keep a single directory handle open — this avoids
for (const entry of nestedEntries) { // partial results from readdirSync which opens a fresh file descriptor
// each call and can miss entries on XFS with delayed metadata logging
const nestedDir = fs.opendirSync(nestedPath);
let nestedEntry;
let moved = 0;
while ((nestedEntry = nestedDir.readSync()) !== null) {
fs.renameSync( fs.renameSync(
path.join(nestedPath, entry), path.join(nestedPath, nestedEntry.name),
path.join(this.destDir, entry), path.join(this.destDir, nestedEntry.name),
); );
moved++;
} }
nestedDir.closeSync();
// Step 3: Remove the now-empty nested directory // Step 3: Remove the now-empty nested directory
fs.rmdirSync(nestedPath); fs.rmdirSync(nestedPath);
// Diagnostic: verify final state
const finalEntries = fs.readdirSync(this.destDir);
console.log(` 📦 Unpacked ${this.sourceFolderName}: moved ${moved} entries, final: ${finalEntries.length} entries`);
return true; return true;
} }
} }