Skip to content

Commit 28c0294

Browse files
authored
access path only if it exists (#5114)
1 parent c55f5b0 commit 28c0294

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

scripts/exp/remove-exp.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,26 @@
2121
*/
2222
const { argv } = require('yargs');
2323
const path = require('path');
24-
const { readdirSync, statSync, readFileSync, writeFileSync } = require('fs');
24+
const {
25+
readdirSync,
26+
statSync,
27+
readFileSync,
28+
writeFileSync,
29+
accessSync
30+
} = require('fs');
2531

2632
// can be used in command line
2733
if (argv._[0]) {
2834
const dirOrFile = path.resolve(argv._[0]);
29-
if (statSync(dirOrFile).isFile()) {
30-
removeExpSuffixFromFile(dirOrFile);
31-
} else {
32-
removeExpSuffix(dirOrFile);
33-
}
35+
36+
try {
37+
accessSync(dirOrFile);
38+
if (statSync(dirOrFile).isFile()) {
39+
removeExpSuffixFromFile(dirOrFile);
40+
} else {
41+
removeExpSuffix(dirOrFile);
42+
}
43+
} catch (_err) {}
3444
}
3545

3646
function removeExpSuffix(dir) {

0 commit comments

Comments
 (0)