Skip to content

Commit d688575

Browse files
Mark Molinaroljharb
Mark Molinaro
authored andcommitted
[Refactor] sync: Do not throw on missing files in isFile/isDirectory (#256)
1 parent 18c5ad5 commit d688575

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/sync.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ var realpathFS = fs.realpathSync && typeof fs.realpathSync.native === 'function'
99

1010
var defaultIsFile = function isFile(file) {
1111
try {
12-
var stat = fs.statSync(file);
12+
var stat = fs.statSync(file, { throwIfNoEntry: false });
1313
} catch (e) {
1414
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
1515
throw e;
1616
}
17-
return stat.isFile() || stat.isFIFO();
17+
return !!stat && (stat.isFile() || stat.isFIFO());
1818
};
1919

2020
var defaultIsDir = function isDirectory(dir) {
2121
try {
22-
var stat = fs.statSync(dir);
22+
var stat = fs.statSync(dir, { throwIfNoEntry: false });
2323
} catch (e) {
2424
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
2525
throw e;
2626
}
27-
return stat.isDirectory();
27+
return !!stat && stat.isDirectory();
2828
};
2929

3030
var defaultRealpathSync = function realpathSync(x) {

0 commit comments

Comments
 (0)