Skip to content

Commit a30be06

Browse files
committed
fix: show correct dependencies count
1 parent dfceb2d commit a30be06

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

app/composables/useNpmRegistry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,8 @@ export function getVersionClass(info: OutdatedDependencyInfo | undefined): strin
858858
// Yellow for patch versions behind
859859
return 'text-yellow-500 cursor-help'
860860
}
861+
862+
export function getDependencyCount(version: PackumentVersion | null): number {
863+
if (!version?.dependencies) return 0
864+
return Object.keys(version.dependencies).length
865+
}

app/composables/usePackageComparison.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ import type {
88
import { encodePackageName } from '#shared/utils/npm'
99
import type { PackageAnalysisResponse } from './usePackageAnalysis'
1010
import { isBinaryOnlyPackage } from '#shared/utils/binary-detection'
11+
import { getDependencyCount } from './useNpmRegistry'
1112

1213
export interface PackageComparisonData {
1314
package: ComparisonPackage
1415
downloads?: number
1516
/** Package's own unpacked size (from dist.unpackedSize) */
1617
packageSize?: number
18+
/** Direct dependencies count */
19+
directDeps: number
1720
/** Install size data (fetched lazily) */
1821
installSize?: {
1922
selfSize: number
2023
totalSize: number
24+
/** Total dependency count */
2125
dependencyCount: number
2226
}
2327
analysis?: PackageAnalysisResponse
@@ -109,6 +113,8 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
109113
),
110114
])
111115

116+
const pkg = usePackage(name, latestVersion)
117+
112118
const versionData = pkgData.versions[latestVersion]
113119
const packageSize = versionData?.dist?.unpackedSize
114120

@@ -139,6 +145,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
139145
},
140146
downloads: downloads?.downloads,
141147
packageSize,
148+
directDeps: getDependencyCount(pkg.data.value?.requestedVersion ?? null),
142149
installSize: undefined, // Will be filled in second pass
143150
analysis: analysis ?? undefined,
144151
vulnerabilities: {
@@ -360,8 +367,7 @@ function computeFacetValue(
360367
}
361368

362369
case 'dependencies':
363-
if (!data.installSize) return null
364-
const depCount = data.installSize.dependencyCount
370+
const depCount = data.directDeps
365371
return {
366372
raw: depCount,
367373
display: String(depCount),
@@ -380,7 +386,13 @@ function computeFacetValue(
380386

381387
// Coming soon facets
382388
case 'totalDependencies':
383-
return null
389+
if (!data.installSize) return null
390+
const totalDepCount = data.installSize.dependencyCount
391+
return {
392+
raw: totalDepCount,
393+
display: String(totalDepCount),
394+
status: totalDepCount > 50 ? 'warning' : 'neutral',
395+
}
384396

385397
default:
386398
return null

app/pages/package/[...package].vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,6 @@ function normalizeGitUrl(url: string): string {
293293
.replace(/^git@github\.com:/, 'https://github.com/')
294294
}
295295
296-
function getDependencyCount(version: PackumentVersion | null): number {
297-
if (!version?.dependencies) return 0
298-
return Object.keys(version.dependencies).length
299-
}
300-
301296
// Check if a version has provenance/attestations
302297
// The dist object may have attestations that aren't in the base type
303298
function hasProvenance(version: PackumentVersion | null): boolean {

0 commit comments

Comments
 (0)