MCPcopy
hub / github.com/vercel/next.js / loadHighestNPMVersionMatching

Function loadHighestNPMVersionMatching

packages/next-codemod/bin/upgrade.ts:44–63  ·  view source on GitHub ↗

* @param query * @example loadHighestNPMVersionMatching("react@^18.3.0 || ^19.0.0") === Promise<"19.0.0">

(query: string)

Source from the content-addressed store, hash-verified

42 * @example loadHighestNPMVersionMatching("react@^18.3.0 || ^19.0.0") === Promise<"19.0.0">
43 */
44async function loadHighestNPMVersionMatching(query: string) {
45 const versionsJSON = execSync(
46 `npm --silent view "${query}" --json --field version`,
47 { encoding: 'utf-8' }
48 )
49 const versionOrVersions = JSON.parse(versionsJSON)
50 if (versionOrVersions.length < 1) {
51 throw new Error(
52 `Found no React versions matching "${query}". This is a bug in the upgrade tool.`
53 )
54 }
55 // npm-view returns an array if there are multiple versions matching the query.
56 if (Array.isArray(versionOrVersions)) {
57 // The last entry will be the latest version published.
58 // But we want the highest version.
59 versionOrVersions.sort(compareVersions)
60 return versionOrVersions[versionOrVersions.length - 1]
61 }
62 return versionOrVersions
63}
64
65function endMessage(targetNextVersion: string) {
66 console.log()

Callers 1

runUpgradeFunction · 0.85

Calls 3

isArrayMethod · 0.80
parseMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected