Detect and remove unused dependencies from Cargo.toml
in Rust projects.
- use the
cargo_metadata
crate to list all dependencies specified in[workspace.dependencies]
and[dependencies]
- iterate through all package targets to locate all Rust files
- use
syn
to parse these Rust files and extract imports - identify the difference between the imports and the package dependencies
- macros
- how can imports be collected from macros? e.g. in
println!({}, foo::bar)
,foo
is a macro token instead of an identifier - can we run some other command and get the macro expanded source to parse?
- is there an API for getting imports instead of parsing?
- how can imports be collected from macros? e.g. in
- make the reporting more granular for
[dependencies]
,[dev-dependencies]
and[build-dependencies]
-
--fix
- add tests
- exit codes
- error recovery
- print things more nicely
- package renames
- uppercase package name, e.g.
Inflector
- pathname in type arguments
pub type ModuleIdToFileName = std::sync::Arc<
dashmap::DashMap<
rspack_core::ModuleIdentifier,
(String, AssetInfo),
std::hash::BuildHasherDefault<rspack_identifier::IdentifierHasher>,
>,
>;