fix(TsCompiler): Clear output directories before compilation to ensure clean builds and avoid stale files

This commit is contained in:
2025-12-14 00:19:09 +00:00
parent 0eaca1f3d1
commit fb6bd614d3
8 changed files with 285 additions and 555 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tsbuild',
version: '3.1.3',
version: '4.0.2',
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
}

View File

@@ -335,6 +335,14 @@ export class TsCompiler {
// Get destination directory as absolute path
const destDir = smartpath.transform.toAbsolute(destPath, this.cwd) as string;
// Clear the destination directory before compilation if it exists
if (await FsHelpers.directoryExists(destDir)) {
if (!isQuiet && !isJson) {
console.log(`🧹 Clearing output directory: ${destPath}`);
}
await FsHelpers.removeDirectory(destDir);
}
// Update compiler options with the output directory
const options: CompilerOptions = {
...customOptions,