@@ -3,13 +3,7 @@ import { dirname, extname, join } from 'node:path';
33import { fileURLToPath } from 'node:url' ;
44import { type RsbuildConfig , type RsbuildPlugin , logger } from '@rsbuild/core' ;
55import ts from 'typescript' ;
6- import {
7- cleanDtsFiles ,
8- cleanTsBuildInfoFile ,
9- clearTempDeclarationDir ,
10- loadTsconfig ,
11- processSourceEntry ,
12- } from './utils' ;
6+ import { loadTsconfig , processSourceEntry } from './utils' ;
137
148const __filename = fileURLToPath ( import . meta. url ) ;
159const __dirname = dirname ( __filename ) ;
@@ -41,10 +35,11 @@ export type DtsGenOptions = PluginDtsOptions & {
4135 cwd : string ;
4236 isWatch : boolean ;
4337 dtsEntry : DtsEntry ;
44- dtsEmitPath : string ;
4538 build ?: boolean ;
4639 tsconfigPath : string ;
4740 tsConfigResult : ts . ParsedCommandLine ;
41+ rootDistPath : string ;
42+ cleanDistPath : NonNullable < RsbuildConfig [ 'output' ] > [ 'cleanDistPath' ] ;
4843 userExternals ?: NonNullable < RsbuildConfig [ 'output' ] > [ 'externals' ] ;
4944} ;
5045
@@ -98,10 +93,6 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
9893 }
9994
10095 const tsConfigResult = loadTsconfig ( tsconfigPath ) ;
101- const dtsEmitPath =
102- options . distPath ??
103- tsConfigResult . options . declarationDir ??
104- config . output ?. distPath ?. root ;
10596
10697 const jsExtension = extname ( __filename ) ;
10798 const childProcess = fork ( join ( __dirname , `./dts${ jsExtension } ` ) , [ ] , {
@@ -110,28 +101,14 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
110101
111102 childProcesses . push ( childProcess ) ;
112103
113- const { cleanDistPath } = config . output ;
114-
115- // clean dts files
116- if ( cleanDistPath !== false ) {
117- await cleanDtsFiles ( dtsEmitPath ) ;
118- }
119-
120- // clean .rslib temp folder
121- if ( options . bundle ) {
122- await clearTempDeclarationDir ( cwd ) ;
123- }
124-
125- // clean tsbuildinfo file
126- await cleanTsBuildInfoFile ( tsconfigPath , tsConfigResult ) ;
127-
128104 const dtsGenOptions : DtsGenOptions = {
129105 ...options ,
130106 dtsEntry,
131- dtsEmitPath ,
107+ rootDistPath : config . output ?. distPath ?. root ,
132108 userExternals : config . output . externals ,
133109 tsconfigPath,
134110 tsConfigResult,
111+ cleanDistPath : config . output . cleanDistPath ,
135112 name : environment . name ,
136113 cwd,
137114 isWatch,
0 commit comments