From 0278f8955b3034edaf7525e553e4bd58a5ec8a31 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 24 Nov 2025 20:20:43 +0800 Subject: [PATCH] fix: clean declaration maps before the build starts --- packages/plugin-dts/src/index.ts | 2 +- packages/plugin-dts/src/utils.ts | 9 ++++++++- tests/scripts/shared.ts | 12 +++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/plugin-dts/src/index.ts b/packages/plugin-dts/src/index.ts index ecb7fafcc..1816efe93 100644 --- a/packages/plugin-dts/src/index.ts +++ b/packages/plugin-dts/src/index.ts @@ -159,7 +159,7 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({ warnIfOutside(cwd, declarationDir, 'declarationDir'); warnIfOutside(cwd, outDir, 'outDir'); - // clean dts files + // clean dts files and maps if (config.output.cleanDistPath !== false) { await cleanDtsFiles(dtsEmitPath); } diff --git a/packages/plugin-dts/src/utils.ts b/packages/plugin-dts/src/utils.ts index 412f7f05a..44846932a 100644 --- a/packages/plugin-dts/src/utils.ts +++ b/packages/plugin-dts/src/utils.ts @@ -612,7 +612,14 @@ export const globDtsFiles = async ( }; export async function cleanDtsFiles(dir: string): Promise { - const patterns = ['/**/*.d.ts', '/**/*.d.cts', '/**/*.d.mts']; + const patterns = [ + '/**/*.d.ts', + '/**/*.d.cts', + '/**/*.d.mts', + '/**/*.d.ts.map', + '/**/*.d.cts.map', + '/**/*.d.mts.map', + ]; const allFiles = await globDtsFiles(dir, patterns); await Promise.all( diff --git a/tests/scripts/shared.ts b/tests/scripts/shared.ts index 1b220222d..af226ce38 100644 --- a/tests/scripts/shared.ts +++ b/tests/scripts/shared.ts @@ -465,14 +465,24 @@ export async function createTempFiles( const tempDirEsm = join(fixturePath, 'dist-types', 'esm'); const tempFileCjs = join(tempDirCjs, 'tempFile.d.ts'); const tempFileEsm = join(tempDirEsm, 'tempFile.d.ts'); + const tempFileMapCjs = join(tempDirCjs, 'tempFile.d.ts.map'); + const tempFileMapEsm = join(tempDirEsm, 'tempFile.d.ts.map'); await fs.promises.mkdir(tempDirCjs, { recursive: true }); await fs.promises.mkdir(tempDirEsm, { recursive: true }); await fs.promises.writeFile(tempFileCjs, 'console.log("temp file for cjs");'); await fs.promises.writeFile(tempFileEsm, 'console.log("temp file for esm");'); + await fs.promises.writeFile( + tempFileMapCjs, + 'console.log("temp map file for cjs");', + ); + await fs.promises.writeFile( + tempFileMapEsm, + 'console.log("temp map file for esm");', + ); - checkFile.push(tempFileCjs, tempFileEsm); + checkFile.push(tempFileCjs, tempFileEsm, tempFileMapCjs, tempFileMapEsm); if (bundle) { const tempDirRslib = join(fixturePath, '.rslib', 'declarations', 'cjs');