@@ -102,27 +102,7 @@ export function createGeneratePlugin({
102102
103103 async buildStart ( options ) {
104104 if ( tsgo ) {
105- const tsgoPkg = import . meta. resolve (
106- '@typescript/native-preview/package.json' ,
107- )
108- const { default : getExePath } = await import (
109- new URL ( './lib/getExePath.js' , tsgoPkg ) . href
110- )
111- const tsgo = getExePath ( )
112- tsgoDist = await mkdtemp ( path . join ( tmpdir ( ) , 'rolldown-plugin-dts-' ) )
113- await spawnAsync (
114- tsgo ,
115- [
116- '--noEmit' ,
117- 'false' ,
118- '--declaration' ,
119- '--emitDeclarationOnly' ,
120- ...( tsconfig ? [ '-p' , tsconfig ] : [ ] ) ,
121- '--outDir' ,
122- tsgoDist ,
123- ] ,
124- { stdio : 'inherit' } ,
125- )
105+ tsgoDist = await runTsgo ( cwd , tsconfig )
126106 } else if ( ! parallel && ( ! isolatedDeclarations || vue ) ) {
127107 tscModule = await import ( './tsc/index.ts' )
128108 tscContext = eager ? undefined : tscModule . createContext ( )
@@ -219,14 +199,12 @@ export function createGeneratePlugin({
219199 throw new Error ( 'tsgo does not support Vue files.' )
220200 const dtsPath = path . resolve (
221201 tsgoDist ! ,
222- path . relative (
223- path . resolve ( typeof tsgo === 'string' ? tsgo : 'src' ) ,
224- filename_ts_to_dts ( id ) ,
225- ) ,
202+ path . relative ( path . resolve ( cwd ) , filename_ts_to_dts ( id ) ) ,
226203 )
227204 if ( existsSync ( dtsPath ) ) {
228205 dtsCode = await readFile ( dtsPath , 'utf8' )
229206 } else {
207+ debug ( '[tsgo]' , dtsPath , 'is missing' )
230208 throw new Error (
231209 `tsgo did not generate dts file for ${ id } , please check your tsconfig.` ,
232210 )
@@ -298,10 +276,38 @@ export function createGeneratePlugin({
298276
299277 async buildEnd ( ) {
300278 childProcess ?. kill ( )
301- if ( tsgoDist ) {
279+ if ( ! debug . enabled && tsgoDist ) {
302280 await rm ( tsgoDist , { recursive : true , force : true } ) . catch ( ( ) => { } )
303281 }
304282 tscContext = tsgoDist = undefined
305283 } ,
306284 }
307285}
286+
287+ async function runTsgo ( root : string , tsconfig ?: string ) {
288+ const tsgoPkg = import . meta. resolve ( '@typescript/native-preview/package.json' )
289+ const { default : getExePath } = await import (
290+ new URL ( './lib/getExePath.js' , tsgoPkg ) . href
291+ )
292+ const tsgo = getExePath ( )
293+ const tsgoDist = await mkdtemp ( path . join ( tmpdir ( ) , 'rolldown-plugin-dts-' ) )
294+ debug ( '[tsgo] tsgoDist' , tsgoDist )
295+
296+ await spawnAsync (
297+ tsgo ,
298+ [
299+ '--noEmit' ,
300+ 'false' ,
301+ '--declaration' ,
302+ '--emitDeclarationOnly' ,
303+ ...( tsconfig ? [ '-p' , tsconfig ] : [ ] ) ,
304+ '--outDir' ,
305+ tsgoDist ,
306+ '--rootDir' ,
307+ root ,
308+ ] ,
309+ { stdio : 'inherit' } ,
310+ )
311+
312+ return tsgoDist
313+ }
0 commit comments