Skip to content

fix: sort versions semantically (ascending order)#2

Merged
jdx merged 1 commit intomainfrom
fix/version-sorting
Jan 18, 2026
Merged

fix: sort versions semantically (ascending order)#2
jdx merged 1 commit intomainfrom
fix/version-sorting

Conversation

@jdx
Copy link
Member

@jdx jdx commented Jan 18, 2026

Summary

  • Versions were returned in the order they appeared in the HTML from ftp.postgresql.org, which was reverse lexicographic order
  • This caused issues like 9.6.9 appearing before 9.6.24 and version 10.x appearing after 9.x

Changes

  • Added semantic version comparison that parses version strings into numeric parts
  • Sorts in ascending order (oldest first, newest last)

Before

9.6.9
9.6.8
9.6.24
9.6.23
...
10.1
10.0
1.09
1.08

After

1.08
1.09
...
9.6.23
9.6.24
...
10.0
10.1
...
17.2

🤖 Generated with Claude Code

Versions were returned in the order they appeared in the HTML from
ftp.postgresql.org, which was reverse lexicographic order. This caused
issues like 9.6.9 appearing before 9.6.24 and version 10.x appearing
after 9.x.

Added semantic version comparison that:
- Parses version strings into numeric parts
- Compares parts numerically (not lexicographically)
- Sorts in ascending order (oldest first, newest last)
@jdx jdx merged commit 125c484 into main Jan 18, 2026
jdx added a commit to jdx/mise that referenced this pull request Jan 18, 2026
## Summary
- Adds a new `semver` Lua module that vfox plugins can use for semantic
version comparison and sorting
- Eliminates the need for each plugin to implement their own version
sorting logic

## API
- `semver.compare(v1, v2)` - Returns -1, 0, or 1
- `semver.parse(version)` - Returns table of numeric parts
- `semver.sort(versions)` - Sorts string array ascending
- `semver.sort_by(items, field)` - Sorts table array by version field

## Example Usage
```lua
local semver = require("semver")

-- Method 1: Use in custom sort
table.sort(result, function(a, b)
    return semver.compare(a.version, b.version) < 0
end)

-- Method 2: Use sort_by helper
result = semver.sort_by(result, "version")
```

## Test Plan
- [x] Unit tests for `parse_version`, `compare_versions`
- [x] Lua integration test

## Related
- vfox-postgres fix:
mise-plugins/vfox-postgres#2

🤖 Generated with [Claude Code](https://claude.ai/code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds a built-in `semver` Lua module and integrates it into the plugin
runtime.
> 
> - New `lua_mod/semver.rs` exports `compare`, `parse`, `sort`, and
`sort_by` for semantic version handling; includes unit and Lua
integration tests
> - Registers `semver` in `lua_mod/mod.rs` and loads it in `plugin.rs`
so `require("semver")` is available to plugins
> - Updates `docs/plugin-lua-modules.md` with `semver` usage and
examples
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e97711a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant