Skip to content
Merged
Changes from 2 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
16 changes: 2 additions & 14 deletions app/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { valid } from 'semver'
import { compare, valid } from 'semver'

/**
* Utilities for handling npm package versions and dist-tags
Expand Down Expand Up @@ -47,19 +47,7 @@ export function parseVersion(version: string): ParsedVersion {
* @returns Comparison result for sorting
*/
export function compareVersions(a: string, b: string): number {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we just use compare wherever compareVersions is used instead of wrapping it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Definitely! I thought about keeping the wrapper for future changes, but it's indeed cleaner to use the package's method where needed, which also eliminates the need for tests.

const va = parseVersion(a)
const vb = parseVersion(b)

if (va.major !== vb.major) return va.major - vb.major
if (va.minor !== vb.minor) return va.minor - vb.minor
if (va.patch !== vb.patch) return va.patch - vb.patch

// Stable versions (no prerelease) are greater than prereleases
if (va.prerelease && vb.prerelease) return va.prerelease.localeCompare(vb.prerelease)
if (va.prerelease) return -1
if (vb.prerelease) return 1

return 0
return compare(a, b)
}

/**
Expand Down