Skip to content

Commit

Permalink
nearly nearly working
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Feb 17, 2015
1 parent 644f814 commit e7bffbf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/async.js
Expand Up @@ -37,7 +37,7 @@ module.exports = function resolve (x, opts, cb) {
loadAsFile(res, opts.package, function (err, m, pkg) {
if (err) cb(err)
else if (m) cb(null, m, pkg)
else loadAsDirectory(path.resolve(y, x), function (err, d, pkg) {
else loadAsDirectory(res, function (err, d, pkg) {
if (err) cb(err)
else if (d) cb(null, d, pkg)
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
Expand All @@ -51,20 +51,21 @@ module.exports = function resolve (x, opts, cb) {
else cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
});

function loadAsFile (x, pkg, cb) {
function loadAsFile (x, pkg, cb, again) {
if (typeof pkg === 'function') {
cb = pkg;
pkg = undefined;
}

var exts = [''].concat(extensions);

if (x === y) {
return loadAsDirectory(y, pkg, cb);
}
else {
return load(exts, x, pkg);
if (x === y && !again) {
loadAsDirectory(y, pkg, function (err, d, pkg) {
if (d) cb(err, d, pkg)
else loadAsFile(x, pkg, cb, true)
});
}
else load(exts, x, pkg)

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

0 comments on commit e7bffbf

Please sign in to comment.