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

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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