Skip to content

fix(upgrade): compare prerelease versions per SemVer#34

Merged
riglar merged 1 commit into
devfrom
fix/upgrade-prerelease-comparison
Jun 24, 2026
Merged

fix(upgrade): compare prerelease versions per SemVer#34
riglar merged 1 commit into
devfrom
fix/upgrade-prerelease-comparison

Conversation

@riglar

@riglar riglar commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Problem

dcd upgrade would not upgrade from 5.0.0-beta.0 to 5.0.0-beta.1, reporting "Already on the latest version" instead.

VersionService.isOutdated stripped the prerelease suffix before comparing:

const nums = version.split('-')[0].split('.').map(Number);

So 5.0.0-beta.0 and 5.0.0-beta.1 both collapsed to [5,0,0], compared equal, and the upgrade was treated as a no-op. The same outdated-version nudge in cloud.ts was affected.

Fix

Replace the naive major.minor.patch compare with a SemVer 2.0.0 compareSemver helper that handles prerelease precedence:

  • A prerelease ranks below its final release (5.0.0-beta.1 < 5.0.0).
  • Prerelease identifiers compare dot-by-dot: numeric numerically, alphanumeric lexically, numeric sorts below alphanumeric, more identifiers wins. So beta.0 < beta.1 and beta.2 < beta.10.

Added test/unit/version.service.test.ts covering the regression plus release/prerelease/equality/v-prefix cases. pnpm typecheck passes; all new tests pass.

Note

This fixes the comparator so future upgrades work. A binary already running the old beta.0 comparator still can't detect the bump — those users need one reinstall to pick up this fix, after which beta-to-beta upgrades work.

🤖 Generated with Claude Code

`isOutdated` stripped the prerelease suffix before comparing, so
beta-to-beta bumps like 5.0.0-beta.0 -> 5.0.0-beta.1 both collapsed to
[5,0,0], compared equal, and `dcd upgrade` reported "Already on the
latest version". Same nudge in cloud.ts was affected.

Replace the naive major.minor.patch compare with a SemVer 2.0.0
`compareSemver` helper that handles prerelease precedence (a prerelease
ranks below its final release; identifiers compare dot-by-dot, numeric
numerically and below alphanumeric). Add unit coverage for the
regression and related cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented Jun 24, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@riglar
riglar merged commit f77841f into dev Jun 24, 2026
6 checks passed
@riglar
riglar deleted the fix/upgrade-prerelease-comparison branch June 24, 2026 08:33
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