66import { mkdir , readFile , writeFile } from 'node:fs/promises'
77import path from 'node:path'
88import { createFilter } from '@rollup/pluginutils'
9+ import Debug from 'debug'
910import MagicString from 'magic-string'
1011import { parseAsync } from 'oxc-parser'
1112import {
@@ -36,8 +37,12 @@ import type {
3637 PluginContext ,
3738} from 'rollup'
3839
40+ const debug = Debug ( 'unplugin-isolated-decl' )
41+
3942export type { Options }
4043
44+ export type * from './core/types'
45+
4146/**
4247 * The main unplugin instance.
4348 */
@@ -117,6 +122,9 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
117122 code = s . toString ( )
118123 }
119124
125+ const label = debug . enabled && `[${ options . transformer } ]`
126+ debug ( label , 'transform' , id )
127+
120128 let result : TransformResult
121129 switch ( options . transformer ) {
122130 case 'oxc' :
@@ -133,6 +141,12 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
133141 )
134142 }
135143 const { code : sourceText , errors } = result
144+ debug (
145+ label ,
146+ 'transformed' ,
147+ id ,
148+ errors . length ? 'with errors' : 'successfully' ,
149+ )
136150 if ( errors . length ) {
137151 if ( options . ignoreErrors ) {
138152 context . warn ( errors [ 0 ] )
@@ -143,7 +157,10 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
143157 }
144158 addOutput ( id , sourceText )
145159
146- if ( ! program ) return
160+ if ( ! program ) {
161+ debug ( 'cannot parse' , id )
162+ return
163+ }
147164 const typeImports = program . body . filter (
148165 (
149166 node ,
@@ -189,6 +206,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
189206 } catch {
190207 continue
191208 }
209+ debug ( 'transform type import:' , resolved )
192210 await transform ( context , source , resolved )
193211 }
194212 }
@@ -233,6 +251,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
233251 if ( options . patchCjsDefaultExport && fileName . endsWith ( '.d.cts' ) ) {
234252 source = patchCjsDefaultExport ( source )
235253 }
254+ debug ( '[rollup] emit dts file:' , fileName )
236255 this . emitFile ( {
237256 type : 'asset' ,
238257 fileName,
@@ -293,6 +312,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
293312 if ( options . patchCjsDefaultExport && fileName . endsWith ( '.d.cts' ) ) {
294313 source = patchCjsDefaultExport ( source )
295314 }
315+ debug ( '[farm] emit dts file:' , fileName )
296316 farmPluginContext . emitFile ( {
297317 type : 'asset' ,
298318 fileName,
@@ -352,7 +372,9 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
352372 if ( write ) {
353373 await mkdir ( path . dirname ( filePath ) , { recursive : true } )
354374 await writeFile ( filePath , source )
375+ debug ( '[esbuild] write dts file:' , filePath )
355376 } else {
377+ debug ( '[esbuild] emit dts file:' , filePath )
356378 result . outputFiles ! . push ( {
357379 path : filePath ,
358380 contents : textEncoder . encode ( source ) ,
0 commit comments