-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathuseLicenseChanges.ts
More file actions
29 lines (24 loc) · 900 Bytes
/
useLicenseChanges.ts
File metadata and controls
29 lines (24 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { MaybeRefOrGetter } from 'vue'
import { toValue } from 'vue'
interface LicenseChangeResponse {
change: { from: string; to: string } | null
}
/**
* Composable to detect license changes across all versions of a package
*/
export function useLicenseChanges(
packageName: MaybeRefOrGetter<string | null | undefined>,
resolvedVersion: MaybeRefOrGetter<string | null | undefined> = () => undefined,
) {
const name = computed(() => toValue(packageName))
if (!name) return { data: null } // Don't fetch if no name
const version = computed(() => toValue(resolvedVersion) ?? 'latest')
const url = computed(() => {
return name.value ? `/api/registry/license-change/${encodeURIComponent(name.value)}` : ''
})
const result = useFetch<LicenseChangeResponse>(url, {
query: computed(() => ({ version: version.value })),
watch: [url, version],
})
return result
}