Skip to content

Commit

Permalink
module: allow require('.')
Browse files Browse the repository at this point in the history
Previously, the minimal argument to require the current directory was
require('./'). This commits allows to skip the trailing slash.

Fixes: #1178
PR-URL: #1185
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Christian Tellnes <christian@tellnes.no>
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information
targos authored and silverwind committed Mar 20, 2015
1 parent a0d32ff commit 6fc5e95
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Module._resolveLookupPaths = function(request, parent) {
}

var start = request.substring(0, 2);
if (start !== './' && start !== '..') {
if (start !== '.' && start !== './' && start !== '..') {
var paths = modulePaths;
if (parent) {
if (!parent.paths) parent.paths = [];
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/module-require/relative/dot-slash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./');
1 change: 1 addition & 0 deletions test/fixtures/module-require/relative/dot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('.');
1 change: 1 addition & 0 deletions test/fixtures/module-require/relative/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.value = 42;
6 changes: 6 additions & 0 deletions test/parallel/test-require-extensions-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ var common = require('../common');
var assert = require('assert');

require(common.fixturesDir + '/require-bin/bin/req.js');

var a = require(common.fixturesDir + '/module-require/relative/dot.js');
var b = require(common.fixturesDir + '/module-require/relative/dot-slash.js');

assert.equal(a.value, 42);
assert.equal(a, b, 'require(".") should resolve like require("./")');

0 comments on commit 6fc5e95

Please sign in to comment.