Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/composables/useNpmRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,8 @@ export function getVersionClass(info: OutdatedDependencyInfo | undefined): strin
// Yellow for patch versions behind
return 'text-yellow-500 cursor-help'
}

export function getDependencyCount(version: PackumentVersion | null): number {
if (!version?.dependencies) return 0
return Object.keys(version.dependencies).length
}
18 changes: 15 additions & 3 deletions app/composables/usePackageComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import type {
import { encodePackageName } from '#shared/utils/npm'
import type { PackageAnalysisResponse } from './usePackageAnalysis'
import { isBinaryOnlyPackage } from '#shared/utils/binary-detection'
import { getDependencyCount } from './useNpmRegistry'

export interface PackageComparisonData {
package: ComparisonPackage
downloads?: number
/** Package's own unpacked size (from dist.unpackedSize) */
packageSize?: number
/** Direct dependencies count */
directDeps: number
/** Install size data (fetched lazily) */
installSize?: {
selfSize: number
totalSize: number
/** Total dependency count */
dependencyCount: number
}
analysis?: PackageAnalysisResponse
Expand Down Expand Up @@ -109,6 +113,8 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
),
])

const pkg = usePackage(name, latestVersion)

const versionData = pkgData.versions[latestVersion]
const packageSize = versionData?.dist?.unpackedSize

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

case 'dependencies':
if (!data.installSize) return null
const depCount = data.installSize.dependencyCount
const depCount = data.directDeps
return {
raw: depCount,
display: String(depCount),
Expand All @@ -380,7 +386,13 @@ function computeFacetValue(

// Coming soon facets
case 'totalDependencies':
return null
if (!data.installSize) return null
const totalDepCount = data.installSize.dependencyCount
return {
raw: totalDepCount,
display: String(totalDepCount),
status: totalDepCount > 50 ? 'warning' : 'neutral',
}

default:
return null
Expand Down
5 changes: 0 additions & 5 deletions app/pages/package/[...package].vue
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ function normalizeGitUrl(url: string): string {
.replace(/^git@github\.com:/, 'https://github.com/')
}

function getDependencyCount(version: PackumentVersion | null): number {
if (!version?.dependencies) return 0
return Object.keys(version.dependencies).length
}

// Check if a version has provenance/attestations
// The dist object may have attestations that aren't in the base type
function hasProvenance(version: PackumentVersion | null): boolean {
Expand Down
1 change: 0 additions & 1 deletion shared/types/comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const FACET_INFO: Record<ComparisonFacet, Omit<FacetInfo, 'id'>> = {
},
totalDependencies: {
category: 'performance',
comingSoon: true,
},
// Health
downloads: {
Expand Down
Loading