use std::path::{Path, PathBuf};
use super::Import;
pub fn dependents_of<P: AsRef<Path>>(module: &str, index: &[(P, Vec<Import>)]) -> Vec<PathBuf> {
let module_finder = memchr::memmem::Finder::new(module.as_bytes());
let mut out = Vec::new();
for (path, imports) in index {
for imp in imports {
let module_match = imp
.module
.as_deref()
.is_some_and(|m| m == module || module_finder.find(m.as_bytes()).is_some());
let raw_match = !module_match && module_finder.find(imp.raw.as_bytes()).is_some();
if module_match || raw_match {
out.push(path.as_ref().to_path_buf());
break;
}
}
}
out.sort();
out
}