-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (26 loc) · 801 Bytes
/
index.js
File metadata and controls
33 lines (26 loc) · 801 Bytes
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
29
30
31
32
33
'use strict';
var path = require('path');
/**
* Return a list of loaded and required modules.
*
* @returns {Array}
* @api public
*/
module.exports = function moduleLoadList() {
var natives = process.moduleLoadList || []
, cwd = process.cwd();
return natives.concat(Object.keys(require.cache).map(function map(line) {
var dependency = line.lastIndexOf('node_modules');
line = line.split('.').shift();
if (~dependency) {
line = line.slice(dependency + 13);
} else {
line = path.relative(cwd, line);
if (line.charAt(0) !== '.') line = './'+ line;
}
line = line.split('/').filter(Boolean);
if (line[line.length - 1] === 'index') line.pop();
if (!line.length) return;
return 'UserModule '+ line.join('/');
})).filter(Boolean);
};