diff --git a/src/constants.ts b/src/constants.ts index ef3694f..7c78550 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,7 +2,7 @@ import type { CheckOptions, CommonOptions, UsageOptions } from './types' export const LOG_LEVELS = ['debug', 'info', 'warn', 'error', 'silent'] as const -export const MODE_CHOICES = ['default', 'major', 'minor', 'patch', 'latest', 'newest'] as const +export const MODE_CHOICES = ['default', 'major', 'minor', 'patch', 'latest', 'newest', 'next'] as const export const DEFAULT_COMMON_OPTIONS: CommonOptions = { cwd: '', diff --git a/src/types.ts b/src/types.ts index 1ccad85..e31e085 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ +import type { MODE_CHOICES } from './constants' import type { SortOption } from './utils/sort' -export type RangeMode = 'default' | 'major' | 'minor' | 'patch' | 'latest' | 'newest' +export type RangeMode = typeof MODE_CHOICES[number] export type PackageMode = Omit | 'ignore' export type DepType = 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies' | 'packageManager' | 'pnpm.overrides' | 'resolutions' | 'overrides' diff --git a/src/utils/versions.ts b/src/utils/versions.ts index c36a00f..58011db 100644 --- a/src/utils/versions.ts +++ b/src/utils/versions.ts @@ -27,7 +27,7 @@ export function getVersionRangePrefix(v: string) { return null } -export function changeVersionRange(version: string, mode: Exclude) { +export function changeVersionRange(version: string, mode: Exclude) { if (!semver.validRange(version)) return null @@ -72,6 +72,9 @@ export function getMaxSatisfying(versions: string[], current: string, mode: Rang else if (mode === 'newest') { version = versions[versions.length - 1] } + else if (mode === 'next') { + version = tags.next + } else if (mode === 'default' && (current === '*' || current.trim() === '')) { return } diff --git a/test/versions.test.ts b/test/versions.test.ts index 121ba71..c9e9576 100644 --- a/test/versions.test.ts +++ b/test/versions.test.ts @@ -100,4 +100,18 @@ it('getMaxSatisfying', async () => { latest: '1.0.0-next.4', next: '1.0.0-next.2', })) + + // should return the next tag version on next mode + // a good test case for this is eslint-plugin-react-hooks + expect('5.1.0-beta-4508873393-20240430').toBe(getMaxSatisfying([ + '4.6.1', + '4.6.2', + '5.1.0-beta-4508873393-20240430', + '0.0.0-experimental-4508873393-20240430', + ], '^1.0.0-next.1', 'next', { + latest: '4.6.2', + next: '5.1.0-beta-4508873393-20240430', + rc: '4.2.1-rc.3', + experimental: '0.0.0-experimental-4508873393-20240430', + })) }, 10_000)