fix: use SemVer for pkgx version comparison#80
Conversation
`parseFloat("2.10")` evaluates to `2.1`, causing pkgm to silently
reject pkgx 2.10.x as below the minimum version (2.4). Use the
already-imported SemVer class for correct version comparison.
Fixes: pkgm install/uninstall/shim silently fail with exit code 1
when pkgx >= 2.10.0 is installed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes pkgm’s minimum pkgx version gate by switching from parseFloat()-based comparisons to semantic version comparison, preventing pkgx 2.10.x from being incorrectly rejected as < 2.4.
Changes:
- Update
get_pkgx()to parsepkgx --versionas a SemVer and compare against2.4.0. - Tighten the version-matching regex to a
major.minor.patchshape.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const stdout = new TextDecoder().decode(out.stdout); | ||
| const match = stdout.match(/^pkgx (\d+.\d+)/); | ||
| if (!match || parseFloat(match[1]) < 2.4) { | ||
| const match = stdout.match(/^pkgx (\d+\.\d+\.\d+)/); |
There was a problem hiding this comment.
The regex only captures the numeric major.minor.patch portion, which drops valid SemVer prerelease/build metadata from pkgx --version (eg 2.8.0-beta.1, 2.8.0+abc123). That can misclassify prereleases (eg 2.4.0-beta.1) as 2.4.0 and incorrectly pass the minimum-version gate. Consider capturing the full version token and comparing that full SemVer value instead of truncating it.
| const match = stdout.match(/^pkgx (\d+\.\d+\.\d+)/); | |
| const match = stdout.match(/^pkgx ([0-9A-Za-z.+-]+)/); |
| if (!match || new SemVer(match[1]).lt(new SemVer("2.4.0"))) { | ||
| Deno.exit(1); |
There was a problem hiding this comment.
On version parse / minimum-version failure this exits with code 1 without any error output. Since this is a user-facing CLI and version-gating is a common failure mode, please print a clear message (including the detected pkgx --version output and the required minimum) before exiting so users can self-diagnose.
|
good catch! |
Summary
parseFloat("2.10")evaluates to2.1, causingget_pkgx()to silently reject pkgx 2.10.x as below the minimum version (2.4)install,uninstall,shim) silently fail with exit code 1 when pkgx >= 2.10.0 is installedSemVerclass for proper semantic version comparison