@@ -6,6 +6,7 @@ import { PackageRouteParamsSchema } from '#shared/schemas/package'
66import { CACHE_MAX_AGE_ONE_HOUR , ERROR_NPM_FETCH_FAILED } from '#shared/utils/constants'
77import { fetchNpmPackage } from '#server/utils/npm'
88import { assertValidPackageName } from '#shared/utils/npm'
9+ import { detectTypesStatus } from '#server/utils/package-analysis'
910import { handleApiError } from '#server/utils/error-handler'
1011
1112const 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