Skip to content
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

feat: new mode next #116

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to specify the literal type twice, so I employ a minor trick to infer the type from the constant variable.

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)