* From a nightly and stable update, determines which is the "best" one to offer. * The rule is to always prefer nightly if the base versions are the same.
( nightly?: UpdateInfo, stable?: UpdateInfo, )
| 21 | * The rule is to always prefer nightly if the base versions are the same. |
| 22 | */ |
| 23 | function getBestAvailableUpdate( |
| 24 | nightly?: UpdateInfo, |
| 25 | stable?: UpdateInfo, |
| 26 | ): UpdateInfo | null { |
| 27 | if (!nightly) return stable || null; |
| 28 | if (!stable) return nightly || null; |
| 29 | |
| 30 | const nightlyVer = nightly.latest; |
| 31 | const stableVer = stable.latest; |
| 32 | |
| 33 | if ( |
| 34 | semver.coerce(stableVer)?.version === semver.coerce(nightlyVer)?.version |
| 35 | ) { |
| 36 | return nightly; |
| 37 | } |
| 38 | |
| 39 | return semver.gt(stableVer, nightlyVer) ? stable : nightly; |
| 40 | } |
| 41 | |
| 42 | export async function checkForUpdates(): Promise<UpdateObject | null> { |
| 43 | try { |