@@ -3,21 +3,21 @@ import { readFileSync, writeFileSync, readdirSync, unlinkSync } from 'node:fs';
33const packagePath = process . cwd ( ) ;
44const typesDir = `${ packagePath } /types` ;
55
6- function rename ( path , ext ) {
7- return path . replace ( / \. t s ( \. m a p ) ? $ / , `.${ ext } $1` ) ;
8- }
9-
106const from = / \b f r o m ( [ ' " ] ) ( \. [ ^ ' " ] * ) \1; / g;
7+ const tsExt = / \. t s ( \. m a p ) ? $ / ;
8+
119for ( const file of readdirSync ( typesDir ) ) {
1210 if ( ! file . endsWith ( '.d.ts' ) && ! file . endsWith ( '.d.ts.map' ) ) continue ;
1311
1412 const path = `${ typesDir } /${ file } ` ;
1513 const contents = readFileSync ( path , 'utf8' ) ;
1614
17- const cts = contents . replace ( / ^ e x p o r t d e f a u l t / gm, 'export =' ) . replace ( from , 'from $1$2.cts$1;' ) ;
15+ const cts = contents
16+ . replace ( / ^ e x p o r t d e f a u l t / gm, 'export = ' )
17+ . replace ( from , 'from $1$2.cts$1;' ) ;
1818 const mts = contents . replace ( from , 'from $1$2.mts$1;' ) ;
1919
2020 unlinkSync ( path ) ;
21- writeFileSync ( rename ( path , ' cts' ) , cts ) ;
22- writeFileSync ( rename ( path , ' mts' ) , mts ) ;
21+ writeFileSync ( path . replace ( tsExt , `. cts$1` ) , cts ) ;
22+ writeFileSync ( path . replace ( tsExt , `. mts$1` ) , mts ) ;
2323}
0 commit comments