Skip to content

Commit 7b9734a

Browse files
committed
feat: more ai slop
1 parent 192db28 commit 7b9734a

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

server/api/registry/badge/[type]/[...pkg].get.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PackageRouteParamsSchema } from '#shared/schemas/package'
66
import { CACHE_MAX_AGE_ONE_HOUR, ERROR_NPM_FETCH_FAILED } from '#shared/utils/constants'
77
import { fetchNpmPackage } from '#server/utils/npm'
88
import { assertValidPackageName } from '#shared/utils/npm'
9+
import { detectTypesStatus } from '#server/utils/package-analysis'
910
import { handleApiError } from '#server/utils/error-handler'
1011

1112
const NPM_DOWNLOADS_API = 'https://api.npmjs.org/downloads/point'
@@ -372,12 +373,39 @@ const badgeStrategies = {
372373
return { label: 'node', value: nodeVersion, color: COLORS.yellow }
373374
},
374375

375-
'types': async (pkgData: globalThis.Packument) => {
376-
const latest = getLatestVersion(pkgData)
377-
const versionData = latest ? pkgData.versions?.[latest] : undefined
378-
const hasTypes = !!(versionData?.types || versionData?.typings)
379-
const value = hasTypes ? 'included' : 'missing'
380-
const color = hasTypes ? COLORS.blue : COLORS.slate
376+
'types': async (pkgData: globalThis.Packument, requestedVersion?: string) => {
377+
const { pkg, typesPackage, files } = await fetchPackageWithTypesAndFiles(
378+
pkgData.name,
379+
requestedVersion,
380+
)
381+
382+
const typesStatus = detectTypesStatus(pkg, typesPackage, files)
383+
384+
let value: string
385+
let color: string
386+
387+
switch (typesStatus.kind) {
388+
case 'included':
389+
value = 'included'
390+
color = COLORS.blue
391+
break
392+
393+
case '@types':
394+
value = '@types'
395+
color = COLORS.purple
396+
if (typesStatus.deprecated) {
397+
value += ' (deprecated)'
398+
color = COLORS.red
399+
}
400+
break
401+
402+
case 'none':
403+
default:
404+
value = 'missing'
405+
color = COLORS.slate
406+
break
407+
}
408+
381409
return { label: 'types', value, color }
382410
},
383411

0 commit comments

Comments
 (0)