@@ -76,6 +76,15 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
7676 const base = options ?. base ?? cwd
7777 const rootDir = `${ cwd } /${ root } `
7878
79+ // Merge the base tsconfig with the package-specific one
80+ const mergedConfig = {
81+ ...configJson ,
82+ compilerOptions : {
83+ ...configJson . compilerOptions ,
84+ ...options ?. compiler ,
85+ } ,
86+ }
87+
7988 const opts : TsOptions = {
8089 base,
8190 baseUrl : base ,
@@ -87,10 +96,14 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
8796 ...( options ?. include && { include : options . include } ) ,
8897 }
8998
90- const parsedConfig = ts . parseJsonConfigFileContent ( configJson , ts . sys , cwd , opts , path )
99+ const parsedConfig = ts . parseJsonConfigFileContent ( mergedConfig , ts . sys , cwd , opts , path )
91100 parsedConfig . options . emitDeclarationOnly = true
92- // console.log('Root directory:', rootDir)
93- // console.log('Output directory:', parsedConfig.options.outDir)
101+
102+ // Use the outdir from options if provided, otherwise use the one from tsconfig
103+ const outDir = options ?. outdir || parsedConfig . options . outDir || 'dist'
104+
105+ // Ensure outDir is relative to the package root, not the monorepo root
106+ parsedConfig . options . outDir = p . resolve ( cwd , outDir )
94107
95108 const host = ts . createCompilerHost ( parsedConfig . options )
96109
@@ -102,10 +115,7 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
102115 if ( 'isDeclarationFile' in sourceFile ) {
103116 const originalFileName = sourceFile . fileName
104117 const entryPointName = p . basename ( originalFileName , '.ts' )
105- // console.log('originalFileName', originalFileName)
106- // console.log('entryPointName', entryPointName)
107118 const newFileName = p . join ( parsedConfig . options . outDir || 'dist' , `${ entryPointName } .d.ts` )
108- // console.log('newFileName', newFileName)
109119
110120 return ts . factory . updateSourceFile (
111121 sourceFile ,
@@ -123,27 +133,20 @@ export async function generate(entryPoints: string | string[], options?: DtsOpti
123133 ] ,
124134 }
125135
126- // console.log('Parsed config:', JSON.stringify(parsedConfig.options, null, 2))
127-
128136 const program = ts . createProgram ( {
129137 rootNames : Array . isArray ( entryPoints ) ? entryPoints : [ entryPoints ] ,
130138 options : parsedConfig . options ,
131139 host,
132140 } )
133141
134- // console.log('Program created with root names:', program.getRootFileNames())
135-
136- // const emitResult = program.emit(
137142 program . emit (
138143 undefined ,
139144 ( fileName , data ) => {
140145 if ( fileName . endsWith ( '.d.ts' ) ) {
141- // console.log('Emitting declaration file:', fileName)
142146 const outputPath = p . join ( parsedConfig . options . outDir || 'dist' , p . relative ( rootDir , fileName ) )
143- // console.log('Attempting to write file:', outputPath)
144147 try {
145148 ts . sys . writeFile ( outputPath , data )
146- // console.log('Successfully wrote file:', outputPath)
149+ console . log ( 'Successfully wrote file:' , outputPath )
147150 } catch ( error ) {
148151 console . error ( 'Error writing file:' , outputPath , error )
149152 }
@@ -169,12 +172,13 @@ export function dts(options?: DtsOptions): BunPlugin {
169172
170173 async setup ( build ) {
171174 const entrypoints = [ ...build . config . entrypoints ] . sort ( )
172- const root = build . config . root ?? 'src'
175+ const root = options ?. root ?? build . config . root ?? 'src'
173176
174177 await generate ( entrypoints , {
175178 root,
176179 include : entrypoints ,
177- outdir : build . config . outdir ,
180+ outdir : options ?. outdir || build . config . outdir ,
181+ cwd : options ?. cwd || process . cwd ( ) ,
178182 ...options ,
179183 } )
180184 } ,
0 commit comments