Skip to content

refactor(pm): use typed PackageLock in lockfile outdated check#2674

Merged
elrrrrrrr merged 2 commits into
nextfrom
refactor/pm-lock-typed
Mar 10, 2026
Merged

refactor(pm): use typed PackageLock in lockfile outdated check#2674
elrrrrrrr merged 2 commits into
nextfrom
refactor/pm-lock-typed

Conversation

@elrrrrrrr

Copy link
Copy Markdown
Contributor

Summary

  • Replace raw serde_json::Value with typed PackageLock/LockPackage in is_pkg_lock_outdated
  • Simplify deps_map_equals_lock from 23 lines to 6 (accept Option<&HashMap> directly)
  • Simplify engines comparison via PartialEq instead of manual key-by-key matching
  • Hoist name variable to reduce repetition

Independent refactoring, no functional changes.

Test plan

  • cargo test -p utoo-pm -- helper::lock — 8 tests pass
  • cargo clippy -p utoo-pm --all-targets -- -D warnings --no-deps — clean

🤖 Generated with Claude Code

Replace raw `serde_json::Value` access with typed `PackageLock` and
`LockPackage` struct fields in `is_pkg_lock_outdated`. Simplify
`deps_map_equals_lock` from 23 lines to 6 by accepting typed
`Option<&HashMap>` directly. Simplify engines comparison via
`PartialEq`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the package lockfile outdated check mechanism within the utoo-pm crate. The primary goal is to enhance code clarity, maintainability, and type safety by transitioning from untyped serde_json::Value representations to strongly typed PackageLock and LockPackage structures. This change simplifies dependency and engine comparison logic, making the codebase more robust and easier to understand without introducing any functional alterations.

Highlights

  • Typed Lockfile Usage: Replaced generic serde_json::Value with specific PackageLock and LockPackage types in the is_pkg_lock_outdated function for improved type safety and readability.
  • Simplified Dependency Map Comparison: Refactored deps_map_equals_lock to directly accept Option<&HashMap<String, String>>, reducing its complexity from 23 lines to 6.
  • Streamlined Engine Comparison: Updated the engine comparison logic to leverage PartialEq for HashMaps, eliminating manual key-by-key matching.
  • Code Repetition Reduction: Hoisted the name variable in is_pkg_lock_outdated to avoid redundant declarations.
  • No Functional Changes: Confirmed that these changes are purely refactoring and do not alter the existing functionality.
Changelog
  • crates/pm/src/helper/lock.rs
    • Updated deps_map_equals_lock function signature and implementation to accept Option<&HashMap<String, String>> for direct comparison.
    • Modified is_pkg_lock_outdated to deserialize package-lock.json directly into a PackageLock struct.
    • Replaced manual serde_json::Value access with direct field access on PackageLock and LockPackage types.
    • Refactored dependency comparison calls to use lock.dependencies.as_ref() and similar typed accessors.
    • Moved the name variable declaration to a higher scope within is_pkg_lock_outdated to reduce redundancy.
    • Simplified the engine comparison logic by directly comparing HashMap instances.
Activity
  • The author confirmed that cargo test -p utoo-pm -- helper::lock passed all 8 tests.
  • cargo clippy -p utoo-pm --all-targets -- -D warnings --no-deps ran clean, indicating no new linter warnings.
  • The pull request description was generated using Claude Code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This is a great refactoring that improves code quality by using typed data structures instead of raw JSON values. The changes make the code cleaner, safer, and easier to understand. I have one minor suggestion to further simplify the code.

Comment thread crates/pm/src/helper/lock.rs
@elrrrrrrr elrrrrrrr added the A-Pkg Manager Area: Package Manager label Mar 10, 2026

@killagu killagu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@elrrrrrrr elrrrrrrr merged commit e95f620 into next Mar 10, 2026
23 checks passed
@elrrrrrrr elrrrrrrr deleted the refactor/pm-lock-typed branch March 10, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Pkg Manager Area: Package Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants