-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.5 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const pacote = require('pacote');
const getTree = require('get-dep-tree');
const packumentCache = new Map();
const fullMetadata = true;
const defaultLogger = (x) => console.error(x);
module.exports = async function listPublishers(mode, { dev, peer, production, logger = defaultLogger } = {}) {
const tree = await getTree(mode, { dev, fullMetadata, logger, packumentCache, peer, production });
const byPackage = new Map();
const byPublisher = new Map();
await Promise.allSettled(Array.from(tree.inventory.values(), async (node) => {
if (!node.isProjectRoot) {
const packument = await pacote.packument(node.packageName, { fullMetadata, packumentCache }).catch((e) => {
console.warn(`no published package found: ${node.packageName}`);
throw e;
});
if (!byPackage.has(node.packageName)) {
byPackage.set(node.packageName, new Map());
}
const versions = byPackage.get(node.packageName);
Object.entries(packument.versions)
.filter(([v]) => v === node.version)
.forEach(([v, { _npmUser: u }]) => {
const publisher = typeof u === 'string' ? { name: u } : u;
if (publisher) {
if (!byPublisher.has(publisher.name)) {
byPublisher.set(publisher.name, new Set());
}
byPublisher.get(publisher.name).add({
name: node.packageName,
publisher,
version: v,
});
versions.set(v, u);
} else {
console.warn(`no publisher found: ${node.packageName}@${v}`);
}
});
}
}));
return { byPackage, byPublisher };
};