Skip to content

Commit 4b249b6

Browse files
committed
Fix prettier not defined and error saving file
Related to #4 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/puntorigen/recover-source/issues/4?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 9a0580a commit 4b249b6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

index.js

100755100644
+13-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { SourceMapConsumer } = require('source-map');
44
const path = require('path');
55
const yargs = require('yargs/yargs');
66
const { hideBin } = require('yargs/helpers');
7+
const prettier = require('prettier');
78

89
const argv = yargs(hideBin(process.argv))
910
.usage('Usage: $0 [options]')
@@ -44,8 +45,12 @@ const handleFile = async (minifiedFilePath) => {
4445
if (sourceContents[source] !== null) {
4546
const originalFilePath = path.join(path.dirname(minifiedFilePath), path.basename(source, '.js') + '');
4647
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+
}
4954
}
5055
}
5156
} else {
@@ -82,8 +87,12 @@ const handleFile = async (minifiedFilePath) => {
8287

8388
const originalFilePath = path.join(path.dirname(minifiedFilePath), path.basename(minifiedFilePath, '.js') + '-recovered.js');
8489
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+
}
8796
}
8897
});
8998
};

0 commit comments

Comments
 (0)