Skip to content

enhancement: add semver-support - #23

Merged
inayayousfi merged 2 commits into
mainfrom
enhancement/17-semver-support
Mar 14, 2026
Merged

enhancement: add semver-support#23
inayayousfi merged 2 commits into
mainfrom
enhancement/17-semver-support

Conversation

@inayayousfi

@inayayousfi inayayousfi commented Mar 14, 2026

Copy link
Copy Markdown
Owner
  • add a reusable semver model with parsing, comparison, change classification, and support for prerelease, build metadata, and revision suffixes like 1.2.3_1
  • refactor npm dependency processing to use semver-backed version structs instead of raw strings during updates
  • preserve dependency prefixes and revision suffixes while skipping no-op updates and downgrades

Closes #17

Summary by CodeRabbit

Release Notes

  • New Features

    • Added semantic versioning support for npm package dependency management.
    • Improved dependency version parsing with semver awareness for better update classification.
    • Enabled automatic downgrade prevention to avoid inadvertent version reductions.
    • Enhanced version prefix preservation (^, ~, >=, etc.) during dependency updates.
  • Tests

    • Added comprehensive test coverage for semantic versioning and dependency update workflows.

@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ZiedYousfi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 51570fd5-f011-40bc-8a8c-02efe4f510f2

📥 Commits

Reviewing files that changed from the base of the PR and between 87e0a57 and d3058d3.

📒 Files selected for processing (2)
  • npm.go
  • npm_test.go
📝 Walkthrough

Walkthrough

This PR introduces comprehensive semver support to the codebase. A new Semver type handles parsing and comparison of semantic versions. The DependencyVersion type now wraps versions with semver awareness. Dependency update flows refactored to parse, classify, and merge versions using semver semantics.

Changes

Cohort / File(s) Summary
Semver Core Implementation
semver.go, semver_test.go
Introduces complete semantic versioning system with Semver struct and SemverChange enum. Provides parsing (supporting v-prefixes, prerelease, build metadata, revision), comparison methods (Compare, LessThan, Equal), change-type detection (ChangeType, IsPatchUpdate, IsMinorUpdate, IsMajorUpdate, IsRevisionUpdate), and string formatting. Extensive test coverage validates parsing edge cases, comparisons, and update type classification.
Dependency Version Handling
npm.go
Refactors DependencyJSON.Version from string to DependencyVersion struct. Adds version parsing utilities (parseDependencyVersion, extractDependencyVersionPrefix) and dependency update helpers (classifyDependencyUpdate, mergeDependencyVersion). Updates updateDependencies flow to parse versions, classify updates by semver change type, and preserve version prefixes (e.g., ^, ~, >=). Removes normalizeDependencyVersions pathway.
Dependency Tests
npm_test.go
Expands test data to use semver-aware versions. Replaces NormalizeDependencyVersions test with data-driven TestParseDependencyVersion. Adds new tests TestUpdateDependenciesSkipsNoopAndDowngrade and TestClassifyDependencyUpdate. Updates assertions to validate Version.String() output, prefix preservation, and downgrade skip behavior.

Sequence Diagram

sequenceDiagram
    participant updateDeps as updateDependencies
    participant parseVer as parseDependencyVersion
    participant classify as classifyDependencyUpdate
    participant merge as mergeDependencyVersion
    participant store as DependencyJSON.Version

    updateDeps->>parseVer: current version string
    parseVer-->>updateDeps: DependencyVersion (parsed semver)
    
    updateDeps->>parseVer: latest version string (from npm)
    parseVer-->>updateDeps: DependencyVersion (parsed semver)
    
    updateDeps->>classify: currentVersion, latestVersion
    classify-->>updateDeps: SemverChange, shouldUpdate bool
    
    alt shouldUpdate
        updateDeps->>merge: currentVersion, latestVersion
        merge-->>updateDeps: merged DependencyVersion
        updateDeps->>store: store merged version
    else downgrade or noop
        updateDeps->>store: skip (preserve current)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #11: Modifies npm dependency handling and normalization flow; directly overlaps with this PR's refactoring of mapToDeps and dependency update pathways.
  • PR #12: Extends npm dependency and version test coverage; aligns with expanded test scenarios for parsing and update classification added in this PR.

Poem

🐰 Hoppity-hop, versions aligned,
Semver magic, nicely designed!
Patches and minors in perfect array,
Dependencies dance the semantic way! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'enhancement: add semver-support' clearly and concisely describes the main change: adding semver support. It aligns with the substantial refactoring of dependency version handling to use semantic versioning.
Linked Issues check ✅ Passed The PR implements semver support through new parsing, comparison, and update utilities in semver.go, integrates it into npm.go for dependency version handling with prefix/revision preservation, and includes comprehensive tests covering the functionality.
Out of Scope Changes check ✅ Passed All changes are in-scope: semver.go adds semantic versioning support; npm.go integrates it into dependency processing; test files validate the new functionality. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/17-semver-support
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
npm.go (2)

69-77: Consider edge case: standalone * version.

The prefix list includes *, but when the version is exactly * (a valid npm wildcard meaning "any version"), this extracts * as a prefix with an empty core version, which will fail semver parsing and fall back to raw. This is probably fine since * isn't a valid semver, but verify this matches expected behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@npm.go` around lines 69 - 77, extractDependencyVersionPrefix currently treats
a standalone "*" as a prefix and returns ("*", ""), which leads to an empty core
version and breaks downstream semver parsing; change
extractDependencyVersionPrefix so it special-cases value == "*" and returns ("",
"*") (i.e. no prefix, core version "*") so callers get a non-empty version
string and can handle the npm wildcard appropriately; update the function
extractDependencyVersionPrefix to check for value == "*" before iterating
prefixes.

163-174: Revision preservation may carry stale metadata.

When the current version has a revision (e.g., 1.2.3_1) and the latest doesn't (e.g., 1.2.4), the code preserves the old revision, resulting in 1.2.4_1. This could be misleading if the revision was specific to the old version (e.g., a distro-specific patch). If this is intentional behavior for your use case, consider adding a comment explaining the rationale.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@npm.go` around lines 163 - 174, mergeDependencyVersion currently carries the
old Semver.Revision from currentVersion into the newer latestVersion.Semver,
producing outputs like 1.2.4_1 which may be stale; change the logic in
mergeDependencyVersion so you only preserve currentVersion.Semver.Revision when
the semantic core (major/minor/patch) actually matches the latest (i.e., the
revision applies to the same base version), otherwise do not copy the revision
and return latestVersion; update the conditional that checks
currentVersion.Semver.HasRevision && !latestVersion.Semver.HasRevision to also
verify semver-core equality (or remove the revision-preserving branch entirely)
and add a comment explaining the chosen behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@npm.go`:
- Around line 69-77: extractDependencyVersionPrefix currently treats a
standalone "*" as a prefix and returns ("*", ""), which leads to an empty core
version and breaks downstream semver parsing; change
extractDependencyVersionPrefix so it special-cases value == "*" and returns ("",
"*") (i.e. no prefix, core version "*") so callers get a non-empty version
string and can handle the npm wildcard appropriately; update the function
extractDependencyVersionPrefix to check for value == "*" before iterating
prefixes.
- Around line 163-174: mergeDependencyVersion currently carries the old
Semver.Revision from currentVersion into the newer latestVersion.Semver,
producing outputs like 1.2.4_1 which may be stale; change the logic in
mergeDependencyVersion so you only preserve currentVersion.Semver.Revision when
the semantic core (major/minor/patch) actually matches the latest (i.e., the
revision applies to the same base version), otherwise do not copy the revision
and return latestVersion; update the conditional that checks
currentVersion.Semver.HasRevision && !latestVersion.Semver.HasRevision to also
verify semver-core equality (or remove the revision-preserving branch entirely)
and add a comment explaining the chosen behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: defa518c-db2b-4134-aa13-8e4f74d02de1

📥 Commits

Reviewing files that changed from the base of the PR and between d7edf16 and 87e0a57.

📒 Files selected for processing (4)
  • npm.go
  • npm_test.go
  • semver.go
  • semver_test.go

…ard support

- Avoids carrying revision suffixes across major semver core changes in mergeDependencyVersion.
- Adds semverCoreEqual helper to correctly compare version cores.
- Improves extractDependencyVersionPrefix to handle wildcard (“*”) versions accurately.
- Extends and clarifies tests for wildcard handling, revision logic, and error cases in npm_test.go.
@inayayousfi
inayayousfi merged commit cc4207a into main Mar 14, 2026
2 checks passed
@inayayousfi
inayayousfi deleted the enhancement/17-semver-support branch March 14, 2026 09:58
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.

Add semver support

1 participant