Skip to content

Commit

Permalink
chore: use channel file for default, then back to 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jun 5, 2023
1 parent 725808b commit 98f2c10
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,21 @@ export class Updater {
return current === updated
}

private async determineChannel(version:string|undefined): Promise<string> {
private async determineChannel(version?:string): Promise<string> {
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<string, string>})['dist-tags']
const tag = Object.keys(tags).find(v => tags[v] === version) ?? 'stable'
const {body} = await HTTP.get<{'dist-tags':Record<string, string>}>(`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
}
}

Expand Down

0 comments on commit 98f2c10

Please sign in to comment.