summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/resolve/lib/node-modules-paths.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/resolve/lib/node-modules-paths.js')
-rw-r--r--tools/eslint/node_modules/resolve/lib/node-modules-paths.js35
1 files changed, 16 insertions, 19 deletions
diff --git a/tools/eslint/node_modules/resolve/lib/node-modules-paths.js b/tools/eslint/node_modules/resolve/lib/node-modules-paths.js
index ce0a0d9f2f..1d17249487 100644
--- a/tools/eslint/node_modules/resolve/lib/node-modules-paths.js
+++ b/tools/eslint/node_modules/resolve/lib/node-modules-paths.js
@@ -1,7 +1,8 @@
var path = require('path');
+var parse = path.parse || require('path-parse');
-module.exports = function (start, opts) {
- var modules = opts.moduleDirectory
+module.exports = function nodeModulesPaths(start, opts) {
+ var modules = opts && opts.moduleDirectory
? [].concat(opts.moduleDirectory)
: ['node_modules']
;
@@ -17,22 +18,18 @@ module.exports = function (start, opts) {
prefix = '\\\\';
}
- var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
-
- var parts = start.split(splitRe);
+ var paths = [start];
+ var parsed = parse(start);
+ while (parsed.dir !== paths[paths.length - 1]) {
+ paths.push(parsed.dir);
+ parsed = parse(parsed.dir);
+ }
- var dirs = [];
- for (var i = parts.length - 1; i >= 0; i--) {
- if (modules.indexOf(parts[i]) !== -1) continue;
- dirs = dirs.concat(modules.map(function(module_dir) {
- return prefix + path.join(
- path.join.apply(path, parts.slice(0, i + 1)),
- module_dir
- );
+ var dirs = paths.reduce(function (dirs, aPath) {
+ return dirs.concat(modules.map(function (moduleDir) {
+ return path.join(prefix, aPath, moduleDir);
}));
- }
- if (process.platform === 'win32'){
- dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\");
- }
- return dirs.concat(opts.paths);
-}
+ }, []);
+
+ return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
+};