@@ -180,10 +180,6 @@ export async function redirectDtsImports(
180180 return ;
181181 }
182182
183- const extensions = dtsExtension
184- . replace ( / \. d \. t s $ / , '.js' )
185- . replace ( / \. d \. c t s $ / , '.cjs' )
186- . replace ( / \. d \. m t s $ / , '.mjs' ) ;
187183 const content = await fsP . readFile ( dtsFile , 'utf-8' ) ;
188184 const code = new MagicString ( content ) ;
189185 const sgNode = ( await parseAsync ( 'typescript' , content ) ) . root ( ) ;
@@ -231,26 +227,32 @@ export async function redirectDtsImports(
231227 } ;
232228 } ) ;
233229
230+ const result = loadConfig ( tsconfigPath ) ;
231+
232+ if ( result . resultType === 'failed' ) {
233+ logger . error ( result . message ) ;
234+ return ;
235+ }
236+
237+ const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result ;
238+ const matchPath = createMatchPath (
239+ absoluteBaseUrl ,
240+ paths ,
241+ mainFields ,
242+ addMatchAll ,
243+ ) ;
244+
245+ const extensions = dtsExtension
246+ . replace ( / \. d \. t s $ / , '.js' )
247+ . replace ( / \. d \. c t s $ / , '.cjs' )
248+ . replace ( / \. d \. m t s $ / , '.mjs' ) ;
249+
234250 for ( const imp of matchModule ) {
235251 const { n : importPath , s : start , e : end } = imp ;
236252
237253 if ( ! importPath ) continue ;
238254
239255 try {
240- const result = loadConfig ( tsconfigPath ) ;
241-
242- if ( result . resultType === 'failed' ) {
243- logger . error ( result . message ) ;
244- return ;
245- }
246-
247- const { absoluteBaseUrl, paths, mainFields, addMatchAll } = result ;
248- const matchPath = createMatchPath (
249- absoluteBaseUrl ,
250- paths ,
251- mainFields ,
252- addMatchAll ,
253- ) ;
254256 const absoluteImportPath = matchPath ( importPath , undefined , undefined , [
255257 '.jsx' ,
256258 '.tsx' ,
0 commit comments