Skip to content

Commit

Permalink
fix: prevent crash when package stats haven't been loaded & are undef…
Browse files Browse the repository at this point in the history
…ined
  • Loading branch information
ThisIsMissEm authored and Julien-R44 committed May 18, 2024
1 parent 8b9608d commit c85ebc6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/services/packages_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ export class PackagesFetcher {
* Merge raw package .yml data with the stats fetched from npm/github stored
* on our database
*/
#mergePackageStatsAndInfo(pkg: PackageInfo, stats: PackageStats) {
#mergePackageStatsAndInfo(pkg: PackageInfo, stats: PackageStats | undefined) {
return {
...pkg,
firstReleaseAt: stats.firstReleaseAt?.toISODate() || undefined,
lastReleaseAt: stats.lastReleaseAt?.toISODate() || undefined,
stars: stats.githubStars,
downloads: stats.weeklyDownloads,
firstReleaseAt: stats?.firstReleaseAt?.toISODate() || undefined,
lastReleaseAt: stats?.lastReleaseAt?.toISODate() || undefined,
stars: stats?.githubStars,
downloads: stats?.weeklyDownloads,
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ export class PackagesFetcher {
const stats = await PackageStats.all()
let packages = [...this.packagesList].map((pkg) => {
const info = stats.find((info) => info.packageName === pkg.name)
return this.#mergePackageStatsAndInfo(pkg, info!)
return this.#mergePackageStatsAndInfo(pkg, info)
})

/**
Expand Down

0 comments on commit c85ebc6

Please sign in to comment.