11import { createResolver } from 'dts-resolver'
2- import { getTsconfig } from 'get-tsconfig'
2+ import { getTsconfig , parseTsconfig } from 'get-tsconfig'
33import { isolatedDeclaration as oxcIsolatedDeclaration } from 'oxc-transform'
44import {
55 filename_dts_to ,
@@ -23,16 +23,47 @@ import type { Plugin } from 'rolldown'
2323const meta = { dtsFile : true } as const
2424
2525export function createGeneratePlugin ( {
26+ tsconfig,
2627 compilerOptions,
2728 isolatedDeclaration,
2829 resolve = false ,
2930 emitDtsOnly = false ,
3031} : Pick <
3132 Options ,
32- 'isolatedDeclaration' | 'resolve' | 'emitDtsOnly' | 'compilerOptions'
33+ | 'isolatedDeclaration'
34+ | 'resolve'
35+ | 'emitDtsOnly'
36+ | 'tsconfig'
37+ | 'compilerOptions'
3338> ) : Plugin {
3439 const dtsMap = new Map < string , { code : string ; src : string } > ( )
3540
41+ function resolveOptions ( cwd ?: string ) {
42+ if ( tsconfig === true || tsconfig == null ) {
43+ const { config } = getTsconfig ( cwd ) || { }
44+ compilerOptions = {
45+ ...config ?. compilerOptions ,
46+ ...compilerOptions ,
47+ }
48+ } else if ( typeof tsconfig === 'string' ) {
49+ const config = parseTsconfig ( tsconfig )
50+ compilerOptions = {
51+ ...config . compilerOptions ,
52+ ...compilerOptions ,
53+ }
54+ }
55+
56+ if ( isolatedDeclaration == null ) {
57+ isolatedDeclaration = ! ! compilerOptions ?. isolatedDeclarations
58+ }
59+ if ( isolatedDeclaration === true ) {
60+ isolatedDeclaration = { }
61+ }
62+ if ( isolatedDeclaration && isolatedDeclaration . stripInternal == null ) {
63+ isolatedDeclaration . stripInternal = ! ! compilerOptions ?. stripInternal
64+ }
65+ }
66+
3667 /**
3768 * A map of input id to output file name
3869 *
@@ -50,20 +81,7 @@ export function createGeneratePlugin({
5081 name : 'rolldown-plugin-dts:generate' ,
5182
5283 async buildStart ( options ) {
53- if ( ! compilerOptions ) {
54- const { config } = getTsconfig ( options . cwd ) || { }
55- compilerOptions = config ?. compilerOptions as any
56- }
57-
58- if ( isolatedDeclaration == null ) {
59- isolatedDeclaration = ! ! compilerOptions ?. isolatedDeclarations
60- }
61- if ( isolatedDeclaration === true ) {
62- isolatedDeclaration = { }
63- }
64- if ( isolatedDeclaration && isolatedDeclaration . stripInternal == null ) {
65- isolatedDeclaration . stripInternal = ! ! compilerOptions ?. stripInternal
66- }
84+ resolveOptions ( options . cwd )
6785
6886 if ( ! isolatedDeclaration ) {
6987 initTs ( )
0 commit comments