Skip to content

Commit 0a1fd71

Browse files
authored
fix: clean declaration maps before the build starts (#1363)
1 parent 403b709 commit 0a1fd71

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/plugin-dts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
159159
warnIfOutside(cwd, declarationDir, 'declarationDir');
160160
warnIfOutside(cwd, outDir, 'outDir');
161161

162-
// clean dts files
162+
// clean dts files and maps
163163
if (config.output.cleanDistPath !== false) {
164164
await cleanDtsFiles(dtsEmitPath);
165165
}

packages/plugin-dts/src/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,14 @@ export const globDtsFiles = async (
612612
};
613613

614614
export async function cleanDtsFiles(dir: string): Promise<void> {
615-
const patterns = ['/**/*.d.ts', '/**/*.d.cts', '/**/*.d.mts'];
615+
const patterns = [
616+
'/**/*.d.ts',
617+
'/**/*.d.cts',
618+
'/**/*.d.mts',
619+
'/**/*.d.ts.map',
620+
'/**/*.d.cts.map',
621+
'/**/*.d.mts.map',
622+
];
616623
const allFiles = await globDtsFiles(dir, patterns);
617624

618625
await Promise.all(

tests/scripts/shared.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,24 @@ export async function createTempFiles(
465465
const tempDirEsm = join(fixturePath, 'dist-types', 'esm');
466466
const tempFileCjs = join(tempDirCjs, 'tempFile.d.ts');
467467
const tempFileEsm = join(tempDirEsm, 'tempFile.d.ts');
468+
const tempFileMapCjs = join(tempDirCjs, 'tempFile.d.ts.map');
469+
const tempFileMapEsm = join(tempDirEsm, 'tempFile.d.ts.map');
468470

469471
await fs.promises.mkdir(tempDirCjs, { recursive: true });
470472
await fs.promises.mkdir(tempDirEsm, { recursive: true });
471473

472474
await fs.promises.writeFile(tempFileCjs, 'console.log("temp file for cjs");');
473475
await fs.promises.writeFile(tempFileEsm, 'console.log("temp file for esm");');
476+
await fs.promises.writeFile(
477+
tempFileMapCjs,
478+
'console.log("temp map file for cjs");',
479+
);
480+
await fs.promises.writeFile(
481+
tempFileMapEsm,
482+
'console.log("temp map file for esm");',
483+
);
474484

475-
checkFile.push(tempFileCjs, tempFileEsm);
485+
checkFile.push(tempFileCjs, tempFileEsm, tempFileMapCjs, tempFileMapEsm);
476486

477487
if (bundle) {
478488
const tempDirRslib = join(fixturePath, '.rslib', 'declarations', 'cjs');

0 commit comments

Comments
 (0)