From d75b63bc3c56c3a9d8c006db2ac183bfc354204e Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 19 Jul 2010 17:54:49 -0700 Subject: [PATCH] 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. --- lib/module.js | 3 ++- test/fixtures/foo | 2 ++ test/simple/test-module-loading.js | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/foo diff --git a/lib/module.js b/lib/module.js index 313be6221f..0211197042 100644 --- a/lib/module.js +++ b/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; diff --git a/test/fixtures/foo b/test/fixtures/foo new file mode 100644 index 0000000000..66390ff24d --- /dev/null +++ b/test/fixtures/foo @@ -0,0 +1,2 @@ + +exports.foo = "ok" diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 23574643a9..5245e4ea0f 100644 --- a/test/simple/test-module-loading.js +++ b/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());