diff --git a/src/commands/use.ts b/src/commands/use.ts index 7c6845f8..d034a6db 100644 --- a/src/commands/use.ts +++ b/src/commands/use.ts @@ -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 ? @@ -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)) { diff --git a/test/commands/use.test.ts b/test/commands/use.test.ts index 923a1900..365c27e6 100644 --- a/test/commands/use.test.ts +++ b/test/commands/use.test.ts @@ -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',