Skip to content

Commit

Permalink
[Refactor] sync: Do not throw on missing files in isFile/`isDirec…
Browse files Browse the repository at this point in the history
…tory`
  • Loading branch information
Mark Molinaro authored and ljharb committed Nov 1, 2021
1 parent 0953f42 commit 1382486
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ var realpathFS = fs.realpathSync && typeof fs.realpathSync.native === 'function'

var defaultIsFile = function isFile(file) {
try {
var stat = fs.statSync(file);
var stat = fs.statSync(file, { throwIfNoEntry: false });
} catch (e) {
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
throw e;
}
return stat.isFile() || stat.isFIFO();
return !!stat && (stat.isFile() || stat.isFIFO());
};

var defaultIsDir = function isDirectory(dir) {
try {
var stat = fs.statSync(dir);
var stat = fs.statSync(dir, { throwIfNoEntry: false });
} catch (e) {
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
throw e;
}
return stat.isDirectory();
return !!stat && stat.isDirectory();
};

var defaultRealpathSync = function realpathSync(x) {
Expand Down

0 comments on commit 1382486

Please sign in to comment.