Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #25: resolve modules with the same name as node stdlib modules #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var path = require('path');
var caller = require('./caller.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 @@ -40,6 +38,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 @@ -4,8 +4,6 @@ var path = require('path');
var caller = require('./caller.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 @@ -28,6 +26,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()
});