Skip to content

Commit 06d5013

Browse files
author
Maël Nison
committed
Implements skipNodeModules
1 parent 0a8fc9f commit 06d5013

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

lib/node-modules-paths.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@ module.exports = function nodeModulesPaths(start, opts) {
2020
}
2121
}
2222

23-
var prefix = '/';
24-
if ((/^([A-Za-z]:)/).test(absoluteStart)) {
25-
prefix = '';
26-
} else if ((/^\\\\/).test(absoluteStart)) {
27-
prefix = '\\\\';
28-
}
23+
var dirs = [];
2924

30-
var paths = [absoluteStart];
31-
var parsed = parse(absoluteStart);
32-
while (parsed.dir !== paths[paths.length - 1]) {
33-
paths.push(parsed.dir);
34-
parsed = parse(parsed.dir);
35-
}
25+
if (!opts || !opts.skipNodeModules) {
26+
var prefix = '/';
27+
if ((/^([A-Za-z]:)/).test(absoluteStart)) {
28+
prefix = '';
29+
} else if ((/^\\\\/).test(absoluteStart)) {
30+
prefix = '\\\\';
31+
}
3632

37-
var dirs = paths.reduce(function (dirs, aPath) {
38-
return dirs.concat(modules.map(function (moduleDir) {
39-
return path.join(prefix, aPath, moduleDir);
40-
}));
41-
}, []);
33+
var paths = [absoluteStart];
34+
var parsed = parse(absoluteStart);
35+
while (parsed.dir !== paths[paths.length - 1]) {
36+
paths.push(parsed.dir);
37+
parsed = parse(parsed.dir);
38+
}
39+
40+
dirs = paths.reduce(function (dirs, aPath) {
41+
return dirs.concat(modules.map(function (moduleDir) {
42+
return path.join(prefix, aPath, moduleDir);
43+
}));
44+
}, []);
45+
}
4246

4347
return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
4448
};

test/node-modules-paths.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ test('node-modules-paths', function (t) {
4949
t.end();
5050
});
5151

52+
t.test('with skipNodeModules=true option', function (t) {
53+
var start = path.join(__dirname, 'resolver');
54+
var dirs = nodeModulesPaths(start, { skipNodeModules: true });
55+
t.deepEqual(dirs, [], 'no node_modules was computed');
56+
t.end();
57+
});
58+
5259
t.test('with paths option', function (t) {
5360
var start = path.join(__dirname, 'resolver');
5461
var paths = ['a', 'b'];

0 commit comments

Comments
 (0)