Skip to content

Commit

Permalink
Default downloads count to 0 to fix very new packages (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion authored Jan 3, 2024
1 parent 1731c3e commit 57b4df6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/packageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ export async function getPackageInfo(name: string): Promise<PackageInfo> {
if (!packageRes.ok) {
throw new Error('Could not get package info from NPM.');
}
const packageInfo: NpmRegistryInfo = await packageRes.json();

if (!downloadsRes.ok) {
throw new Error('Could not get downloads info from NPM.');
// Default the downloads to 0, because the API call returns an error for very new packages which do exist.
let downloadsInfo: NpmDownloadsInfo = { downloads: 0 };
if (downloadsRes.ok) {
downloadsInfo = await downloadsRes.json();
}

const packageInfo = await packageRes.json();
const downloadsInfo = await downloadsRes.json();
return npmRegistryInfoToPackageInfo(packageInfo, downloadsInfo);
}

Expand Down

0 comments on commit 57b4df6

Please sign in to comment.