forked from effector/effector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-npm-stats.mjs
96 lines (83 loc) · 2.73 KB
/
get-npm-stats.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as childProcess from "node:child_process";
import { promisify } from "node:util";
const exec = promisify(childProcess.exec);
async function getGzipSize(packageName) {
const response = await fetch(
`https://bundlephobia.com/api/size?package=${packageName}@latest&record=true`,
{
headers: {
accept: "application/json",
"accept-language": "en-GB,en;q=0.9,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.6",
"x-bundlephobia-user": "bundlephobia website",
},
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "omit",
},
);
const { gzip } = await response.json();
if (!gzip) return null;
return gzip / 1024;
}
// Links to web:
// - https://bundlejs.com/?q=effector&treeshake=[*]
// - https://bundlephobia.com/package/effector@latest
// // PACKAGE HISTORY SIZE
// fetch("https://bundlephobia.com/api/package-history?package={PACKAGE_NAME}@latest&limit=500", {
// headers: {
// accept: "application/json",
// "accept-language": "en-GB,en;q=0.9,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.6",
// "x-bundlephobia-user": "bundlephobia website",
// },
// referrerPolicy: "strict-origin-when-cross-origin",
// body: null,
// method: "GET",
// mode: "cors",
// credentials: "omit",
// });
// // FETCH DOWNLOADS COUNT FROM NPM
// fetch("https://npm-stat.com/api/download-counts?package=effector&from=2017-02-01&until=2023-02-19", {
// headers: {
// accept: "application/json, text/javascript, */*; q=0.01",
// "x-requested-with": "XMLHttpRequest",
// },
// referrer: "https://npm-stat.com/charts.html?package=effector&from=2017-02-01&to=2023-02-19",
// referrerPolicy: "strict-origin-when-cross-origin",
// body: null,
// method: "GET",
// mode: "cors",
// credentials: "omit",
// });
const packages = [
"effector",
"effector-react",
"effector-solid",
"effector-vue",
"patronum",
"@effector/reflect",
];
const minWidth = packages.reduce((a, b) => Math.max(a, b.length), 0);
const results = await Promise.all(
packages.map(
async (packageName) =>
`${packageName.padEnd(minWidth + 4, " ")}${await (
await getGzipSize(packageName)
).toFixed(1)} kB gzipped`,
),
);
console.log(results.join("\n"));
const result = await exec("npm info effector --json");
const npm = JSON.parse(result.stdout);
const latestVersion = npm["dist-tags"].latest;
const latestVersionReleaseDate = npm.time[latestVersion];
const totalNpmReleases = npm.versions.length;
console.log(" ");
console.log(
"Latest version".padEnd(minWidth + 3, " "),
latestVersion,
"at",
new Date(latestVersionReleaseDate).toLocaleDateString("ru-RU"),
);
console.log("Total NPM Releases".padEnd(minWidth + 3, " "), totalNpmReleases);