From 98f2c1037fc9ef635a38b830618647aa8fc3f0ce Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 5 Jun 2023 08:16:19 -0600 Subject: [PATCH] chore: use channel file for default, then back to 'stable' --- src/update.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/update.ts b/src/update.ts index 28d93fe5..e8e830e4 100644 --- a/src/update.ts +++ b/src/update.ts @@ -268,17 +268,21 @@ export class Updater { return current === updated } - private async determineChannel(version:string|undefined): Promise { + private async determineChannel(version?:string): Promise { + const channelPath = path.join(this.config.dataDir, 'channel') + + const channel = fs.existsSync(channelPath) ? (await fs.readFile(channelPath, 'utf8')).trim() : 'stable' + try { - const {body} = await HTTP.get(`https://registry.npmjs.org/${this.config.pjson.name}/`) - const tags = (body as {'dist-tags': Record})['dist-tags'] - const tag = Object.keys(tags).find(v => tags[v] === version) ?? 'stable' + const {body} = await HTTP.get<{'dist-tags':Record}>(`https://registry.npmjs.org/${this.config.pjson.name}/`) + const tags = body['dist-tags'] + const tag = Object.keys(tags).find(v => tags[v] === version) ?? channel // convert from npm style tag defaults to OCLIF style if (tag === 'latest') return 'stable' if (tag === 'latest-rc') return 'stable-rc' return tag } catch { - return 'stable' + return channel } }