Skip to content

Commit 9637b60

Browse files
michaelficarraJames Halliday
authored andcommitted
fixes #25: resolve modules with the same name as node stdlib modules
1 parent 281b336 commit 9637b60

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

lib/async.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ var caller = require('./caller.js');
55
var nodeModulesPaths = require('./node-modules-paths.js');
66

77
module.exports = function resolve (x, opts, cb) {
8-
if (core[x]) return cb(null, x);
9-
108
if (typeof opts === 'function') {
119
cb = opts;
1210
opts = {};
@@ -42,6 +40,7 @@ module.exports = function resolve (x, opts, cb) {
4240
else loadNodeModules(x, y, function (err, n, pkg) {
4341
if (err) cb(err)
4442
else if (n) cb(null, n, pkg)
43+
else if (core[x]) return cb(null, x);
4544
else cb(new Error("Cannot find module '" + x + "'"))
4645
});
4746

lib/sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ var caller = require('./caller.js');
55
var nodeModulesPaths = require('./node-modules-paths.js');
66

77
module.exports = function (x, opts) {
8-
if (core[x]) return x;
9-
108
if (!opts) opts = {};
119
var isFile = opts.isFile || function (file) {
1210
try { var stat = fs.statSync(file) }
@@ -29,6 +27,8 @@ module.exports = function (x, opts) {
2927
if (n) return n;
3028
}
3129

30+
if (core[x]) return x;
31+
3232
throw new Error("Cannot find module '" + x + "'");
3333

3434
function loadAsFileSync (x) {

test/resolver.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,13 @@ test('without basedir', function (t) {
268268
});
269269
});
270270

271+
test('#25: node modules with the same name as node stdlib modules', function (t) {
272+
t.plan(1);
273+
274+
var resolverDir = __dirname + '/resolver/punycode';
275+
276+
resolve('punycode', { basedir : resolverDir }, function (err, res, pkg) {
277+
if (err) t.fail(err);
278+
t.equal(res, resolverDir + '/node_modules/punycode/index.js');
279+
});
280+
});

test/resolver/punycode/node_modules/punycode/index.js

Whitespace-only changes.

test/resolver_sync.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ test('other path', function (t) {
156156
t.end();
157157
});
158158

159-
160159
test('incorrect main', function (t) {
161160
var resolverDir = __dirname + '/resolver';
162161
var dir = resolverDir + '/incorrect_main';
@@ -168,3 +167,14 @@ test('incorrect main', function (t) {
168167

169168
t.end()
170169
});
170+
171+
test('#25: node modules with the same name as node stdlib modules', function (t) {
172+
var resolverDir = __dirname + '/resolver/punycode';
173+
174+
t.equal(
175+
resolve.sync('punycode', { basedir : resolverDir }),
176+
resolverDir + '/node_modules/punycode/index.js'
177+
)
178+
179+
t.end()
180+
});

0 commit comments

Comments
 (0)