From 78a7dc2b8f123f15be1a3ad05e1cb5b480983881 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 11 Dec 2014 01:37:03 -0600 Subject: [PATCH] module: fix regression in require ../ Fixes regression in require system that prevented loading relative packages via main property in package.json where the file is not index.{ext}. The regression was introduced in commit 36777d2. PR-URL: https://github.com/iojs/io.js/pull/145 Reviewed-By: Ben Noordhuis --- lib/module.js | 4 ++++ test/fixtures/require-bin/bin/req.js | 1 + test/fixtures/require-bin/lib/req.js | 1 + test/fixtures/require-bin/package.json | 4 ++++ test/simple/test-require-extensions-main.js | 4 ++++ 5 files changed, 14 insertions(+) create mode 100644 test/fixtures/require-bin/bin/req.js create mode 100644 test/fixtures/require-bin/lib/req.js create mode 100644 test/fixtures/require-bin/package.json create mode 100644 test/simple/test-require-extensions-main.js diff --git a/lib/module.js b/lib/module.js index 3eb3d3cb2db..5c18d943037 100644 --- a/lib/module.js +++ b/lib/module.js @@ -186,6 +186,10 @@ Module._findPath = function(request, paths) { } } + if (!filename) { + filename = tryPackage(basePath, exts); + } + if (!filename) { // try it with each of the extensions at "index" filename = tryExtensions(path.resolve(basePath, 'index'), exts); diff --git a/test/fixtures/require-bin/bin/req.js b/test/fixtures/require-bin/bin/req.js new file mode 100644 index 00000000000..4b2e02c0cc1 --- /dev/null +++ b/test/fixtures/require-bin/bin/req.js @@ -0,0 +1 @@ +module.exports = require('../'); diff --git a/test/fixtures/require-bin/lib/req.js b/test/fixtures/require-bin/lib/req.js new file mode 100644 index 00000000000..9dc5fc1e4a4 --- /dev/null +++ b/test/fixtures/require-bin/lib/req.js @@ -0,0 +1 @@ +module.exports = ''; diff --git a/test/fixtures/require-bin/package.json b/test/fixtures/require-bin/package.json new file mode 100644 index 00000000000..5ffac0c1e36 --- /dev/null +++ b/test/fixtures/require-bin/package.json @@ -0,0 +1,4 @@ +{ + "name": "req", + "main": "./lib/req.js" +} diff --git a/test/simple/test-require-extensions-main.js b/test/simple/test-require-extensions-main.js new file mode 100644 index 00000000000..032f2eb2c98 --- /dev/null +++ b/test/simple/test-require-extensions-main.js @@ -0,0 +1,4 @@ +var common = require('../common'); +var assert = require('assert'); + +require(common.fixturesDir + '/require-bin/bin/req.js');