-
Notifications
You must be signed in to change notification settings - Fork 5
/
get_npm_deps_cli.js
executable file
·52 lines (39 loc) · 1.27 KB
/
get_npm_deps_cli.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Command line tool which gets all transitive dependencies for a given npm package
// Shows every package that will be installed whenever a user requests the given package
if (process.argv[2] == undefined) {
console.log('Usage: node get_npm_deps_cli.js [package_name]');
process.exit(1);
}
var ls = require('npm-remote-ls').ls;
var config = require('npm-remote-ls').config;
config({
development: false
});
package_name = process.argv[2];
function clean_deps(dependency_tree) {
let temp_set = new Set();
if (dependency_tree == []) {
return null;
}
for (let package of dependency_tree) {
// remove version number
let package_name = null;
if (package[0] == '@') {
let at_index = package.indexOf('@', 1);
package_name = package.substring(0, at_index);
} else {
package_name = package.split('@')[0];
}
// add package name to set
temp_set.add(package_name);
}
return Array.from(temp_set);
}
ls(package_name, 'latest', true, (r) => {
let dependencies = clean_deps(r);
if (dependencies != null) {
for (let dependency of dependencies) {
console.log(dependency);
}
}
});