@@ -17,26 +17,44 @@ async function documents(): Promise<void> {
17
17
await fs . promises . link ( `${ ROOT } /${ file } ` , `${ DIST } /${ file } ` ) ;
18
18
}
19
19
20
- async function module ( ) : Promise < void > {
21
- const javascript = async ( location : string , file : string ) => {
22
- const content : string = await fs . promises . readFile ( location , "utf8" ) ;
23
- const replaced : string = content
24
- . replace ( / ( i m p o r t | e x p o r t ) ( . * ) f r o m " ( . \/ | .. \/ ) ( . * ) " / g , str => {
20
+ const substitude =
21
+ ( content : string ) =>
22
+ content . replace (
23
+ / ( i m p o r t | e x p o r t ) ( . * ) f r o m " ( . \/ | .. \/ ) ( . * ) " / g ,
24
+ str => {
25
25
const to : number = str . lastIndexOf ( `"` ) ;
26
26
return [
27
27
str . substring ( 0 , to ) ,
28
28
`.mjs"` ,
29
29
str . substring ( to + 1 )
30
30
] . join ( "" ) ;
31
- } )
31
+ }
32
+ ) ;
33
+
34
+ async function module ( ) : Promise < void > {
35
+ const declaration = async ( location : string ) => {
36
+ const content = substitude (
37
+ await fs . promises . readFile ( location , "utf8" )
38
+ ) ;
39
+ await fs . promises . unlink ( location ) ;
40
+ await fs . promises . writeFile (
41
+ `${ location . substring ( 0 , location . length - 5 ) } .d.mts` ,
42
+ content ,
43
+ "utf8"
44
+ ) ;
45
+ } ;
46
+ const javascript = async ( location : string , file : string ) => {
47
+ const content = substitude (
48
+ await fs . promises . readFile ( location , "utf8" )
49
+ )
32
50
. replace (
33
51
`//# sourceMappingURL=${ file } .map` ,
34
52
`//# sourceMappingURL=${ file . substring ( 0 , file . length - 3 ) } .mjs.map`
35
53
) ;
36
54
await fs . promises . unlink ( location ) ;
37
55
await fs . promises . writeFile (
38
56
`${ location . substring ( 0 , location . length - 3 ) } .mjs` ,
39
- replaced ,
57
+ content ,
40
58
"utf8"
41
59
) ;
42
60
} ;
@@ -52,6 +70,7 @@ async function module(): Promise<void> {
52
70
"utf8"
53
71
) ;
54
72
} ;
73
+
55
74
const iterate = async ( path : string ) : Promise < void > => {
56
75
const directory : string [ ] = await fs . promises . readdir ( path ) ;
57
76
for ( const file of directory ) {
@@ -61,6 +80,8 @@ async function module(): Promise<void> {
61
80
if ( stats . isDirectory ( ) ) await iterate ( location ) ;
62
81
else if ( location . substr ( - 3 ) === ".js" )
63
82
await javascript ( location , file ) ;
83
+ else if ( location . substr ( - 5 ) === ".d.ts" )
84
+ await declaration ( location ) ;
64
85
else if ( location . substr ( - 7 ) === ".js.map" )
65
86
await mapper ( location ) ;
66
87
}
0 commit comments