@@ -5,6 +5,7 @@ import type {
55 Packument ,
66 VulnerabilityTreeResult ,
77} from '#shared/types'
8+ import type { PackageLikes } from '#shared/types/social'
89import { encodePackageName } from '#shared/utils/npm'
910import type { PackageAnalysisResponse } from './usePackageAnalysis'
1011import { isBinaryOnlyPackage } from '#shared/utils/binary-detection'
@@ -28,6 +29,8 @@ export const NoDependencyDisplay = {
2829export interface PackageComparisonData {
2930 package : ComparisonPackage
3031 downloads ?: number
32+ /** Total likes from atproto */
33+ totalLikes ?: number
3134 /** Package's own unpacked size (from dist.unpackedSize) */
3235 packageSize ?: number
3336 /** Number of direct dependencies */
@@ -127,7 +130,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
127130 if ( ! latestVersion ) return null
128131
129132 // Fetch fast additional data in parallel (optional - failures are ok)
130- const [ downloads , analysis , vulns ] = await Promise . all ( [
133+ const [ downloads , analysis , vulns , likes ] = await Promise . all ( [
131134 $fetch < { downloads : number } > (
132135 `https://api.npmjs.org/downloads/point/last-week/${ encodePackageName ( name ) } ` ,
133136 ) . catch ( ( ) => null ) ,
@@ -137,8 +140,8 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
137140 $fetch < VulnerabilityTreeResult > (
138141 `/api/registry/vulnerabilities/${ encodePackageName ( name ) } ` ,
139142 ) . catch ( ( ) => null ) ,
143+ $fetch < PackageLikes > ( `/api/social/likes/${ name } ` ) . catch ( ( ) => null ) ,
140144 ] )
141-
142145 const versionData = pkgData . versions [ latestVersion ]
143146 const packageSize = versionData ?. dist ?. unpackedSize
144147
@@ -188,6 +191,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
188191 deprecated : versionData ?. deprecated ,
189192 } ,
190193 isBinaryOnly : isBinary ,
194+ totalLikes : likes ?. totalLikes ,
191195 }
192196 } catch {
193197 return null
@@ -299,6 +303,7 @@ function createNoDependencyData(): PackageComparisonData {
299303 } ,
300304 isNoDependency : true ,
301305 downloads : undefined ,
306+ totalLikes : undefined ,
302307 packageSize : 0 ,
303308 directDeps : 0 ,
304309 installSize : {
@@ -353,6 +358,14 @@ function computeFacetValue(
353358 status : 'neutral' ,
354359 }
355360 }
361+ case 'totalLikes' : {
362+ if ( data . totalLikes === undefined ) return null
363+ return {
364+ raw : data . totalLikes ,
365+ display : formatCompactNumber ( data . totalLikes ) ,
366+ status : 'neutral' ,
367+ }
368+ }
356369 case 'packageSize' : {
357370 // A size of zero is valid
358371 if ( data . packageSize == null ) return null
0 commit comments