* @param query * @example loadHighestNPMVersionMatching("react@^18.3.0 || ^19.0.0") === Promise<"19.0.0">
(query: string)
| 42 | * @example loadHighestNPMVersionMatching("react@^18.3.0 || ^19.0.0") === Promise<"19.0.0"> |
| 43 | */ |
| 44 | async 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 | |
| 65 | function endMessage(targetNextVersion: string) { |
| 66 | console.log() |
no test coverage detected