if (!pkg) return false;
var filename = path.resolve(requestPath, pkg);
- return tryFile(filename) || tryExtensions(filename, exts) ||
+ return tryFile(filename, null) || tryExtensions(filename, exts) ||
tryExtensions(path.resolve(filename, 'index'), exts);
}
Module._realpathCache = {};
// check if the file exists and is not a directory
-function tryFile(requestPath) {
- var stats = statPath(requestPath);
+function tryFile(requestPath, stats) {
+ stats = stats || statPath(requestPath);
if (stats && !stats.isDirectory()) {
return fs.realpathSync(requestPath, Module._realpathCache);
}
// given a path check a the file exists with any of the set extensions
function tryExtensions(p, exts) {
for (var i = 0, EL = exts.length; i < EL; i++) {
- var filename = tryFile(p + exts[i]);
+ var filename = tryFile(p + exts[i], null);
if (filename) {
return filename;
if (!trailingSlash) {
var stats = statPath(basePath);
// try to join the request to the path
- filename = tryFile(basePath);
+ filename = tryFile(basePath, stats);
if (!filename && stats && stats.isDirectory()) {
filename = tryPackage(basePath, exts);