package.json main as indexed subdir

Closes GH-686.
This commit is contained in:
isaacs
2011-02-17 12:00:39 -08:00
committed by Ryan Dahl
parent aac5cbe025
commit f8defa3e09
4 changed files with 8 additions and 1 deletions

View File

@@ -85,7 +85,8 @@ function tryPackage(requestPath, exts) {
if (!pkg || !pkg.main) return false;
var filename = path.resolve(requestPath, pkg.main);
return tryFile(filename) || tryExtensions(filename, exts);
return tryFile(filename) || tryExtensions(filename, exts) ||
tryExtensions(path.resolve(filename, 'index'), exts);
}
// In order to minimize unnecessary lstat() calls,

View File

@@ -0,0 +1 @@
exports.ok = "ok"

View File

@@ -0,0 +1,3 @@
{"name":"package-name"
,"version":"1.2.3"
,"main":"package-main-module"}

View File

@@ -70,6 +70,8 @@ assert.notEqual(threeFolder, three);
common.debug('test package.json require() loading');
assert.equal(require('../fixtures/packages/main').ok, 'ok',
'Failed loading package');
assert.equal(require('../fixtures/packages/main-index').ok, 'ok',
'Failed loading package with index.js in main subdir');
common.debug('test cycles containing a .. path');
var root = require('../fixtures/cycles/root'),