From 52e1a25948204789c0a51ecbc9379807b21d29b2 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 5 Mar 2026 11:59:18 +0000 Subject: [PATCH] fix(diagnostics): add diagnostic logging around compilation and unpack to aid troubleshooting --- changelog.md | 8 ++++++++ ts/00_commitinfo_data.ts | 2 +- ts/mod_compiler/classes.tscompiler.ts | 25 +++++++++++++++++++++++++ ts/mod_unpack/classes.tsunpacker.ts | 16 +++++++++++++++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index da4227c..d270c82 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # Changelog +## 2026-03-05 - 4.1.5 - fix(diagnostics) +add diagnostic logging around compilation and unpack to aid troubleshooting + +- Enable TypeScript CompilerOptions.listEmittedFiles to surface emitted file info +- Log destination directory contents and emitted file/error counts after compile and after unpack (only when not quiet and not json) +- Add unpack-specific diagnostic logs: shouldUnpack skip, detectNesting result and nestedPath, and nested/destination directory listings before removing sibling directories +- All logs use console.log and are wrapped in try/catch to avoid throwing; changes are informational and non-breaking + ## 2026-03-05 - 4.1.4 - fix(deps) bump @git.zone/tspublish dependency to ^1.11.2 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2e671cc..a8c261c 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbuild', - version: '4.1.4', + version: '4.1.5', description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.' } diff --git a/ts/mod_compiler/classes.tscompiler.ts b/ts/mod_compiler/classes.tscompiler.ts index 46e4437..5f61c0a 100644 --- a/ts/mod_compiler/classes.tscompiler.ts +++ b/ts/mod_compiler/classes.tscompiler.ts @@ -349,6 +349,7 @@ export class TsCompiler { const options: CompilerOptions = { ...customOptions, outDir: destDir, + listEmittedFiles: true, }; currentTask++; @@ -364,9 +365,33 @@ export class TsCompiler { emittedFiles.push(...result.emittedFiles); errorSummaries.push(result.errorSummary); + // DIAGNOSTIC: Log directory contents after compilation + if (!isQuiet && !isJson) { + try { + const fs = await import('fs'); + const dirEntries = fs.readdirSync(destDir, { withFileTypes: true }); + const dirs = dirEntries.filter((e: any) => e.isDirectory()).map((e: any) => e.name).sort(); + const fileCount = dirEntries.filter((e: any) => e.isFile()).length; + console.log(` 📋 [DIAG] After emit: ${dirs.length} dirs [${dirs.join(', ')}], ${fileCount} top-level files`); + console.log(` 📋 [DIAG] emittedFiles.length=${result.emittedFiles.length}, totalErrors=${result.errorSummary.totalErrors}`); + } catch (e: any) { console.log(` 📋 [DIAG] Error reading destDir: ${e.message}`); } + } + // Perform unpack if compilation succeeded if (result.errorSummary.totalErrors === 0) { await performUnpack(pattern, destDir, this.cwd); + + // DIAGNOSTIC: Log directory contents after unpack + if (!isQuiet && !isJson) { + try { + const fs = await import('fs'); + const dirEntries = fs.readdirSync(destDir, { withFileTypes: true }); + const dirs = dirEntries.filter((e: any) => e.isDirectory()).map((e: any) => e.name).sort(); + const fileCount = dirEntries.filter((e: any) => e.isFile()).length; + console.log(` 📋 [DIAG] After unpack: ${dirs.length} dirs [${dirs.join(', ')}], ${fileCount} top-level files`); + } catch (e: any) { console.log(` 📋 [DIAG] Error reading destDir after unpack: ${e.message}`); } + } + successfulOutputDirs.push(destDir); } } diff --git a/ts/mod_unpack/classes.tsunpacker.ts b/ts/mod_unpack/classes.tsunpacker.ts index 17aa663..222e435 100644 --- a/ts/mod_unpack/classes.tsunpacker.ts +++ b/ts/mod_unpack/classes.tsunpacker.ts @@ -87,16 +87,30 @@ export class TsUnpacker { public async unpack(): Promise { // Check if we should unpack based on config if (!(await this.shouldUnpack())) { + console.log(` 📋 [DIAG-UNPACK] Skipping unpack: shouldUnpack=false`); return false; } // Check if nested structure exists - if (!(await this.detectNesting())) { + const hasNesting = await this.detectNesting(); + console.log(` 📋 [DIAG-UNPACK] detectNesting=${hasNesting}, nestedPath=${this.getNestedPath()}`); + if (!hasNesting) { return false; } const nestedPath = this.getNestedPath(); + // DIAGNOSTIC: Log contents before unpack + try { + const destEntries = fs.readdirSync(this.destDir, { withFileTypes: true }); + const destDirs = destEntries.filter(e => e.isDirectory()).map(e => e.name).sort(); + console.log(` 📋 [DIAG-UNPACK] Before removeSibling: destDir dirs=[${destDirs.join(', ')}]`); + const nestedEntries = fs.readdirSync(nestedPath, { withFileTypes: true }); + const nestedDirs = nestedEntries.filter(e => e.isDirectory()).map(e => e.name).sort(); + const nestedFiles = nestedEntries.filter(e => e.isFile()).length; + console.log(` 📋 [DIAG-UNPACK] Nested dir (${this.sourceFolderName}/): ${nestedDirs.length} dirs [${nestedDirs.join(', ')}], ${nestedFiles} files`); + } catch (e: any) { console.log(` 📋 [DIAG-UNPACK] Error reading: ${e.message}`); } + // Delete sibling folders (not the source folder) await this.removeSiblingDirectories();