-
-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathuseResolvedVersion.ts
More file actions
20 lines (19 loc) · 674 Bytes
/
useResolvedVersion.ts
File metadata and controls
20 lines (19 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { ResolvedPackageVersion } from 'fast-npm-meta'
export function useResolvedVersion(
packageName: MaybeRefOrGetter<string>,
requestedVersion: MaybeRefOrGetter<string | null>,
) {
return useAsyncData(
() => `resolved-version:${toValue(packageName)}:${toValue(requestedVersion) ?? 'latest'}`,
async () => {
const version = toValue(requestedVersion)
const name = toValue(packageName)
const url = version
? `https://npm.antfu.dev/${name}@${version}`
: `https://npm.antfu.dev/${name}`
const data = await $fetch<ResolvedPackageVersion>(url)
return data.version
},
{ default: () => undefined },
)
}