-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (22 loc) · 812 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const path = require('path');
const Module = require('module');
const gm = require('global-modules');
module.exports = cwd => {
// backwards compatibility
if (cwd && typeof cwd === 'object') cwd = cwd.cwd;
let isWindows = process.platform === 'win32'
|| process.env.OSTYPE === 'msys'
|| process.env.OSTYPE === 'cygwin';
let paths = new Set(Module._nodeModulePaths(cwd || process.cwd()));
paths.add(gm);
if (process.env.NODE_PATH) {
// this really should be avoided, see https://github.com/nodejs/node/issues/9372
process.env.NODE_PATH.split(path.delimiter).forEach(dir => paths.add(dir));
} else if (isWindows) {
paths.add(path.join(process.env.APPDATA, 'npm', 'node_modules'));
} else {
paths.add('/usr/lib/node_modules');
}
return [...paths];
};