Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4a1ff5eab | |||
| d3e3905e7f | |||
| fe60a21c59 | |||
| 920095d008 | |||
| e1198c0a78 | |||
| 01b2cfe69c |
25
changelog.md
25
changelog.md
@@ -1,5 +1,30 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@git.zone/tsbuild",
|
"name": "@git.zone/tsbuild",
|
||||||
"version": "4.1.9",
|
"version": "4.1.12",
|
||||||
"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",
|
||||||
|
|||||||
@@ -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.12',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import type { CompilerOptions, Diagnostic, Program } from 'typescript';
|
import type { CompilerOptions, Diagnostic, Program } from 'typescript';
|
||||||
import typescript 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 smartdelay from '@push.rocks/smartdelay';
|
||||||
import * as smartpromise from '@push.rocks/smartpromise';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smartpath from '@push.rocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
@@ -367,6 +370,12 @@ export class TsCompiler {
|
|||||||
|
|
||||||
// Perform unpack if compilation succeeded
|
// Perform unpack if compilation succeeded
|
||||||
if (result.errorSummary.totalErrors === 0) {
|
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 {
|
try {
|
||||||
await performUnpack(pattern, destDir, this.cwd);
|
await performUnpack(pattern, destDir, this.cwd);
|
||||||
} catch (unpackErr: any) {
|
} catch (unpackErr: any) {
|
||||||
@@ -495,6 +504,27 @@ export class TsCompiler {
|
|||||||
return success;
|
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
|
* Merge multiple error summaries into one
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -81,62 +81,65 @@ 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
|
*
|
||||||
|
* Strategy: instead of listing entries and moving them individually (which is
|
||||||
|
* vulnerable to async readdir returning partial results under signal pressure),
|
||||||
|
* we rename the entire nested directory out, remove the dest dir, then rename
|
||||||
|
* the nested directory back as the dest dir. This 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)
|
// Log what we're about to do
|
||||||
await this.removeSiblingDirectories();
|
const nestedEntries = fs.readdirSync(nestedPath);
|
||||||
|
console.log(` 📦 Unpacking ${this.sourceFolderName}/: ${nestedEntries.length} entries in nested dir`);
|
||||||
|
console.log(` 📦 Entries: [${nestedEntries.join(', ')}]`);
|
||||||
|
// Also list the dest dir to see what TypeScript created
|
||||||
|
const destEntries = fs.readdirSync(this.destDir);
|
||||||
|
console.log(` 📦 destDir entries: [${destEntries.join(', ')}]`);
|
||||||
|
|
||||||
// Move contents from nested folder up
|
// Clean up any leftover temp dir from a previous failed unpack
|
||||||
await this.moveNestedContentsUp();
|
await fs.promises.rm(tempPath, { recursive: true, force: true });
|
||||||
|
|
||||||
// Remove empty nested folder
|
// Step 1: Rename the nested source folder out to a temp location.
|
||||||
await FsHelpers.removeEmptyDirectory(nestedPath);
|
// e.g. dist_ts/ts/ → dist_ts.__unpack_temp__/
|
||||||
|
await fs.promises.rename(nestedPath, tempPath);
|
||||||
|
|
||||||
|
// Verify step 1
|
||||||
|
const tempEntries = fs.readdirSync(tempPath);
|
||||||
|
console.log(` 📦 Step 1 (rename to temp): ${tempEntries.length} entries in temp`);
|
||||||
|
|
||||||
|
// Step 2: Remove the dest dir (which now only contains sibling folders
|
||||||
|
// like ts_interfaces/). Use recursive rm to handle any contents.
|
||||||
|
await fs.promises.rm(this.destDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
||||||
|
console.log(` 📦 Step 2 (remove dest): done`);
|
||||||
|
|
||||||
|
// Step 3: Rename the temp dir to the dest dir.
|
||||||
|
// e.g. dist_ts.__unpack_temp__/ → dist_ts/
|
||||||
|
await fs.promises.rename(tempPath, this.destDir);
|
||||||
|
|
||||||
|
// Verify final state
|
||||||
|
const finalEntries = fs.readdirSync(this.destDir);
|
||||||
|
const finalDirs = finalEntries.filter((e: string) => {
|
||||||
|
return fs.statSync(path.join(this.destDir, e)).isDirectory();
|
||||||
|
});
|
||||||
|
console.log(` 📦 Step 3 (rename to dest): ${finalEntries.length} entries (${finalDirs.length} dirs)`);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user