MCPcopy Create free account
hub / github.com/TanStack/cli / resolveNpmVersion

Function resolveNpmVersion

packages/create/src/npm-resolver.ts:11–28  ·  view source on GitHub ↗
(pkg: string)

Source from the content-addressed store, hash-verified

9const cache = new Map<string, string>()
10
11export async function resolveNpmVersion(pkg: string): Promise<string | null> {
12 if (cache.has(pkg)) {
13 return cache.get(pkg)!
14 }
15
16 try {
17 const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
18 headers: { Accept: 'application/vnd.npm.install-v1+json' },
19 })
20 if (!res.ok) return null
21 const data = (await res.json()) as { version?: string }
22 const version = data.version ?? null
23 if (version) cache.set(pkg, version)
24 return version
25 } catch {
26 return null
27 }
28}
29
30/**
31 * Walk a deps object and resolve any "latest" values to pinned versions.

Callers 1

resolveLatestVersionsFunction · 0.85

Calls 3

jsonMethod · 0.80
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected