package.json main as indexed subdir
authorisaacs <i@izs.me>
Thu, 17 Feb 2011 20:00:39 +0000 (12:00 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Fri, 18 Feb 2011 18:43:06 +0000 (10:43 -0800)
Closes GH-686.

lib/module.js
test/fixtures/packages/main-index/package-main-module/index.js [new file with mode: 0644]
test/fixtures/packages/main-index/package.json [new file with mode: 0644]
test/simple/test-module-loading.js

index f94da1d..ba0b4f3 100644 (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,
diff --git a/test/fixtures/packages/main-index/package-main-module/index.js b/test/fixtures/packages/main-index/package-main-module/index.js
new file mode 100644 (file)
index 0000000..a9fe795
--- /dev/null
@@ -0,0 +1 @@
+exports.ok = "ok"
diff --git a/test/fixtures/packages/main-index/package.json b/test/fixtures/packages/main-index/package.json
new file mode 100644 (file)
index 0000000..13a7d58
--- /dev/null
@@ -0,0 +1,3 @@
+{"name":"package-name"
+,"version":"1.2.3"
+,"main":"package-main-module"}
index 12f685e..4b7062f 100644 (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'),