-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add npm tag lookup to determineChannel correctly #563
Changes from 2 commits
b277ae3
a29de42
725808b
98f2c10
8401d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
/package-lock.json | ||
/tmp | ||
/oclif-plugin-update-*.tgz | ||
/.vscode | ||
/.vscode | ||
/.idea |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ export class Updater { | |
return | ||
} | ||
|
||
const channel = options.channel || await this.determineChannel() | ||
const channel = options.channel || await this.determineChannel(version) | ||
const current = await this.determineCurrentVersion() | ||
|
||
if (version) { | ||
|
@@ -268,14 +268,18 @@ export class Updater { | |
return current === updated | ||
} | ||
|
||
private async determineChannel(): Promise<string> { | ||
const channelPath = path.join(this.config.dataDir, 'channel') | ||
if (fs.existsSync(channelPath)) { | ||
const channel = await fs.readFile(channelPath, 'utf8') | ||
return String(channel).trim() | ||
private async determineChannel(version:string|undefined): Promise<string> { | ||
try { | ||
const {body} = await HTTP.get(`https://registry.npmjs.org/${this.config.pjson.name}/`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. proxy should be ok. That library looks to have implemented it |
||
const tags = (body as {'dist-tags': Record<string, string>})['dist-tags'] | ||
const tag = Object.keys(tags).find(v => tags[v] === version) ?? 'stable' | ||
// 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
} | ||
|
||
return this.config.channel || 'stable' | ||
} | ||
|
||
private determinePlatform(): Interfaces.PlatformTypes { | ||
|
@@ -303,7 +307,7 @@ export class Updater { | |
|
||
private async setChannel(channel: string): Promise<void> { | ||
const channelPath = path.join(this.config.dataDir, 'channel') | ||
fs.writeFile(channelPath, channel, 'utf8') | ||
await fs.writeFile(channelPath, channel, 'utf8') | ||
} | ||
|
||
private async logChop(): Promise<void> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.