-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm.js
40 lines (30 loc) · 813 Bytes
/
npm.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
import { execa } from "execa";
import { cacheResponse, readCachedResponse } from "./cache.js";
import { NOT_AUTHORIZED, NOT_FOUND } from "./info-buckets.js";
export async function getPackageInfo(name) {
let cached = await readCachedResponse(name);
if (cached) {
return cached;
}
try {
let { stdout } = await execa`npm info ${name} --json`;
let json = JSON.parse(stdout);
await cacheResponse(name, json);
return json;
} catch (e) {
if (typeof e === "object" && e !== null) {
if ("message" in e) {
let msg = e.message;
if (msg.includes("code E404")) {
NOT_FOUND.add(name);
return;
}
if (msg.includes("code E401")) {
NOT_AUTHORIZED.add(name);
return;
}
}
}
throw e;
}
}