Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,14 @@ Module._resolveFilename = function(request, parent, isMain, options) {

if (typeof options === 'object' && options !== null &&
Array.isArray(options.paths)) {
const fakeParent = new Module('', null);

paths = [];

for (var i = 0; i < options.paths.length; i++) {
const path = options.paths[i];
const lookupPaths = Module._resolveLookupPaths(path, parent, true);
fakeParent.paths = Module._nodeModulePaths(path);
const lookupPaths = Module._resolveLookupPaths(request, fakeParent, true);

if (!paths.includes(path))
paths.push(path);
Expand Down
Empty file.
21 changes: 21 additions & 0 deletions test/fixtures/resolve-paths/default/verify-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
require('../../../common');
const assert = require('assert');
const path = require('path');

// By default, resolving 'dep' should return
// fixturesDir/resolve-paths/default/node_modules/dep/index.js. By setting
// the path to fixturesDir/resolve-paths/default, the 'default' directory
// structure should be ignored.

assert.strictEqual(
require.resolve('dep'),
path.join(__dirname, 'node_modules', 'dep', 'index.js')
);

const paths = [path.resolve(__dirname, '..', 'defined')];

assert.strictEqual(
require.resolve('dep', { paths }),
path.join(paths[0], 'node_modules', 'dep', 'index.js')
);
Empty file.
1 change: 1 addition & 0 deletions test/parallel/test-require-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ assert.strictEqual('path', require.resolve('path'));

// Test configurable resolve() paths.
require(fixtures.path('require-resolve.js'));
require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));