Skip to content

feat: better printing of dependency diffs - #25

Merged
inayayousfi merged 3 commits into
mainfrom
enhancement/16-better-deps-diff-printing
Mar 14, 2026
Merged

feat: better printing of dependency diffs#25
inayayousfi merged 3 commits into
mainfrom
enhancement/16-better-deps-diff-printing

Conversation

@inayayousfi

@inayayousfi inayayousfi commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • print dependency updates to stdout even without verbose logging, with clear before/after versions for dependencies and devDependencies
  • add a reusable Semver.Diff helper so semver changes can be formatted consistently
  • cover the new output behavior and diff helper with tests

Closes #16

Summary by CodeRabbit

Release Notes

  • New Features

    • Added detailed reporting of dependency updates showing before/after version changes
    • Update reports now distinguish between dependencies and dev dependencies
    • Formatted output displays version transitions and change types for clarity
    • Reports generated in both preview (dry-run) and actual update modes
  • Bug Fixes

    • Improved error handling in dependency update logic to prevent early termination

Make dependency changes visible without requiring verbose logging so package updates clearly show before-and-after versions. Add reusable semver diff formatting to keep dependency output consistent across update paths.
@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 12 minutes and 22 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: b5f21f24-d37e-4591-ba4d-cc88b5e5fc81

📥 Commits

Reviewing files that changed from the base of the PR and between 8689cc1 and ed4a746.

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

Walkthrough

The changes introduce a dependency update reporting infrastructure by adding an output writer field to the Context struct, creating a DependencyUpdate type to track version changes, updating dependency processing to collect and report these updates, and adding a Diff method to Semver for formatting version comparisons.

Changes

Cohort / File(s) Summary
Output Infrastructure
ctx.go
Added Output io.Writer field to Context struct and initialized it to os.Stdout, along with necessary imports for io and os packages.
Dependency Update Reporting
npm.go
Introduced DependencyUpdate type with Name, Before, and After fields. Added utility functions outputWriter(), formatDependencyDiff(), printDependencyUpdates(), and method (DependencyUpdate).String(). Updated updateDependencies() signature to return ([]DependencyUpdate, error) and accumulate updates instead of returning early. Enhanced processNPMPackage() to collect and print dependency updates.
Version Diff Display
semver.go
Added Diff(other Semver) method that returns a formatted string comparing current and target versions with change type (e.g., "1.2.3 -> 1.2.4 (patch)").
Test Updates
npm_test.go, semver_test.go
Updated npm_test.go to handle new updateDependencies() signature returning updates and errors, added output capture via Context.Output field, and verified update reports. Added test case in semver_test.go for Diff() method output.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant ProcessNPM as processNPMPackage()
    participant UpdateDeps as updateDependencies()
    participant Print as printDependencyUpdates()
    participant Output as Context.Output

    Caller->>ProcessNPM: process package (dry-run or actual)
    ProcessNPM->>UpdateDeps: update dependencies list
    UpdateDeps->>UpdateDeps: fetch versions & compare
    UpdateDeps-->>ProcessNPM: return []DependencyUpdate, error
    
    ProcessNPM->>UpdateDeps: update devDependencies list
    UpdateDeps-->>ProcessNPM: return []DependencyUpdate, error
    
    ProcessNPM->>Print: printDependencyUpdates(deps updates)
    Print->>Print: outputWriter() → get Context.Output
    Print->>Output: write formatted update report
    
    ProcessNPM->>Print: printDependencyUpdates(devDeps updates)
    Print->>Output: write formatted update report
    
    ProcessNPM-->>Caller: complete with updates reported
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • enhancement: add semver-support #23: Modifies semver and npm dependency handling to add and use new Semver methods alongside dependency update representation changes.
  • techinal/10 #11: Extends the Context struct in ctx.go and modifies npm.go, providing foundational changes that this PR builds upon.

Poem

🐰 A rabbit hops through versions fine,
Before and after, now they align!
With Output streams and Updates bright,
Dependencies dance into the light! ✨

🚥 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 'feat: better printing of dependency diffs' directly and clearly describes the main change—improving how dependency version changes are displayed.
Linked Issues check ✅ Passed The PR implements all requirements from issue #16: always-visible dependency output (via Context.Output field), before/after version printing (via DependencyUpdate and Diff helper), and comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: io/os imports and Context.Output for dependency output, DependencyUpdate type and related functions for formatted printing, Semver.Diff for version formatting, and tests validating the new behavior.

✏️ 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/16-better-deps-diff-printing
📝 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.

Route visible dependency diff messages through the existing log package so normal output follows the project's logging infrastructure. Keep tests deterministic by injecting a test logger instead of writing directly to stdout.

@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)

126-132: The nil check is redundant given the default initialization.

Ctx.Output is initialized to os.Stdout in ctx.go, so Ctx.Output will never be nil in practice. The fallback is defensive but unnecessary.

♻️ Suggested simplification
 func outputWriter() io.Writer {
-	if Ctx.Output != nil {
-		return Ctx.Output
-	}
-
-	return os.Stdout
+	return Ctx.Output
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@npm.go` around lines 126 - 132, The nil check in outputWriter() is
unnecessary because Ctx.Output is default-initialized to os.Stdout in ctx.go;
simplify the function by removing the conditional and directly return Ctx.Output
(reference symbols: function outputWriter and variable Ctx.Output, and
initialization in ctx.go) so the function is a single return of Ctx.Output.

166-202: Returning nil on error discards partial updates.

When getNPMPackageLatestVersion fails mid-iteration (line 178), any successfully processed updates are discarded by returning nil. This matches the test expectations but may lose useful information about which dependencies were successfully evaluated before the failure.

If partial visibility is desired, consider returning updates instead of nil on error. However, the current behavior is consistent and acceptable if the intent is all-or-nothing semantics.

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

In `@npm.go` around lines 166 - 202, The function updateDependencies currently
returns nil on error from getNPMPackageLatestVersion, discarding any partial
updates; change the error return to return the collected updates along with the
error (i.e. return updates, fmt.Errorf(...)) so callers can see which
DependencyUpdate entries were produced before the failure; update any tests or
callers that expect all-or-nothing behavior if needed and keep references to
updateDependencies, getNPMPackageLatestVersion, and DependencyUpdate when making
the change.
🤖 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 126-132: The nil check in outputWriter() is unnecessary because
Ctx.Output is default-initialized to os.Stdout in ctx.go; simplify the function
by removing the conditional and directly return Ctx.Output (reference symbols:
function outputWriter and variable Ctx.Output, and initialization in ctx.go) so
the function is a single return of Ctx.Output.
- Around line 166-202: The function updateDependencies currently returns nil on
error from getNPMPackageLatestVersion, discarding any partial updates; change
the error return to return the collected updates along with the error (i.e.
return updates, fmt.Errorf(...)) so callers can see which DependencyUpdate
entries were produced before the failure; update any tests or callers that
expect all-or-nothing behavior if needed and keep references to
updateDependencies, getNPMPackageLatestVersion, and DependencyUpdate when making
the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33767025-1c8e-4949-ad7b-47a0d649b94f

📥 Commits

Reviewing files that changed from the base of the PR and between 487cd48 and 8689cc1.

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

- Change log output from Info to Debug level for dependency version checks and up-to-date reporting.
- Remove redundant update action log, streamlining console output during dependency updates.
- No changes to update logic; only logging/moderation of output for improved clarity.
@inayayousfi
inayayousfi merged commit e1b935d into main Mar 14, 2026
2 checks passed
@inayayousfi
inayayousfi deleted the enhancement/16-better-deps-diff-printing branch March 14, 2026 10:29
@coderabbitai coderabbitai Bot mentioned this pull request May 9, 2026
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.

Better printing of deps diffs

1 participant