fix(mod_unpack): handle partial readdirSync results when moving nested directory entries and add diagnostic log
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tsbuild',
|
||||
version: '4.1.22',
|
||||
version: '4.1.23',
|
||||
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
||||
}
|
||||
|
||||
@@ -116,17 +116,27 @@ export class TsUnpacker {
|
||||
}
|
||||
|
||||
// Step 2: Move all contents from nested dir up to dest dir
|
||||
const nestedEntries = fs.readdirSync(nestedPath);
|
||||
for (const entry of nestedEntries) {
|
||||
fs.renameSync(
|
||||
path.join(nestedPath, entry),
|
||||
path.join(this.destDir, entry),
|
||||
);
|
||||
// Use a loop to handle any partial readdirSync results
|
||||
let moved = 0;
|
||||
while (true) {
|
||||
const entries = fs.readdirSync(nestedPath);
|
||||
if (entries.length === 0) break;
|
||||
for (const entry of entries) {
|
||||
fs.renameSync(
|
||||
path.join(nestedPath, entry),
|
||||
path.join(this.destDir, entry),
|
||||
);
|
||||
moved++;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 ${moved} entries, final: ${finalEntries.length} entries`);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user