Skip to content

Commit c330cd0

Browse files
committed
wip
1 parent 73a8d30 commit c330cd0

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

app/composables/usePackageComparison.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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 '~/utils/npm/common'
11+
import { getDependencyCount } from '~/utils/npm/dependency-count'
1212

1313
export interface PackageComparisonData {
1414
package: ComparisonPackage
@@ -114,6 +114,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
114114
])
115115

116116
const pkg = usePackage(name, latestVersion)
117+
const requestedVersion = pkg.data.value?.requestedVersion
117118

118119
const versionData = pkgData.versions[latestVersion]
119120
const packageSize = versionData?.dist?.unpackedSize
@@ -145,7 +146,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
145146
},
146147
downloads: downloads?.downloads,
147148
packageSize,
148-
directDeps: getDependencyCount(pkg.data.value?.requestedVersion ?? null),
149+
directDeps: getDependencyCount(requestedVersion ?? null),
149150
installSize: undefined, // Will be filled in second pass
150151
analysis: analysis ?? undefined,
151152
vulnerabilities: {
@@ -367,11 +368,12 @@ function computeFacetValue(
367368
}
368369

369370
case 'dependencies':
371+
if (!data.directDeps) return null
370372
const depCount = data.directDeps
371373
return {
372374
raw: depCount,
373375
display: String(depCount),
374-
status: depCount > 50 ? 'warning' : 'neutral',
376+
status: depCount > 10 ? 'warning' : 'neutral',
375377
}
376378

377379
case 'deprecated':

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { joinURL } from 'ufo'
1111
import { areUrlsEquivalent } from '#shared/utils/url'
1212
import { isEditableElement } from '~/utils/input'
1313
import { formatBytes } from '~/utils/formatters'
14-
import { getDependencyCount } from '~/utils/npm/common'
14+
import { getDependencyCount } from '~/utils/npm/dependency-count'
1515
import { NuxtLink } from '#components'
1616
1717
definePageMeta({

app/utils/npm/common.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,3 @@ export const NPM_API = 'https://api.npmjs.org'
1212
export function buildScopeTeam(orgName: string, teamName: string): `@${string}:${string}` {
1313
return `@${orgName.replace(/^@/, '')}:${teamName}`
1414
}
15-
16-
export function getDependencyCount(version: PackumentVersion | null): number {
17-
if (!version?.dependencies) return 0
18-
return Object.keys(version.dependencies).length
19-
}

app/utils/npm/dependency-count.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { PackumentVersion } from '#shared/types'
2+
3+
export function getDependencyCount(version: PackumentVersion | null): number {
4+
if (!version?.dependencies) return 0
5+
return Object.keys(version.dependencies).length
6+
}

0 commit comments

Comments
 (0)