Skip to content

Commit 70146a5

Browse files
author
James Halliday
committed
path logic fix that seems to handle all the cases across this package and browserify
1 parent e7bffbf commit 70146a5

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

lib/async.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ module.exports = function resolve (x, opts, cb) {
3434
if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) {
3535
var res = path.resolve(y, x);
3636
if (x === '..') res += '/';
37-
loadAsFile(res, opts.package, function (err, m, pkg) {
38-
if (err) cb(err)
39-
else if (m) cb(null, m, pkg)
40-
else loadAsDirectory(res, function (err, d, pkg) {
41-
if (err) cb(err)
42-
else if (d) cb(null, d, pkg)
43-
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
44-
})
45-
});
37+
if (/\/$/.test(x) && res === y) {
38+
loadAsDirectory(res, opts.package, onfile);
39+
}
40+
else loadAsFile(res, opts.package, onfile);
4641
}
4742
else loadNodeModules(x, y, function (err, n, pkg) {
4843
if (err) cb(err)
@@ -51,21 +46,24 @@ module.exports = function resolve (x, opts, cb) {
5146
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
5247
});
5348

54-
function loadAsFile (x, pkg, cb, again) {
49+
function onfile (err, m, pkg) {
50+
if (err) cb(err)
51+
else if (m) cb(null, m, pkg)
52+
else loadAsDirectory(res, function (err, d, pkg) {
53+
if (err) cb(err)
54+
else if (d) cb(null, d, pkg)
55+
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
56+
})
57+
}
58+
59+
function loadAsFile (x, pkg, cb) {
5560
if (typeof pkg === 'function') {
5661
cb = pkg;
5762
pkg = undefined;
5863
}
5964

6065
var exts = [''].concat(extensions);
61-
62-
if (x === y && !again) {
63-
loadAsDirectory(y, pkg, function (err, d, pkg) {
64-
if (d) cb(err, d, pkg)
65-
else loadAsFile(x, pkg, cb, true)
66-
});
67-
}
68-
else load(exts, x, pkg)
66+
load(exts, x, pkg)
6967

7068
function load (exts, x, pkg) {
7169
if (exts.length === 0) return cb(null, undefined, pkg);

0 commit comments

Comments
 (0)