Compare commits

..

10 Commits

6 changed files with 61 additions and 51 deletions

View File

@@ -1,5 +1,45 @@
# Changelog # Changelog
## 2026-03-05 - 4.1.14 - fix(fs)
replace execSync and fsync workarounds with atomic async FsHelpers operations to avoid XFS races and shell dependencies
- Removed child_process.execSync usage and shell mv/rm commands in mod_unpack and mod_compiler.
- Removed syncDirectoryTree and fsync-based workaround from the compiler module.
- Use FsHelpers.move and FsHelpers.removeDirectory (async rename/remove) for atomic filesystem operations during unpack.
- Await performUnpack directly and simplify unpack flow to improve portability and reliability on XFS and other filesystems.
## 2026-03-05 - 4.1.13 - fix(mod_unpack)
Use child_process.execSync (mv/rm) to perform unpack atomically, replacing async fs operations and logs to avoid ENOENT/partial directory listings on XFS
- Replaced async fs.promises.rename/rm and readdir/stat debugging with execSync rm -rf and mv operations for sequential, atomic moves
- Imported execSync from child_process and removed verbose console logging and extra fs checks
- Addresses race conditions observed on filesystems like XFS where libuv async operations can return partial results or ENOENT errors
## 2026-03-05 - 4.1.12 - fix(mod_compiler)
replace runtime require calls with top-level imports and use execSync/path.join for filesystem sync and traversal
- Added top-level imports: path and execSync from child_process
- Replaced require('child_process').execSync('sync') with execSync('sync') to force fs sync
- Replaced require('path').join(...) with path.join(...) when recursing directories
- Refactor is purely local/maintenance-focused (consistency and slight performance/readability improvement); no functional change expected
## 2026-03-05 - 4.1.11 - fix(mod_compiler)
flush directory entries before unpack to avoid XFS delayed-log causing partial readdir results
- Add fs import and call child_process.execSync('sync') before unpacking compiled output to force kernel-level sync
- Add syncDirectoryTree(dir) to recursively open and fsync directory file descriptors and traverse subdirectories
- Call syncDirectoryTree on the destination directory before performing unpack to ensure TypeScript writeFileSync entries are committed (prevents partial readdir results on XFS)
- Errors during directory sync are ignored to avoid breaking normal flow
## 2026-03-05 - 4.1.10 - fix(unpack)
use atomic renames to flatten nested output and make unpacking more reliable
- Replace per-entry moves with an atomic 3-step strategy: rename nested dir to a temp location, remove the destination dir, then rename temp back to the destination to avoid partial readdir/move under signal pressure.
- FsHelpers.move switched from sync rename to fs.promises.rename to work with async flows.
- Use fs.promises.rm with retries and explicit temp-dir cleanup to handle previous failed runs.
- Add diagnostic logging and verification of intermediate states.
- Removed the older removeSiblingDirectories and moveNestedContentsUp methods in favor of the new rename-based approach.
## 2026-03-05 - 4.1.9 - fix(fs) ## 2026-03-05 - 4.1.9 - fix(fs)
improve filesystem helpers: use sync rename for reliability on certain filesystems; retry rmdir with delays and avoid recursive rm; bump @push.rocks/smartfs to ^1.3.2 improve filesystem helpers: use sync rename for reliability on certain filesystems; retry rmdir with delays and avoid recursive rm; bump @push.rocks/smartfs to ^1.3.2

View File

@@ -1,6 +1,6 @@
{ {
"name": "@git.zone/tsbuild", "name": "@git.zone/tsbuild",
"version": "4.1.9", "version": "4.1.14",
"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.9', version: '4.1.14',
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

@@ -367,12 +367,7 @@ export class TsCompiler {
// Perform unpack if compilation succeeded // Perform unpack if compilation succeeded
if (result.errorSummary.totalErrors === 0) { if (result.errorSummary.totalErrors === 0) {
try { await performUnpack(pattern, destDir, this.cwd);
await performUnpack(pattern, destDir, this.cwd);
} catch (unpackErr: any) {
console.error(` ⚠️ Unpack error for ${destPath}: ${unpackErr.message}`);
}
successfulOutputDirs.push(destDir); successfulOutputDirs.push(destDir);
} }

View File

@@ -130,11 +130,9 @@ export class FsHelpers {
/** /**
* Move/rename a file or directory * Move/rename a file or directory
* Uses renameSync for reliability on XFS/mounted filesystems where async
* rename can be interrupted by signals from process managers
*/ */
public static async move(src: string, dest: string): Promise<void> { public static async move(src: string, dest: string): Promise<void> {
fs.renameSync(src, dest); await fs.promises.rename(src, dest);
} }
/** /**

View File

@@ -1,4 +1,3 @@
import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import { TsPublishConfig } from '../mod_config/index.js'; import { TsPublishConfig } from '../mod_config/index.js';
import { FsHelpers } from '../mod_fs/index.js'; import { FsHelpers } from '../mod_fs/index.js';
@@ -81,62 +80,40 @@ export class TsUnpacker {
} }
/** /**
* Perform the unpack operation - flatten nested output directories * Perform the unpack operation - flatten nested output directories.
* Returns true if unpacking was performed, false if skipped *
* Renames the nested directory to a temp location, removes the dest dir,
* then renames the temp dir back as dest. Uses only rename operations
* which are atomic at the kernel level.
*
* Returns true if unpacking was performed, false if skipped.
*/ */
public async unpack(): Promise<boolean> { public async unpack(): Promise<boolean> {
// Check if we should unpack based on config
if (!(await this.shouldUnpack())) { if (!(await this.shouldUnpack())) {
return false; return false;
} }
// Check if nested structure exists
if (!(await this.detectNesting())) { if (!(await this.detectNesting())) {
return false; return false;
} }
const nestedPath = this.getNestedPath(); const nestedPath = this.getNestedPath();
const tempPath = this.destDir + '.__unpack_temp__';
// Delete sibling folders (not the source folder) // Step 1: Clean up any leftover temp dir from a previous failed run
await this.removeSiblingDirectories(); await FsHelpers.removeDirectory(tempPath);
// Move contents from nested folder up // Step 2: Rename nested → temp
await this.moveNestedContentsUp(); await FsHelpers.move(nestedPath, tempPath);
// Remove empty nested folder // Step 3: Remove dest dir (now contains only sibling folders)
await FsHelpers.removeEmptyDirectory(nestedPath); await FsHelpers.removeDirectory(this.destDir);
// Step 4: Rename temp → dest
await FsHelpers.move(tempPath, this.destDir);
return true; return true;
} }
/**
* Remove sibling directories in the destination folder
* (directories other than the source folder being unpacked)
*/
private async removeSiblingDirectories(): Promise<void> {
const entries = await FsHelpers.listDirectory(this.destDir);
for (const entry of entries) {
if (entry.isDirectory && entry.name !== this.sourceFolderName) {
await FsHelpers.removeDirectory(path.join(this.destDir, entry.name));
}
}
}
/**
* Move contents from the nested folder up to the destination directory
*/
private async moveNestedContentsUp(): Promise<void> {
const nestedPath = this.getNestedPath();
const entries = await FsHelpers.listDirectory(nestedPath);
const dirCount = entries.filter(e => e.isDirectory).length;
const fileCount = entries.filter(e => e.isFile).length;
console.log(` 📦 Unpacking ${this.sourceFolderName}/: ${dirCount} directories, ${fileCount} files`);
for (const entry of entries) {
const src = path.join(nestedPath, entry.name);
const dest = path.join(this.destDir, entry.name);
await FsHelpers.move(src, dest);
}
}
} }
/** /**