Skip to content

Commit

Permalink
Seek ENOENTness rather than asking existsSync
Browse files Browse the repository at this point in the history
  • Loading branch information
valadaptive committed Feb 22, 2024
1 parent a6689a6 commit 59b5035
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ function createSyncImportHook() {
function tryReadFileSync(str) {
if (
typeof str == 'string' &&
str.indexOf(path.sep) !== -1 &&
fs.existsSync(str)
str.indexOf(path.sep) !== -1
) {
// Try interpreting `str` as path to a file.
return fs.readFileSync(str, {encoding: 'utf8'});
try {
// Try interpreting `str` as path to a file.
return fs.readFileSync(str, {encoding: 'utf8'});
} catch (err) {
// If the file doesn't exist, return `null`. Rethrow all other errors.
if (err.code !== 'ENOENT') throw err;
}
}
return null;
}
Expand Down

0 comments on commit 59b5035

Please sign in to comment.