enhanced-resolve
enhanced-resolve copied to clipboard
Use throwIfNoEntry for sync resolver once graceful-fs supports it
For cases of using sync resolver, throwIfNoEntry improves stat fail case by a large margin. The API in node is backwards compatible, so we should just be able to add this option and be on our way.
Unfortunately, there is an issue with this option in graceful-fs, so I have opened an issue there. Once resolved, this should be unblocked and easy change here.
https://github.com/isaacs/node-graceful-fs/issues/221
const fs = require("fs");
function oldStat(path) {
let stat;
try {
stat = fs.statSync(path);
} catch (e) {
if (!(e && (e.code === "ENOENT" || e.code === "ENOTDIR"))) {
throw e;
}
}
}
console.time("oldStat");
for (let i = 0; i < 100000; i++) oldStat("not-real-path");
console.timeEnd("oldStat"); // 6.7s
function newStat(path) {
let stat = fs.statSync(path, { throwIfNoEntry: false });
}
console.time("newStat");
for (let i = 0; i < 100000; i++) newStat("not-real-path");
console.timeEnd("newStat"); // 2.1s
Make sense, PR welcome