diff --git a/lib/async.js b/lib/async.js index 5aadbb88..fe96cd23 100644 --- a/lib/async.js +++ b/lib/async.js @@ -5,8 +5,6 @@ var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); module.exports = function resolve (x, opts, cb) { - if (core[x]) return cb(null, x); - if (typeof opts === 'function') { cb = opts; opts = {}; @@ -42,6 +40,7 @@ module.exports = function resolve (x, opts, cb) { else loadNodeModules(x, y, function (err, n, pkg) { if (err) cb(err) else if (n) cb(null, n, pkg) + else if (core[x]) return cb(null, x); else cb(new Error("Cannot find module '" + x + "'")) }); diff --git a/lib/sync.js b/lib/sync.js index a7219606..9daad946 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -5,8 +5,6 @@ var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); module.exports = function (x, opts) { - if (core[x]) return x; - if (!opts) opts = {}; var isFile = opts.isFile || function (file) { try { var stat = fs.statSync(file) } @@ -29,6 +27,8 @@ module.exports = function (x, opts) { if (n) return n; } + if (core[x]) return x; + throw new Error("Cannot find module '" + x + "'"); function loadAsFileSync (x) { diff --git a/test/resolver.js b/test/resolver.js index 63c530ea..9ace416b 100644 --- a/test/resolver.js +++ b/test/resolver.js @@ -268,3 +268,13 @@ test('without basedir', function (t) { }); }); +test('#25: node modules with the same name as node stdlib modules', function (t) { + t.plan(1); + + var resolverDir = __dirname + '/resolver/punycode'; + + resolve('punycode', { basedir : resolverDir }, function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, resolverDir + '/node_modules/punycode/index.js'); + }); +}); diff --git a/test/resolver/punycode/node_modules/punycode/index.js b/test/resolver/punycode/node_modules/punycode/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/resolver_sync.js b/test/resolver_sync.js index 79168899..5f808f34 100644 --- a/test/resolver_sync.js +++ b/test/resolver_sync.js @@ -156,7 +156,6 @@ test('other path', function (t) { t.end(); }); - test('incorrect main', function (t) { var resolverDir = __dirname + '/resolver'; var dir = resolverDir + '/incorrect_main'; @@ -168,3 +167,14 @@ test('incorrect main', function (t) { t.end() }); + +test('#25: node modules with the same name as node stdlib modules', function (t) { + var resolverDir = __dirname + '/resolver/punycode'; + + t.equal( + resolve.sync('punycode', { basedir : resolverDir }), + resolverDir + '/node_modules/punycode/index.js' + ) + + t.end() +});