@@ -8,11 +8,13 @@ import type {
88 NpmPerson ,
99 PackageVersionInfo ,
1010} from '#shared/types'
11+ import type { PackageVersionsInfoWithMetadata } from 'fast-npm-meta'
1112import type { ReleaseType } from 'semver'
1213import { maxSatisfying , prerelease , major , minor , diff , gt , compare } from 'semver'
1314import { isExactVersion } from '~/utils/versions'
1415import { extractInstallScriptsInfo } from '~/utils/install-scripts'
1516import type { CachedFetchFunction } from '#shared/utils/fetch-cache-config'
17+ import { FAST_NPM_META_API , encodePackageName } from '#shared/utils/npm'
1618
1719const NPM_REGISTRY = 'https://registry.npmjs.org'
1820const NPM_API = 'https://api.npmjs.org'
@@ -594,32 +596,31 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
594596const allVersionsCache = new Map < string , Promise < PackageVersionInfo [ ] > > ( )
595597
596598/**
597- * Fetch all versions of a package from the npm registry .
599+ * Fetch all versions of a package using fast- npm-meta API .
598600 * Returns version info sorted by version (newest first).
599601 * Results are cached to avoid duplicate requests.
600602 *
601603 * Note: This is a standalone async function for use in event handlers.
602604 * For composable usage, use useAllPackageVersions instead.
605+ *
606+ * @see https://github.com/antfu/fast-npm-meta
603607 */
604608export async function fetchAllPackageVersions ( packageName : string ) : Promise < PackageVersionInfo [ ] > {
605609 const cached = allVersionsCache . get ( packageName )
606610 if ( cached ) return cached
607611
608612 const promise = ( async ( ) => {
609613 const encodedName = encodePackageName ( packageName )
610- // Use regular $fetch for client-side calls (this is called on user interaction)
611- const data = await $fetch < {
612- versions : Record < string , { deprecated ?: string } >
613- time : Record < string , string >
614- } > ( `${ NPM_REGISTRY } /${ encodedName } ` )
615-
616- return Object . entries ( data . versions )
617- . filter ( ( [ v ] ) => data . time [ v ] )
618- . map ( ( [ version , versionData ] ) => ( {
614+ const data = await $fetch < PackageVersionsInfoWithMetadata > (
615+ `${ FAST_NPM_META_API } /versions/${ encodedName } ?metadata=true` ,
616+ )
617+
618+ return Object . entries ( data . versionsMeta )
619+ . map ( ( [ version , meta ] ) => ( {
619620 version,
620- time : data . time [ version ] ,
621- hasProvenance : false , // Would need to check dist.attestations for each version
622- deprecated : versionData . deprecated ,
621+ time : meta . time ,
622+ hasProvenance : meta . provenance === 'trustedPublisher' || meta . provenance === true ,
623+ deprecated : meta . deprecated ,
623624 } ) )
624625 . sort ( ( a , b ) => compare ( b . version , a . version ) )
625626 } ) ( )
0 commit comments