Skip to content

Commit ca804f5

Browse files
module: Only resolve to _-prefixed filename if needed
* Fixes `test-cwd-enoent-preload.js` * Minor performance improvement
1 parent 0ef4591 commit ca804f5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/module.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,15 @@ Module._findPath = function(request, paths, isMain) {
193193
var curPath = paths[i];
194194
if (curPath && stat(curPath) < 1) continue;
195195

196-
// If _basePath is a symlink, use the real path rather than the path of the
197-
// symlink as cache key.
198-
var _basePath = path.resolve(curPath, '_' + request);
199196
var basePath = path.resolve(curPath, request);
197+
var filename = tryFindPath(basePath, exts, isMain, isAbsolute)
200198

201-
var filename = tryFindPath(basePath, exts, isMain, isAbsolute) ||
202-
tryFindPath(_basePath, exts, true, isAbsolute);
199+
if (!filename) {
200+
// If _basePath is a symlink, use the real path rather than the path of
201+
// the symlink as cache key.
202+
basePath = path.resolve(curPath, '_' + request);
203+
filename = tryFindPath(basePath, exts, true, isAbsolute);
204+
}
203205

204206
if (filename) {
205207
// Warn once if '.' resolved outside the module dir

0 commit comments

Comments
 (0)