Skip to content

Commit

Permalink
get downloads stats in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jun 14, 2022
1 parent 18fdb83 commit 0233e1f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scripts/downloads-by-versions.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import coerce from 'semver/functions/coerce.js';
const { cyan, green } = chalk;
const ALL = !argv['main-only'];
const downloadsByPatch = {};
const downloadsByMinor = {};
const downloadsByMajor = {};
let total = 0;

async function getStat(pkg) {
const res = await fetch(`https://www.npmjs.com/package/${ pkg }`);
Expand All @@ -7,15 +13,11 @@ async function getStat(pkg) {
return JSON.parse(json).context.versionsDownloads;
}

const { cyan, green } = chalk;
const ALL = !argv['main-only'];
const core = await getStat('core-js');
const pure = ALL && await getStat('core-js-pure');
const bundle = ALL && await getStat('core-js-bundle');
const downloadsByPatch = {};
const downloadsByMinor = {};
const downloadsByMajor = {};
let total = 0;
const [core, pure, bundle] = await Promise.all([
getStat('core-js'),
ALL && getStat('core-js-pure'),
ALL && getStat('core-js-bundle'),
]);

for (let [patch, downloads] of Object.entries(core)) {
const semver = coerce(patch);
Expand Down

0 comments on commit 0233e1f

Please sign in to comment.