fix(version): compare SemVer prereleases correctly - #173
Conversation
fed2e02 to
3eda73f
Compare
3eda73f to
2800b40
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d2726817f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (candidateIdentifier.length !== installedIdentifier.length) { | ||
| return candidateIdentifier.length > installedIdentifier.length; |
There was a problem hiding this comment.
Reject leading-zero numeric prerelease identifiers
When a custom or malformed registry returns 1.0.0-alpha.01 for an installation at 1.0.0-alpha.1, VERSION_PATTERN accepts the candidate and this length comparison reports it as newer. SemVer forbids leading zeroes in numeric prerelease identifiers, so an invalid registry version can now produce an update notice instead of being ignored; validate prerelease identifiers before applying the length-based numeric comparison.
Useful? React with 👍 / 👎.
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Summary
alpha.1/alpha-1case as regression coverageRoot cause
The update notifier compared each complete prerelease string with
Intl.Collator. Locale-aware comparison does not implement SemVer's identifier boundaries or precedence rules, so valid versions such as1.0.0-alpha-1and1.0.0-alpha.1could be ordered incorrectly.Impact
Prerelease users receive update notices only when the registry version has higher SemVer precedence. Stable-version behavior is unchanged.
Overlap check
Before publishing, open issues and pull requests were reviewed and repository-wide searches were run for
semver,prerelease,update notice, andversion comparison. No active issue or pull request overlaps this fix. The only related search hits were already-merged work that introduced the broader update-notice and release features.Validation
pnpm dlx bun test --timeout 30000 ./tests-ts/update-notice.test.ts— 10 passedpnpm exec tsc --noEmitpnpm exec prettier --check src/version.ts tests-ts/update-notice.test.tsgit diff --check