source: imaps-frontend/node_modules/resolve/lib/node-modules-paths.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1var path = require('path');
2var parse = path.parse || require('path-parse'); // eslint-disable-line global-require
3
4var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
5 var prefix = '/';
6 if ((/^([A-Za-z]:)/).test(absoluteStart)) {
7 prefix = '';
8 } else if ((/^\\\\/).test(absoluteStart)) {
9 prefix = '\\\\';
10 }
11
12 var paths = [absoluteStart];
13 var parsed = parse(absoluteStart);
14 while (parsed.dir !== paths[paths.length - 1]) {
15 paths.push(parsed.dir);
16 parsed = parse(parsed.dir);
17 }
18
19 return paths.reduce(function (dirs, aPath) {
20 return dirs.concat(modules.map(function (moduleDir) {
21 return path.resolve(prefix, aPath, moduleDir);
22 }));
23 }, []);
24};
25
26module.exports = function nodeModulesPaths(start, opts, request) {
27 var modules = opts && opts.moduleDirectory
28 ? [].concat(opts.moduleDirectory)
29 : ['node_modules'];
30
31 if (opts && typeof opts.paths === 'function') {
32 return opts.paths(
33 request,
34 start,
35 function () { return getNodeModulesDirs(start, modules); },
36 opts
37 );
38 }
39
40 var dirs = getNodeModulesDirs(start, modules);
41 return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
42};
Note: See TracBrowser for help on using the repository browser.