@@ -46,10 +46,15 @@ export function createGeneratePlugin({
4646 const inputAliasMap = new Map < string , string > ( )
4747 const resolver = createResolver ( )
4848 let programs : TsProgram [ ] = [ ]
49+ let cwd : string
4950
5051 return {
5152 name : 'rolldown-plugin-dts:generate' ,
5253
54+ options ( options ) {
55+ cwd = options . cwd || process . cwd ( )
56+ } ,
57+
5358 buildStart ( options ) {
5459 if ( ! compilerOptions ) {
5560 const { config } = getTsconfig ( options . cwd ) || { }
@@ -71,10 +76,9 @@ export function createGeneratePlugin({
7176 }
7277
7378 if ( ! Array . isArray ( options . input ) ) {
74- const cwd = options . cwd || process . cwd ( )
75- for ( const [ fileName , inputFilePath ] of Object . entries ( options . input ) ) {
76- const id = path . resolve ( cwd , inputFilePath )
77- inputAliasMap . set ( id , fileName )
79+ for ( const [ name , id ] of Object . entries ( options . input ) ) {
80+ // `id` should be resolved in `resolveId`
81+ inputAliasMap . set ( id , name )
7882 }
7983 }
8084 } ,
@@ -163,10 +167,28 @@ export function createGeneratePlugin({
163167 } ,
164168 } ,
165169
166- async resolveId ( id , importer ) {
167- // must be entry
170+ async resolveId ( id , importer , extraOptions ) {
168171 if ( dtsMap . has ( id ) ) {
172+ // must be dts entry
169173 return { id, meta }
174+ } else if ( extraOptions . isEntry && inputAliasMap . has ( id ) ) {
175+ // resolve id for inputAliasMap
176+ let resolution = await this . resolve ( id , importer , {
177+ ...extraOptions ,
178+ skipSelf : true ,
179+ } )
180+ if ( ! resolution ) {
181+ resolution = await this . resolve ( path . resolve ( cwd , id ) , importer , {
182+ ...extraOptions ,
183+ skipSelf : true ,
184+ } )
185+ if ( ! resolution ) return
186+ }
187+
188+ const alias = inputAliasMap . get ( id ) !
189+ inputAliasMap . delete ( id )
190+ inputAliasMap . set ( resolution . id , alias )
191+ return resolution
170192 }
171193
172194 if ( importer && this . getModuleInfo ( importer ) ?. meta . dtsFile ) {
0 commit comments