Skip to content

Commit

Permalink
fixes #25: resolve modules with the same name as node stdlib modules
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra authored and James Halliday committed Nov 26, 2013
1 parent 281b336 commit 9637b60
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 + "'"))
});

Expand Down
4 changes: 2 additions & 2 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Empty file.
12 changes: 11 additions & 1 deletion test/resolver_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()
});

0 comments on commit 9637b60

Please sign in to comment.