use std::path::{Component, Path};
pub fn normalize_path_like(p: &Path) -> String {
let mut out = std::path::PathBuf::new();
for comp in p.components() {
match comp {
Component::CurDir => {}
Component::ParentDir => {
out.pop();
}
other => out.push(other.as_os_str()),
}
}
out.to_string_lossy().replace('\\', "/")
}
pub fn resolve_module_path(cur_file: &str, raw: &str, exts: &[&str]) -> Option<String> {
let mut s = raw.trim().to_string();
for &ext in exts {
if s.ends_with(ext) {
s.truncate(s.len() - ext.len());
}
}
let s = s.replace('\\', "/");
if s.starts_with("./") || s.starts_with("../") {
let base = Path::new(cur_file)
.parent()
.unwrap_or_else(|| Path::new("."));
let joined = base.join(&s);
Some(normalize_path_like(&joined))
} else {
Some(s.trim_start_matches('/').to_string())
}
}