File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,12 @@ export function dts(): Plugin {
6363 return {
6464 ...options ,
6565 resolve : {
66- extensions : [ '.d.ts' ] ,
67- extensionAlias : { '.js' : [ '.d.ts' ] } ,
66+ extensions : [ '.d.ts' , '.d.mts' , '.d.cts' ] ,
67+ extensionAlias : {
68+ '.js' : [ '.d.ts' ] ,
69+ '.mjs' : [ '.d.mts' ] ,
70+ '.cjs' : [ '.d.cts' ] ,
71+ } ,
6872 ...options . resolve ,
6973 } ,
7074 onLog ( level , log , defaultHandler ) {
@@ -386,17 +390,20 @@ function patchVariableDeclarator(
386390 }
387391}
388392
393+ const RE_D_TS = / \. d \. ( [ c m ] ? ) t s $ /
394+
389395// patch `.d.ts` suffix in import source to `.js`
390396function patchImportSource ( s : MagicStringAST , node : Node ) {
391397 if (
392398 ( node . type === 'ImportDeclaration' ||
393399 node . type === 'ExportAllDeclaration' ||
394400 node . type === 'ExportNamedDeclaration' ) &&
395- node . source ?. value . endsWith ( '.d.ts' )
401+ node . source ?. value &&
402+ RE_D_TS . test ( node . source . value )
396403 ) {
397404 s . overwriteNode (
398405 node . source ,
399- JSON . stringify ( ` ${ node . source . value . slice ( 0 , - 4 ) } js` ) ,
406+ JSON . stringify ( node . source . value . replace ( RE_D_TS , '.$1js' ) ) ,
400407 )
401408 return true
402409 }
You can’t perform that action at this time.
0 commit comments