-
Notifications
You must be signed in to change notification settings - Fork 0
/
dep-list.mjs
43 lines (31 loc) · 918 Bytes
/
dep-list.mjs
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
#!/usr/bin/env node
import glob from 'glob';
import { promises as fs } from 'fs';
const map = {};
glob('./modules/*/package.json', { cwd: process.cwd() }, async(error, files) => {
if (error !== null) {
throw error;
}
for (const file of files) {
const { name, peerDependencies } = JSON.parse(await fs.readFile(file, {encoding: 'utf-8'}));
let dependencies = [];
if (peerDependencies) {
dependencies = dependencies.concat(Object.keys(peerDependencies));
}
const pkg = getPackage(name);
pkg.dependencies = dependencies;
dependencies.forEach((dep) => {
getPackage(dep).dependants.push(name);
});
}
console.log(map);
});
function getPackage(name) {
if (!(name in map)) {
map[name] = {
dependencies: [],
dependants: []
};
}
return map[name];
}