Skip to content

Commit

Permalink
fix: stable resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sumwatshade committed Jun 3, 2021
1 parent 6784f81 commit 92c3493
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/commands/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class UseCommand extends UpdateCommand {
const {args} = this.parse(UseCommand)

// Check if this command is trying to update the channel. TODO: make this dynamic
const channelUpdateRequested = ['alpha', 'beta', 'next', 'stable'].some(
const prereleaseChannels = ['alpha', 'beta', 'next']
const channelUpdateRequested = ['stable', ...prereleaseChannels].some(
c => args.version === c,
)
this.channel = channelUpdateRequested ?
Expand All @@ -39,7 +40,8 @@ export default class UseCommand extends UpdateCommand {
if (versions.length === 0)
throw new Error('No locally installed versions found.')
const matchingLocalVersions = versions
.filter(version => version.includes(targetVersion))
// If we request stable, only provide standard versions
.filter(version => (this.channel === 'stable' && !prereleaseChannels.some(c => version.includes(c))) || (version.includes(targetVersion) && !version.includes('.partial')))
.sort((a, b) => semver.compare(b, a))

if (args.version && (versions.includes(targetVersion) || matchingLocalVersions.length > 0)) {
Expand Down
21 changes: 21 additions & 0 deletions test/commands/use.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ describe('Use Command', () => {
expect(commandInstance.channel).toBe('next')
})

it('when provided stable channel, uses only release versions', async () => {
mockFs.readdirSync.mockReturnValue([
'1.0.0-next.2',
'1.0.3',
'1.0.0-next.3',
'1.0.1',
'1.0.0-alpha.0',
] as any)

// oclif-example use next
commandInstance = new MockedUseCommand(['stable'], config)

commandInstance.fetchManifest.mockResolvedValue({})

await commandInstance.run()

expect(commandInstance.downloadAndExtract).not.toBeCalled()
expect(commandInstance.updatedVersion).toBe('1.0.3')
expect(commandInstance.channel).toBe('stable')
})

it('when provided a version, will directly switch to it locally', async () => {
mockFs.readdirSync.mockReturnValue([
'1.0.0-next.2',
Expand Down

0 comments on commit 92c3493

Please sign in to comment.