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` (#256)
  • Loading branch information
Mark Molinaro authored and ljharb committed Nov 1, 2021
1 parent 18c5ad5 commit d688575
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 d688575

Please sign in to comment.