Skip to content

Commit

Permalink
[refactor] sync: check existence of node_modules
Browse files Browse the repository at this point in the history
This brings the same perf improvements as in 4cf8928 / browserify#190
  • Loading branch information
keithamus authored and ljharb committed May 14, 2019
1 parent bf3a9cd commit b7f1805
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ module.exports = function (x, options) {
var dirs = nodeModulesPaths(start, opts, x);
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var m = loadAsFileSync(path.join(dir, '/', x));
if (m) return m;
var n = loadAsDirectorySync(path.join(dir, '/', x));
if (n) return n;
if (isDirectory(dir)) {
var m = loadAsFileSync(path.join(dir, '/', x));
if (m) return m;
var n = loadAsDirectorySync(path.join(dir, '/', x));
if (n) return n;
}
}
}
};
2 changes: 2 additions & 0 deletions test/mock_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('mock', function (t) {

var dirs = {};
dirs[path.resolve('/foo/bar')] = true;
dirs[path.resolve('/foo/node_modules')] = true;

function opts(basedir) {
return {
Expand Down Expand Up @@ -56,6 +57,7 @@ test('mock package', function (t) {

var dirs = {};
dirs[path.resolve('/foo')] = true;
dirs[path.resolve('/foo/node_modules')] = true;

function opts(basedir) {
return {
Expand Down

0 comments on commit b7f1805

Please sign in to comment.