Skip to content
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
4 changes: 2 additions & 2 deletions app/composables/useInstallSizeDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const SIZE_DECREASE_THRESHOLD = 0.2
const DEP_DECREASE_THRESHOLD = 3

function getComparisonVersion(pkg: SlimPackument, resolvedVersion: string): string | null {
const isCurrentPrerelease = getPrerelease(resolvedVersion) !== null
const isCurrentPrerelease = getPrerelease(resolvedVersion)?.length

const stableVersions = Object.keys(pkg.time)
.filter(v => v !== 'modified' && v !== 'created' && isValid(v) && getPrerelease(v) === null)
.filter(v => v !== 'modified' && v !== 'created' && isValid(v) && !getPrerelease(v)?.length)
.sort((a, b) => compare(a, b))

if (isCurrentPrerelease) {
Expand Down
32 changes: 6 additions & 26 deletions app/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ export interface ParsedVersion {
prerelease: string
}

/**
* Parse a semver stable version string into its components
* `@param` version - The version string (e.g., "1.2.3")
* `@returns` Parsed version object with major, minor, patch, or null for
* invalid versions and for prerelease versions (e.g., "1.0.0-beta.1")
*/
export function parseVersion(version: string): ParsedVersion {
const parsedVersion = tryParse(version)

if (!parsedVersion) {
return { major: 0, minor: 0, patch: 0, prerelease: '' }
}

return {
major: parsedVersion.major,
minor: parsedVersion.minor,
patch: parsedVersion.patch,
prerelease: parsedVersion.prerelease.join('.'),
}
}

/**
* Parse a semver stable version string into its components
* @param version - The version string (e.g., "1.2.3" or "1.0.0-beta.1")
Expand All @@ -52,7 +31,7 @@ export function parseVersion(version: string): ParsedVersion {
export function parseStableVersion(version: string): Omit<ParsedVersion, 'prerelease'> | null {
const parsedVersion = tryParse(version)

if (!parsedVersion || parsedVersion.prerelease.length > 0) {
if (!parsedVersion || parsedVersion.prerelease?.length) {
return null
}

Expand All @@ -69,9 +48,9 @@ export function parseStableVersion(version: string): Omit<ParsedVersion, 'prerel
* @returns The channel name (e.g., "beta") or empty string for stable versions
*/
export function getPrereleaseChannel(version: string): string {
const parsed = parseVersion(version)
if (!parsed.prerelease) return ''
const match = parsed.prerelease.match(/^([a-z]+)/i)
const tag = tryParse(version)?.prerelease?.[0]
if (!tag) return ''
const match = String(tag).match(/^([a-z]+)/i)
return match ? match[1]!.toLowerCase() : ''
}

Expand Down Expand Up @@ -238,7 +217,8 @@ export function filterExcludedTags(tags: string[], excludeTags: string[]): strin
* @returns A grouping key string (e.g., "0.9", "1")
*/
export function getVersionGroupKey(version: string): string {
const parsed = parseVersion(version)
const parsed = tryParse(version)
if (!parsed) return '0.0'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (parsed.major === 0) {
// For 0.x versions, group by major.minor
return `0.${parsed.minor}`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"unocss": "66.7.4",
"valibot": "1.4.2",
"validate-npm-package-name": "8.0.0",
"verkit": "0.1.2",
"verkit": "0.3.1",
"virtua": "0.49.2",
"vite-plugin-pwa": "1.3.0",
"vite-plus": "catalog:vite-plus",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ ignoreWorkspaceRootCheck: true

minimumReleaseAgeExclude:
- vue-data-ui@3.22.13
- verkit@0.1.2
- module-replacements@3.1.0

overrides:
Expand Down
55 changes: 5 additions & 50 deletions test/unit/app/utils/versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getVersionGroupLabel,
isExactVersion,
isSameVersionGroup,
parseVersion,
parseStableVersion,
sortTags,
} from '~/utils/versions'
Expand Down Expand Up @@ -49,55 +48,6 @@ describe('isExactVersion', () => {
})
})

describe('parseVersion', () => {
it('parses stable versions', () => {
expect(parseVersion('1.2.3')).toEqual({
major: 1,
minor: 2,
patch: 3,
prerelease: '',
})
})

it('parses prerelease versions', () => {
expect(parseVersion('1.0.0-beta.1')).toEqual({
major: 1,
minor: 0,
patch: 0,
prerelease: 'beta.1',
})
})

it('handles invalid versions gracefully', () => {
expect(parseVersion('invalid')).toEqual({
major: 0,
minor: 0,
patch: 0,
prerelease: '',
})
})

it('parses TypeScript-style versions', () => {
// TypeScript uses versions like 5.8.0-beta, 5.8.0-rc
expect(parseVersion('5.8.0-beta')).toEqual({
major: 5,
minor: 8,
patch: 0,
prerelease: 'beta',
})
})

it('parses Next.js canary versions', () => {
// Next.js uses versions like 15.3.0-canary.1
expect(parseVersion('15.3.0-canary.1')).toEqual({
major: 15,
minor: 3,
patch: 0,
prerelease: 'canary.1',
})
})
})

describe('getPrereleaseChannel', () => {
it('returns empty string for stable versions', () => {
expect(getPrereleaseChannel('1.0.0')).toBe('')
Expand All @@ -122,6 +72,11 @@ describe('getPrereleaseChannel', () => {
it('handles versions with just channel name (TypeScript style)', () => {
expect(getPrereleaseChannel('5.8.0-beta')).toBe('beta')
})

it('handles versions with numerical prerelease channel name', () => {
expect(getPrereleaseChannel('3.0.0-0')).toBe('')
expect(getPrereleaseChannel('3.0.0-1')).toBe('')
})
})

describe('sortTags', () => {
Expand Down
Loading