File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "author" : " The MessagePack community" ,
66 "license" : " ISC" ,
77 "main" : " ./dist/index.js" ,
8- "module" : " ./dist.es5+esm/index.js " ,
8+ "module" : " ./dist.es5+esm/index.mjs " ,
99 "cdn" : " ./dist.es5+umd/msgpack.min.js" ,
1010 "unpkg" : " ./dist.es5+umd/msgpack.min.js" ,
1111 "types" : " ./dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -6,8 +6,19 @@ import fs from "fs";
66const files = process . argv . slice ( 2 ) ;
77
88for ( const file of files ) {
9- console . info ( `Processing ${ file } ` ) ;
10- const content = fs . readFileSync ( file ) . toString ( "utf8" ) ;
11- const newContent = content . replace ( / \b f r o m " ( [ ^ " ] + ) " ; / g, 'from "$1.js";' ) ;
12- fs . writeFileSync ( file , newContent ) ;
9+ const fileMjs = file . replace ( / \. j s $ / , ".mjs" ) ;
10+ console . info ( `Processing ${ file } => ${ fileMjs } ` ) ;
11+ // .js => .mjs
12+ const content = fs . readFileSync ( file ) . toString ( "utf-8" ) ;
13+ const newContent = content . replace ( / \b f r o m " ( [ ^ " ] + ) " ; / g, 'from "$1.mjs";' )
14+ . replace ( / \/ \/ # s o u r c e M a p p i n g U R L = ( .+ ) \. j s \. m a p $ / ,
15+ "//# sourceMappingURL=$1.mjs.map" ) ;
16+ fs . writeFileSync ( fileMjs , newContent ) ;
17+ fs . unlinkSync ( file ) ;
18+
19+ // .js.map => .mjs.map
20+ const mapping = JSON . parse ( fs . readFileSync ( `${ file } .map` ) . toString ( "utf-8" ) ) ;
21+ mapping . file = mapping . file . replace ( / \. j s $ / , ".mjs" ) ;
22+ fs . writeFileSync ( `${ fileMjs } .map` , JSON . stringify ( mapping ) ) ;
23+ fs . unlinkSync ( `${ file } .map` ) ;
1324}
You can’t perform that action at this time.
0 commit comments