Skip to content

Commit

Permalink
feat: new mode next (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored May 1, 2024
1 parent 1851c87 commit 3b42900
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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<RangeMode, 'default'> | 'ignore'
export type DepType = 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies' | 'packageManager' | 'pnpm.overrides' | 'resolutions' | 'overrides'

Expand Down
5 changes: 4 additions & 1 deletion src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getVersionRangePrefix(v: string) {
return null
}

export function changeVersionRange(version: string, mode: Exclude<RangeMode, 'latest' | 'newest'>) {
export function changeVersionRange(version: string, mode: Exclude<RangeMode, 'latest' | 'newest' | 'next'>) {
if (!semver.validRange(version))
return null

Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 14 additions & 0 deletions test/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3b42900

Please sign in to comment.