diff --git a/crates/domain/src/value_objects/source/module_name.rs b/crates/domain/src/value_objects/source/module_name.rs index 79888b6..d0d0c09 100644 --- a/crates/domain/src/value_objects/source/module_name.rs +++ b/crates/domain/src/value_objects/source/module_name.rs @@ -20,8 +20,10 @@ impl ModuleName { root: &Path, module_mappings: &HashMap, ) -> Option { + 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('/'); diff --git a/crates/presentation/src/lib.rs b/crates/presentation/src/lib.rs index 332fcb0..b52e214 100644 --- a/crates/presentation/src/lib.rs +++ b/crates/presentation/src/lib.rs @@ -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 = 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 = graph @@ -235,21 +238,17 @@ 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) - && let Ok(edge) = archlens_domain::Relationship::new( - &src_cap, - &tgt_cap, - archlens_domain::RelationshipKind::Composition, - ) - { - graph.add_relationship(edge); - } + 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, + archlens_domain::RelationshipKind::Composition, + ) + { + graph.add_relationship(edge); } } }