Browse Source

Support including modules that don't have an extension.

This way, require("/foo") will work if there is a "foo.js", or a file named
simply "foo" with no extension.
v0.7.4-release
isaacs 15 years ago
committed by Ryan Dahl
parent
commit
d75b63bc3c
  1. 3
      lib/module.js
  2. 2
      test/fixtures/foo
  3. 3
      test/simple/test-module-loading.js

3
lib/module.js

@ -142,7 +142,8 @@ function findModulePath (id, dirs, callback) {
path.join(dir, id + ".js"),
path.join(dir, id + ".node"),
path.join(dir, id, "index.js"),
path.join(dir, id, "index.node")
path.join(dir, id, "index.node"),
path.join(dir, id)
];
var ext;

2
test/fixtures/foo

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

3
test/simple/test-module-loading.js

@ -103,6 +103,9 @@ debug("load modules by absolute id, then change require.paths, and load another
var foo = require("../fixtures/require-path/p1/foo");
process.assert(foo.bar.expect === foo.bar.actual);
assert.equal(require('../fixtures/foo').foo, 'ok',
'require module with no extension');
process.addListener("exit", function () {
assert.equal(true, a.A instanceof Function);
assert.equal("A done", a.A());

Loading…
Cancel
Save