Skip to content

Commit d75b63b

Browse files
isaacsry
authored andcommitted
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.
1 parent 7067a71 commit d75b63b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/module.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ function findModulePath (id, dirs, callback) {
142142
path.join(dir, id + ".js"),
143143
path.join(dir, id + ".node"),
144144
path.join(dir, id, "index.js"),
145-
path.join(dir, id, "index.node")
145+
path.join(dir, id, "index.node"),
146+
path.join(dir, id)
146147
];
147148

148149
var ext;

test/fixtures/foo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
exports.foo = "ok"

test/simple/test-module-loading.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ debug("load modules by absolute id, then change require.paths, and load another
103103
var foo = require("../fixtures/require-path/p1/foo");
104104
process.assert(foo.bar.expect === foo.bar.actual);
105105

106+
assert.equal(require('../fixtures/foo').foo, 'ok',
107+
'require module with no extension');
108+
106109
process.addListener("exit", function () {
107110
assert.equal(true, a.A instanceof Function);
108111
assert.equal("A done", a.A());

0 commit comments

Comments
 (0)