88 getPrereleaseChannel ,
99 parseVersion ,
1010} from ' ~/utils/versions'
11+ import { fetchAllPackageVersions } from ' ~/composables/useNpmRegistry'
1112
1213const props = defineProps <{
1314 packageName: string
@@ -107,18 +108,12 @@ const otherMajorGroups = ref<
107108> ([])
108109const otherVersionsLoading = ref (false )
109110
110- // Cached full version list
111+ // Cached full version list (local to component instance)
111112const allVersionsCache = ref <PackageVersionInfo [] | null >(null )
112113const loadingVersions = ref (false )
113114const hasLoadedAll = ref (false )
114115
115- // npm registry packument type (simplified)
116- interface NpmPackument {
117- versions: Record <string , unknown >
118- time: Record <string , string >
119- }
120-
121- // Load all versions directly from npm registry
116+ // Load all versions using shared function
122117async function loadAllVersions(): Promise <PackageVersionInfo []> {
123118 if (allVersionsCache .value ) return allVersionsCache .value
124119
@@ -136,23 +131,7 @@ async function loadAllVersions(): Promise<PackageVersionInfo[]> {
136131
137132 loadingVersions .value = true
138133 try {
139- // Fetch directly from npm registry
140- const encodedName = props .packageName .startsWith (' @' )
141- ? ` @${encodeURIComponent (props .packageName .slice (1 ))} `
142- : encodeURIComponent (props .packageName )
143-
144- const data = await $fetch <NpmPackument >(` https://registry.npmjs.org/${encodedName } ` )
145-
146- // Convert to our format
147- const versions: PackageVersionInfo [] = Object .keys (data .versions )
148- .filter (v => data .time [v ])
149- .map (version => ({
150- version ,
151- time: data .time [version ],
152- hasProvenance: false ,
153- }))
154- .sort ((a , b ) => compareVersions (b .version , a .version ))
155-
134+ const versions = await fetchAllPackageVersions (props .packageName )
156135 allVersionsCache .value = versions
157136 hasLoadedAll .value = true
158137 return versions
@@ -290,14 +269,6 @@ function toggleMajorGroup(index: number) {
290269function getTagVersions(tag : string ): VersionDisplay [] {
291270 return tagVersions .value .get (tag ) ?? []
292271}
293-
294- function formatDate(dateStr : string ): string {
295- return new Date (dateStr ).toLocaleDateString (' en-US' , {
296- year: ' numeric' ,
297- month: ' short' ,
298- day: ' numeric' ,
299- })
300- }
301272 </script >
302273
303274<template >
@@ -341,13 +312,14 @@ function formatDate(dateStr: string): string {
341312 {{ row.primaryVersion.version }}
342313 </NuxtLink >
343314 <div class =" flex items-center gap-2 shrink-0" >
344- <time
315+ <NuxtTime
345316 v-if =" row.primaryVersion.time"
346317 :datetime =" row.primaryVersion.time"
318+ year =" numeric"
319+ month =" short"
320+ day =" numeric"
347321 class =" text-xs text-fg-subtle"
348- >
349- {{ formatDate(row.primaryVersion.time) }}
350- </time >
322+ />
351323 <ProvenanceBadge
352324 v-if =" row.primaryVersion.hasProvenance"
353325 :package-name =" packageName"
@@ -384,9 +356,14 @@ function formatDate(dateStr: string): string {
384356 {{ v.version }}
385357 </NuxtLink >
386358 <div class =" flex items-center gap-2 shrink-0" >
387- <time v-if =" v.time" :datetime =" v.time" class =" text-[10px] text-fg-subtle" >
388- {{ formatDate(v.time) }}
389- </time >
359+ <NuxtTime
360+ v-if =" v.time"
361+ :datetime =" v.time"
362+ class =" text-[10px] text-fg-subtle"
363+ year =" numeric"
364+ month =" short"
365+ day =" numeric"
366+ />
390367 <ProvenanceBadge
391368 v-if =" v.hasProvenance"
392369 :package-name =" packageName"
@@ -451,13 +428,14 @@ function formatDate(dateStr: string): string {
451428 {{ row.primaryVersion.version }}
452429 </NuxtLink >
453430 <div class =" flex items-center gap-2 shrink-0" >
454- <time
431+ <NuxtTime
455432 v-if =" row.primaryVersion.time"
456433 :datetime =" row.primaryVersion.time"
457434 class =" text-[10px] text-fg-subtle"
458- >
459- {{ formatDate(row.primaryVersion.time) }}
460- </time >
435+ year =" numeric"
436+ month =" short"
437+ day =" numeric"
438+ />
461439 </div >
462440 </div >
463441 <div v-if =" row.tags.length" class =" flex items-center gap-1 mt-0.5 flex-wrap" >
@@ -543,9 +521,14 @@ function formatDate(dateStr: string): string {
543521 {{ v.version }}
544522 </NuxtLink >
545523 <div class =" flex items-center gap-2 shrink-0" >
546- <time v-if =" v.time" :datetime =" v.time" class =" text-[10px] text-fg-subtle" >
547- {{ formatDate(v.time) }}
548- </time >
524+ <NuxtTime
525+ v-if =" v.time"
526+ :datetime =" v.time"
527+ class =" text-[10px] text-fg-subtle"
528+ year =" numeric"
529+ month =" short"
530+ day =" numeric"
531+ />
549532 <ProvenanceBadge
550533 v-if =" v.hasProvenance"
551534 :package-name =" packageName"
0 commit comments