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, root: &Path,
module_mappings: &HashMap<String, String>, module_mappings: &HashMap<String, String>,
) -> Option<Self> { ) -> 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 let relative = file_path
.strip_prefix(root.to_str().unwrap_or("")) .strip_prefix(root_str)
.unwrap_or(file_path) .unwrap_or(file_path)
.trim_start_matches('/'); .trim_start_matches('/');

View File

@@ -216,13 +216,16 @@ fn merge_project_deps_as_module_edges(
) { ) {
use std::collections::HashMap; 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() { for element in project_graph.elements() {
let module = element let module = if let Some(m) = element.module() {
.module() m.as_str().to_string()
.map(|m| m.as_str()) } else {
.unwrap_or(element.name()); let path = element.file_path().as_str();
crate_to_module.insert(element.name(), module); 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 let graph_modules: std::collections::HashSet<String> = graph
@@ -235,21 +238,17 @@ fn merge_project_deps_as_module_edges(
let src_module = crate_to_module.get(rel.source()); let src_module = crate_to_module.get(rel.source());
let tgt_module = crate_to_module.get(rel.target()); let tgt_module = crate_to_module.get(rel.target());
if let (Some(src), Some(tgt)) = (src_module, tgt_module) { if let (Some(src_cap), Some(tgt_cap)) = (src_module, tgt_module)
let src_cap = ModuleName::capitalize(src); && src_cap != tgt_cap
let tgt_cap = ModuleName::capitalize(tgt); && graph_modules.contains(src_cap)
&& graph_modules.contains(tgt_cap)
if src_cap != tgt_cap && let Ok(edge) = archlens_domain::Relationship::new(
&& graph_modules.contains(&src_cap) src_cap,
&& graph_modules.contains(&tgt_cap) tgt_cap,
&& let Ok(edge) = archlens_domain::Relationship::new( archlens_domain::RelationshipKind::Composition,
&src_cap, )
&tgt_cap, {
archlens_domain::RelationshipKind::Composition, graph.add_relationship(edge);
)
{
graph.add_relationship(edge);
}
} }
} }
} }