Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f8443d33f | |||
| 2fb838d1bd | |||
| b4a1ff5eab | |||
| d3e3905e7f | |||
| fe60a21c59 | |||
| 920095d008 | |||
| e1198c0a78 | |||
| 01b2cfe69c |
32
changelog.md
32
changelog.md
@@ -1,5 +1,37 @@
|
||||
# Changelog
|
||||
|
||||
## 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)
|
||||
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
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tsbuild",
|
||||
"version": "4.1.9",
|
||||
"version": "4.1.13",
|
||||
"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.1.9',
|
||||
version: '4.1.13',
|
||||
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { CompilerOptions, Diagnostic, Program } from 'typescript';
|
||||
import typescript from 'typescript';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
@@ -367,6 +370,12 @@ export class TsCompiler {
|
||||
|
||||
// Perform unpack if compilation succeeded
|
||||
if (result.errorSummary.totalErrors === 0) {
|
||||
// Force XFS to commit all pending directory entries before unpacking.
|
||||
// TypeScript's writeFileSync creates entries that may reside in XFS's
|
||||
// delayed log. Without sync, readdir can return partial results.
|
||||
execSync('sync');
|
||||
this.syncDirectoryTree(destDir);
|
||||
|
||||
try {
|
||||
await performUnpack(pattern, destDir, this.cwd);
|
||||
} catch (unpackErr: any) {
|
||||
@@ -495,6 +504,27 @@ export class TsCompiler {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively fsync all directories in a tree.
|
||||
* Forces XFS to commit pending directory entries from its log.
|
||||
*/
|
||||
private syncDirectoryTree(dirPath: string): void {
|
||||
try {
|
||||
const fd = fs.openSync(dirPath, 'r');
|
||||
fs.fsyncSync(fd);
|
||||
fs.closeSync(fd);
|
||||
|
||||
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory()) {
|
||||
this.syncDirectoryTree(path.join(dirPath, entry.name));
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors (directory may not exist)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge multiple error summaries into one
|
||||
*/
|
||||
|
||||
@@ -130,11 +130,9 @@ export class FsHelpers {
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
fs.renameSync(src, dest);
|
||||
await fs.promises.rename(src, dest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import { TsPublishConfig } from '../mod_config/index.js';
|
||||
import { FsHelpers } from '../mod_fs/index.js';
|
||||
|
||||
@@ -81,62 +81,36 @@ export class TsUnpacker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the unpack operation - flatten nested output directories
|
||||
* Returns true if unpacking was performed, false if skipped
|
||||
* Perform the unpack operation - flatten nested output directories.
|
||||
*
|
||||
* Uses shell commands (mv, rm) via execSync for reliability. Node.js async
|
||||
* fs operations (rename, rm) can race on XFS filesystems where metadata
|
||||
* commits are delayed, causing ENOENT or partial directory listings.
|
||||
* Shell commands execute as direct syscalls without libuv's async layer.
|
||||
*
|
||||
* Returns true if unpacking was performed, false if skipped.
|
||||
*/
|
||||
public async unpack(): Promise<boolean> {
|
||||
// Check if we should unpack based on config
|
||||
if (!(await this.shouldUnpack())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if nested structure exists
|
||||
if (!(await this.detectNesting())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const nestedPath = this.getNestedPath();
|
||||
const tempPath = this.destDir + '.__unpack_temp__';
|
||||
|
||||
// Delete sibling folders (not the source folder)
|
||||
await this.removeSiblingDirectories();
|
||||
|
||||
// Move contents from nested folder up
|
||||
await this.moveNestedContentsUp();
|
||||
|
||||
// Remove empty nested folder
|
||||
await FsHelpers.removeEmptyDirectory(nestedPath);
|
||||
// Use shell commands for atomic, sequential filesystem operations.
|
||||
// This avoids race conditions between Node.js async fs operations on XFS.
|
||||
execSync(`rm -rf "${tempPath}"`, { stdio: 'ignore' });
|
||||
execSync(`mv "${nestedPath}" "${tempPath}"`, { stdio: 'ignore' });
|
||||
execSync(`rm -rf "${this.destDir}"`, { stdio: 'ignore' });
|
||||
execSync(`mv "${tempPath}" "${this.destDir}"`, { stdio: 'ignore' });
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user