Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | var path = require('path');
|
---|
| 2 | var parse = path.parse || require('path-parse');
|
---|
| 3 |
|
---|
| 4 | var 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 |
|
---|
| 26 | module.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.