orium / cargo-rdme

Cargo command to create the README.md from your crate's documentation
Mozilla Public License 2.0
126 stars 5 forks source link

Be sure to select packages only from the workspace, not other dependencies #237

Closed maackle closed 2 months ago

maackle commented 2 months ago

In situations where multiple version of a package are included as dependencies, cargo-rdme only chooses the first one it finds. metadata.workspace_members seems to only list the latest version. This PR updates the package selection to choose the package with the latest version when there are multiple choices.

The test in the first commit fails, the second commit fixes it.

maackle commented 2 months ago

This may not be the ideal solution (ideally we select the local package, if there are multiple), but I think this is better than selecting arbitrarily.

orium commented 2 months ago

This may not be the ideal solution (ideally we select the local package, if there are multiple), but I think this is better than selecting arbitrarily.

We can do better. What we want to do is select the package that is in the workspace. That can be done by checking the package id. The method select_package() can simply become

metadata.packages.iter().find(|package| {
    package.name == package_name && metadata.workspace_members.contains(&package.id)
})

Edit: Can you also squash your commits. No need to have a commit with the test before the fix.

maackle commented 2 months ago

Ah yes that's better. I made that change and reset everything to a single commit.

orium commented 2 months ago

Thanks for you contribution @maackle. I'll cut a release now.

orium commented 2 months ago

Released in v1.4.4.