Skip to content

Commit

Permalink
feat: handle package rename in workspace dependencies
Browse files Browse the repository at this point in the history
e.g. `ustr = { package = "ustr-fxhash", version = "1.0.0" }`
  • Loading branch information
Boshen committed Apr 9, 2024
1 parent bd45f9f commit aa2e832
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ proc-macro2 = { version = "1", features = ["span-locations"] }
syn = { version = "2", features = [
"full",
"visit",
"extra-traits" # add "extra-traits" to debug syn ast
"extra-traits", # add "extra-traits" to debug syn ast
] }
regex = "1.10.4"
rayon = "1.10.0"
Expand Down
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,24 @@ impl CargoShear {
let cargo_toml_path = metadata_path.join("Cargo.toml");
let metadata = cargo_toml::Manifest::from_path(&cargo_toml_path)?;
let Some(workspace) = &metadata.workspace else { return Ok(()) };

let ignored_package_names =
Self::get_ignored_package_names(&workspace_metadata.workspace_metadata);

let workspace_deps = workspace
.dependencies
.keys()
.iter()
.map(|(key, dependency)| {
// renamed package, e.g. `ustr = { package = "ustr-fxhash", version = "1.0.0" }`
dependency
.detail()
.and_then(|detail| detail.package.as_ref())
.unwrap_or(key)
.clone()
})
.filter(|name| !ignored_package_names.contains(name.as_str()))
.cloned()
.collect::<HashSet<String>>();

let unused_deps = workspace_deps.difference(all_pkg_deps).cloned().collect::<Vec<_>>();

if unused_deps.is_empty() {
Expand Down

0 comments on commit aa2e832

Please sign in to comment.