1use std::path::{Path, PathBuf};
2
3pub fn resolve_relative_import(current_file: &Path, import_src: &str) -> Option<PathBuf> {
4 let parent = current_file.parent().unwrap_or(Path::new("."));
5 let base_path = parent.join(import_src);
6
7 if base_path.exists() && base_path.is_file() { return Some(base_path); }
9
10 for ext in &["js", "ts", "jsx", "tsx", "mjs", "cjs"] {
12 let p = base_path.with_extension(ext);
13 if p.exists() { return Some(p); }
14 }
15
16 let index_path = base_path.join("index");
18 for ext in &["js", "ts", "jsx", "tsx", "mjs", "cjs"] {
19 let p = index_path.with_extension(ext);
20 if p.exists() { return Some(p); }
21 }
22
23 None
24}