@@ -3,6 +3,7 @@ import { getTsconfig } from 'get-tsconfig'
33import { isolatedDeclaration as oxcIsolatedDeclaration } from 'oxc-transform'
44import {
55 filename_dts_to ,
6+ filename_js_to_dts ,
67 filename_ts_to_dts ,
78 isRelative ,
89 RE_DTS ,
@@ -165,7 +166,7 @@ export function createGeneratePlugin({
165166 } ,
166167 } ,
167168
168- async resolveId ( id , importer ) {
169+ async resolveId ( id , importer , options ) {
169170 if ( dtsMap . has ( id ) ) {
170171 // must be dts entry
171172 return { id, meta }
@@ -174,9 +175,14 @@ export function createGeneratePlugin({
174175 if ( ! importer || ! this . getModuleInfo ( importer ) ?. meta . dtsFile ) {
175176 return
176177 }
177-
178178 // in dts file
179179
180+ if ( RE_DTS . test ( id ) ) {
181+ const resolution = await this . resolve ( id , importer , options )
182+ if ( ! resolution ) return
183+ return { ...resolution , meta }
184+ }
185+
180186 // resolve dependency
181187 if ( ! isRelative ( id ) ) {
182188 let shouldResolve : boolean
@@ -196,17 +202,29 @@ export function createGeneratePlugin({
196202 }
197203
198204 // link to the original module
199- const resolution = await this . resolve ( id , filename_dts_to ( importer , 'ts' ) )
205+ let resolution = await this . resolve ( id , filename_dts_to ( importer , 'ts' ) )
200206 if ( ! resolution || resolution . external ) return
201207
202- const dtsId = filename_ts_to_dts ( resolution . id )
203- if ( dtsMap . has ( dtsId ) ) {
204- return { id : dtsId , meta }
208+ let dtsId : string
209+ if ( RE_JS . test ( resolution . id ) ) {
210+ // resolve dts for js
211+ resolution = await this . resolve (
212+ filename_js_to_dts ( resolution . id ) ,
213+ importer ,
214+ { skipSelf : false } ,
215+ )
216+ if ( ! resolution ) return
217+ dtsId = resolution . id
218+ } else {
219+ dtsId = filename_ts_to_dts ( resolution . id )
220+ if ( dtsMap . has ( dtsId ) ) {
221+ return { id : dtsId , meta }
222+ }
205223 }
206224
207- // pre-load original module if not already loaded
208225 await this . load ( resolution )
209- if ( dtsMap . has ( dtsId ) ) {
226+
227+ if ( RE_DTS . test ( resolution . id ) || dtsMap . has ( dtsId ) ) {
210228 return { id : dtsId , meta }
211229 }
212230 } ,
0 commit comments