From e4dd3538c9bb3ad4c795de2c95edb873305385e8 Mon Sep 17 00:00:00 2001 From: 10Derozan Date: Tue, 12 Dec 2023 15:45:43 +0800 Subject: [PATCH] fix(module-tools): use tsc --clean to clear the tsbuildinfo and d.ts (#5064) --- .changeset/wet-beds-eat.md | 6 ++++++ .../solutions/module-tools/src/builder/clear.ts | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/wet-beds-eat.md diff --git a/.changeset/wet-beds-eat.md b/.changeset/wet-beds-eat.md new file mode 100644 index 000000000000..faeccca15eba --- /dev/null +++ b/.changeset/wet-beds-eat.md @@ -0,0 +1,6 @@ +--- +'@modern-js/module-tools': patch +--- + +fix(module-tools): use tsc --clean to clear the tsbuildinfo and d.ts files +fix(module-tools): 使用 "tsc --clean" 来清理生成的 tsbuildinfo 和类型描述文件 diff --git a/packages/solutions/module-tools/src/builder/clear.ts b/packages/solutions/module-tools/src/builder/clear.ts index 229321b2a6ef..2b1e85b9bdab 100644 --- a/packages/solutions/module-tools/src/builder/clear.ts +++ b/packages/solutions/module-tools/src/builder/clear.ts @@ -1,6 +1,7 @@ -import { fs, logger, chalk } from '@modern-js/utils'; +import { fs, logger, chalk, execa } from '@modern-js/utils'; import type { BaseBuildConfig } from '../types'; import { i18n, localeKeys } from '../locale'; +import { getTscBinPath } from '../utils'; export const clearBuildConfigPaths = async ( configs: BaseBuildConfig[], @@ -12,5 +13,19 @@ export const clearBuildConfigPaths = async ( } else { await fs.remove(config.outDir); } + + // tsc --build --clean + if (config.buildType === 'bundleless' && config.dts) { + const tscBinFile = await getTscBinPath(projectAbsRootPath); + const childProgress = execa(tscBinFile, ['--build', '--clean'], { + stdio: 'pipe', + cwd: projectAbsRootPath, + }); + try { + await childProgress; + } catch (e) { + logger.error(e); + } + } } };