fix: CLI update without arguments shouldn't install previous beta if you are on latest beta

Massimo Melina committed Jun 7, 2024 at 12:18 UTC 64a691b2d73092b0f6c536003b75d469b8e0c91c
2 files changed +4 -4
src/commands.ts
+1 -1
@@ -101,7 +101,7 @@ const commands = {
101 'check-update': {
102 params: '',
103 async cb() {
104 - const update = _.find(await getUpdates(), x => x.isNewer)
104 + const update = (await getUpdates(true))[0]
105 if (!update)
106 throw "you already have the latest version: " + VERSION
107 console.log("new version available", update.name)
src/update.ts
+3 -3
@@ -23,14 +23,14 @@ interface Release {
23 isNewer: boolean // introduced by us
24 }
25
26 -export async function getUpdates() {
26 +export async function getUpdates(strict=false) {
27 const stable: Release = await getRepoInfo(HFS_REPO + '/releases/latest')
28 const verStable = ver(stable)
29 const ret = await getBetas()
30 stable.isNewer = currentVersion.olderThan(stable.tag_name)
31 if (stable.isNewer || RUNNING_BETA)
32 ret.push(stable)
33 - return ret
33 + return ret.filter(x => !strict || x.isNewer)
34
35 function ver(x: any) {
36 return versionToScalar(x.name)
@@ -76,7 +76,7 @@ export async function update(tagOrUrl: string='') {
76 if (!updateSource) {
77 if (/^\d/.test(tagOrUrl)) // work even if the tag is passed without the initial 'v' (useful for console commands)
78 tagOrUrl = 'v' + tagOrUrl
79 - const update = !tagOrUrl ? (await getUpdates())[0]
79 + const update = !tagOrUrl ? (await getUpdates(true))[0]
80 : await getRepoInfo(HFS_REPO + '/releases/tags/' + tagOrUrl).catch(e => {
81 if (e.message === '404') console.error("version not found")
82 else throw e