1 var path = require('path');
3 module.exports = function (start, opts) {
4 var modules = opts.moduleDirectory
5 ? [].concat(opts.moduleDirectory)
9 // ensure that `start` is an absolute path at this point,
10 // resolving against the process' current working directory
11 start = path.resolve(start);
14 if (/^([A-Za-z]:)/.test(start)) {
16 } else if (/^\\\\/.test(start)) {
20 var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
22 var parts = start.split(splitRe);
25 for (var i = parts.length - 1; i >= 0; i--) {
26 if (modules.indexOf(parts[i]) !== -1) continue;
27 dirs = dirs.concat(modules.map(function(module_dir) {
28 return prefix + path.join(
29 path.join.apply(path, parts.slice(0, i + 1)),
34 if (process.platform === 'win32'){
35 dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\");
37 return dirs.concat(opts.paths);