11import { fork , type ChildProcess } from 'node:child_process'
22import { existsSync } from 'node:fs'
3- import { readFile , rm } from 'node:fs/promises'
3+ import { readFile } from 'node:fs/promises'
44import path from 'node:path'
55import { parse } from '@babel/parser'
66import { createDebug } from 'obug'
@@ -24,7 +24,7 @@ import {
2424 invalidateContextFile ,
2525 type TscContext ,
2626} from './tsc/context.ts'
27- import { runTsgo } from './tsgo.ts'
27+ import { runTsgo , type TsgoContext } from './tsgo.ts'
2828import type { OptionsResolved } from './options.ts'
2929import type { TscOptions , TscResult } from './tsc/index.ts'
3030import type { TscFunctions } from './tsc/worker.ts'
@@ -106,15 +106,15 @@ export function createGeneratePlugin({
106106 let rpc : BirpcReturn < TscFunctions > | undefined
107107 let tscModule : typeof import ( './tsc/index.ts' )
108108 let tscContext : TscContext | undefined
109- let tsgoDist : string | undefined
109+ let tsgoContext : TsgoContext | undefined
110110 const rootDir = tsconfig ? path . dirname ( tsconfig ) : cwd
111111
112112 return {
113113 name : 'rolldown-plugin-dts:generate' ,
114114
115115 async buildStart ( options ) {
116116 if ( tsgo ) {
117- tsgoDist = await runTsgo ( rootDir , tsconfig , sourcemap , tsgo . path )
117+ tsgoContext = await runTsgo ( rootDir , tsconfig , sourcemap , tsgo . path )
118118 } else if ( ! oxc ) {
119119 // tsc
120120 if ( parallel ) {
@@ -237,7 +237,7 @@ export function createGeneratePlugin({
237237 if ( RE_VUE . test ( id ) )
238238 throw new Error ( 'tsgo does not support Vue files.' )
239239 const dtsPath = path . resolve (
240- tsgoDist ! ,
240+ tsgoContext ! . path ,
241241 path . relative ( path . resolve ( rootDir ) , filename_to_dts ( id ) ) ,
242242 )
243243 if ( ! existsSync ( dtsPath ) ) {
@@ -359,10 +359,8 @@ export { __json_default_export as default }`
359359
360360 async buildEnd ( ) {
361361 childProcess ?. kill ( )
362- if ( ! debug . enabled && tsgoDist ) {
363- await rm ( tsgoDist , { recursive : true , force : true } ) . catch ( ( ) => { } )
364- }
365- tsgoDist = undefined
362+ await tsgoContext ?. dispose ( )
363+ tsgoContext = undefined
366364 if ( newContext ) {
367365 tscContext = undefined
368366 }
0 commit comments