Skip to content

Commit 5ef661a

Browse files
committed
perf: use fast-npm-meta to get all versions
1 parent a209e53 commit 5ef661a

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

app/composables/useNpmRegistry.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import type {
88
NpmPerson,
99
PackageVersionInfo,
1010
} from '#shared/types'
11+
import type { PackageVersionsInfoWithMetadata } from 'fast-npm-meta'
1112
import type { ReleaseType } from 'semver'
1213
import { maxSatisfying, prerelease, major, minor, diff, gt, compare } from 'semver'
1314
import { isExactVersion } from '~/utils/versions'
1415
import { extractInstallScriptsInfo } from '~/utils/install-scripts'
1516
import type { CachedFetchFunction } from '#shared/utils/fetch-cache-config'
17+
import { FAST_NPM_META_API, encodePackageName } from '#shared/utils/npm'
1618

1719
const NPM_REGISTRY = 'https://registry.npmjs.org'
1820
const NPM_API = 'https://api.npmjs.org'
@@ -594,32 +596,31 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
594596
const 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
*/
604608
export 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
})()

shared/types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export * from './deno-doc'
88
export * from './i18n-status'
99
export * from './comparison'
1010
export * from './skills'
11-
export * from './fast-npm-meta'

0 commit comments

Comments
 (0)