Skip to content

Commit b7f1805

Browse files
keithamusljharb
authored andcommitted
[refactor] sync: check existence of node_modules
This brings the same perf improvements as in 4cf8928 / #190
1 parent bf3a9cd commit b7f1805

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/sync.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,12 @@ module.exports = function (x, options) {
164164
var dirs = nodeModulesPaths(start, opts, x);
165165
for (var i = 0; i < dirs.length; i++) {
166166
var dir = dirs[i];
167-
var m = loadAsFileSync(path.join(dir, '/', x));
168-
if (m) return m;
169-
var n = loadAsDirectorySync(path.join(dir, '/', x));
170-
if (n) return n;
167+
if (isDirectory(dir)) {
168+
var m = loadAsFileSync(path.join(dir, '/', x));
169+
if (m) return m;
170+
var n = loadAsDirectorySync(path.join(dir, '/', x));
171+
if (n) return n;
172+
}
171173
}
172174
}
173175
};

test/mock_sync.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('mock', function (t) {
1010

1111
var dirs = {};
1212
dirs[path.resolve('/foo/bar')] = true;
13+
dirs[path.resolve('/foo/node_modules')] = true;
1314

1415
function opts(basedir) {
1516
return {
@@ -56,6 +57,7 @@ test('mock package', function (t) {
5657

5758
var dirs = {};
5859
dirs[path.resolve('/foo')] = true;
60+
dirs[path.resolve('/foo/node_modules')] = true;
5961

6062
function opts(basedir) {
6163
return {

0 commit comments

Comments
 (0)