use std::path::Path;
use sdivi_graph::{parse_tsconfig_content, TsConfigPaths};
pub(crate) fn read_go_mod_prefix(root: &Path) -> Option<String> {
let content = std::fs::read_to_string(root.join("go.mod")).ok()?;
for line in content.lines() {
if let Some(rest) = line.trim().strip_prefix("module") {
let trimmed = rest.trim();
if !trimmed.is_empty() && !trimmed.starts_with('(') {
return trimmed.split_whitespace().next().map(str::to_string);
}
}
}
None
}
pub(crate) fn read_tsconfig_paths(root: &Path) -> Option<TsConfigPaths> {
let tsconfig_path = if root.join("tsconfig.json").exists() {
root.join("tsconfig.json")
} else if root.join("jsconfig.json").exists() {
root.join("jsconfig.json")
} else {
return None;
};
let content = std::fs::read_to_string(&tsconfig_path).ok()?;
parse_tsconfig_content(&content, Path::new(""))
}