Skip to content

Instantly share code, notes, and snippets.

@sunshowers
Created May 7, 2020 19:02
Show Gist options
  • Save sunshowers/91f9189db45318befb1189624e82be82 to your computer and use it in GitHub Desktop.
Save sunshowers/91f9189db45318befb1189624e82be82 to your computer and use it in GitHub Desktop.
// This is a map of direct deps by name -> version -> packages that depend on it.
let mut direct_deps: BTreeMap<&str, BTreeMap<&Version, Vec<&str>>> = BTreeMap::new();
package_graph.query_workspace().resolve_with_fn(|_, link| {
// Collect direct dependencies of workspace packages.
let (from, to) = link.endpoints();
if from.in_workspace() && !to.in_workspace() {
direct_deps
.entry(to.name())
.or_default()
.entry(to.version())
.or_default()
.push(from.name());
}
// query_workspace + preventing further traversals will mean that only direct
// dependencies are considered.
false
});
for (direct_dep, versions) in direct_deps {
if versions.len() > 1 {
let mut msg = format!("duplicate direct dependency '{}':\n", direct_dep);
for (version, packages) in versions {
msg.push_str(&format!(" * {} (", version));
msg.push_str(&packages.join(", "));
msg.push_str(")\n");
}
out.write(LintLevel::Error, msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment