Tolerate ENOENT exceptions from files.realpath in isWithinProdPackage.

This commit is contained in:
Ben Newman
2017-02-08 17:18:30 -05:00
parent e2cf76f8da
commit 365ceb6386

View File

@@ -482,8 +482,9 @@ export class NodeModulesDirectory {
return true;
}
const real = files.realpath(path);
if (real !== path) {
const real = realpathOrNull(path);
if (typeof real === "string" &&
real !== path) {
// If node_modules/.bin/command is a symlink, determine the
// answer by calling isWithinProdPackage(real).
return isWithinProdPackage(real);
@@ -521,6 +522,15 @@ export class NodeModulesDirectory {
}
}
function realpathOrNull(path) {
try {
return files.realpath(path);
} catch (e) {
if (e.code !== "ENOENT") throw e;
return null;
}
}
///////////////////////////////////////////////////////////////////////////////
// File
///////////////////////////////////////////////////////////////////////////////