@@ -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,11 +93,6 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
9893 }
9994
10095 const tsConfigResult = loadTsconfig ( tsconfigPath ) ;
101- const compilerOptions = tsConfigResult . options ;
102- const dtsEmitPath =
103- options . distPath ??
104- compilerOptions . declarationDir ??
105- config . output ?. distPath ?. root ;
10696
10797 const jsExtension = extname ( __filename ) ;
10898 const childProcess = fork ( join ( __dirname , `./dts${ jsExtension } ` ) , [ ] , {
@@ -111,34 +101,14 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
111101
112102 childProcesses . push ( childProcess ) ;
113103
114- const { cleanDistPath } = config . output ;
115-
116- // clean dts files
117- if ( cleanDistPath !== false ) {
118- await cleanDtsFiles ( dtsEmitPath ) ;
119- }
120-
121- // clean .rslib temp folder
122- if ( options . bundle ) {
123- await clearTempDeclarationDir ( cwd ) ;
124- }
125-
126- // clean tsbuildinfo file
127- if (
128- compilerOptions . composite ||
129- compilerOptions . incremental ||
130- options . build
131- ) {
132- await cleanTsBuildInfoFile ( tsconfigPath , tsConfigResult ) ;
133- }
134-
135104 const dtsGenOptions : DtsGenOptions = {
136105 ...options ,
137106 dtsEntry,
138- dtsEmitPath ,
107+ rootDistPath : config . output ?. distPath ?. root ,
139108 userExternals : config . output . externals ,
140109 tsconfigPath,
141110 tsConfigResult,
111+ cleanDistPath : config . output . cleanDistPath ,
142112 name : environment . name ,
143113 cwd,
144114 isWatch,
0 commit comments