@@ -4,6 +4,7 @@ const { SourceMapConsumer } = require('source-map');
4
4
const path = require ( 'path' ) ;
5
5
const yargs = require ( 'yargs/yargs' ) ;
6
6
const { hideBin } = require ( 'yargs/helpers' ) ;
7
+ const prettier = require ( 'prettier' ) ;
7
8
8
9
const argv = yargs ( hideBin ( process . argv ) )
9
10
. usage ( 'Usage: $0 [options]' )
@@ -44,8 +45,12 @@ const handleFile = async (minifiedFilePath) => {
44
45
if ( sourceContents [ source ] !== null ) {
45
46
const originalFilePath = path . join ( path . dirname ( minifiedFilePath ) , path . basename ( source , '.js' ) + '' ) ;
46
47
fs . mkdirSync ( path . dirname ( originalFilePath ) , { recursive : true } ) ;
47
- fs . writeFileSync ( originalFilePath , sourceContents [ source ] ) ;
48
- console . log ( `Source code recovered to ${ originalFilePath } ` ) ;
48
+ try {
49
+ await fs . promises . writeFile ( originalFilePath , sourceContents [ source ] ) ;
50
+ console . log ( `Source code recovered to ${ originalFilePath } ` ) ;
51
+ } catch ( error ) {
52
+ console . error ( `Error saving file ${ originalFilePath } :` , error ) ;
53
+ }
49
54
}
50
55
}
51
56
} else {
@@ -82,8 +87,12 @@ const handleFile = async (minifiedFilePath) => {
82
87
83
88
const originalFilePath = path . join ( path . dirname ( minifiedFilePath ) , path . basename ( minifiedFilePath , '.js' ) + '-recovered.js' ) ;
84
89
fs . mkdirSync ( path . dirname ( originalFilePath ) , { recursive : true } ) ;
85
- fs . writeFileSync ( originalFilePath , reconstructedSource ) ;
86
- console . log ( `Source code recovered to ${ originalFilePath } ` ) ;
90
+ try {
91
+ await fs . promises . writeFile ( originalFilePath , reconstructedSource ) ;
92
+ console . log ( `Source code recovered to ${ originalFilePath } ` ) ;
93
+ } catch ( error ) {
94
+ console . error ( `Error saving file ${ originalFilePath } :` , error ) ;
95
+ }
87
96
}
88
97
} ) ;
89
98
} ;
0 commit comments