fix: canonicalize root path for module inference, fix crate-to-module mapping

This commit is contained in:
2026-06-16 16:40:02 +02:00
parent ae241aacac
commit 100b014ff6
2 changed files with 23 additions and 22 deletions

View File

@@ -20,8 +20,10 @@ impl ModuleName {
root: &Path,
module_mappings: &HashMap<String, String>,
) -> Option<Self> {
let canonical_root = root.canonicalize().unwrap_or_else(|_| root.to_path_buf());
let root_str = canonical_root.to_str().unwrap_or("");
let relative = file_path
.strip_prefix(root.to_str().unwrap_or(""))
.strip_prefix(root_str)
.unwrap_or(file_path)
.trim_start_matches('/');

View File

@@ -216,13 +216,16 @@ fn merge_project_deps_as_module_edges(
) {
use std::collections::HashMap;
let mut crate_to_module: HashMap<&str, &str> = HashMap::new();
let mut crate_to_module: HashMap<String, String> = HashMap::new();
for element in project_graph.elements() {
let module = element
.module()
.map(|m| m.as_str())
.unwrap_or(element.name());
crate_to_module.insert(element.name(), module);
let module = if let Some(m) = element.module() {
m.as_str().to_string()
} else {
let path = element.file_path().as_str();
let dir = path.split('/').rev().nth(1).unwrap_or(element.name());
ModuleName::capitalize(dir)
};
crate_to_module.insert(element.name().to_string(), module);
}
let graph_modules: std::collections::HashSet<String> = graph
@@ -235,23 +238,19 @@ fn merge_project_deps_as_module_edges(
let src_module = crate_to_module.get(rel.source());
let tgt_module = crate_to_module.get(rel.target());
if let (Some(src), Some(tgt)) = (src_module, tgt_module) {
let src_cap = ModuleName::capitalize(src);
let tgt_cap = ModuleName::capitalize(tgt);
if src_cap != tgt_cap
&& graph_modules.contains(&src_cap)
&& graph_modules.contains(&tgt_cap)
if let (Some(src_cap), Some(tgt_cap)) = (src_module, tgt_module)
&& src_cap != tgt_cap
&& graph_modules.contains(src_cap)
&& graph_modules.contains(tgt_cap)
&& let Ok(edge) = archlens_domain::Relationship::new(
&src_cap,
&tgt_cap,
src_cap,
tgt_cap,
archlens_domain::RelationshipKind::Composition,
)
{
graph.add_relationship(edge);
}
}
}
}
fn run_diff(args: &Cli, existing_path: &std::path::Path) -> Result<()> {