use crate::{AppContext, ModuleId, PluginInfo};
pub fn imports(ctx: &AppContext, importer: ModuleId, imported: ModuleId) -> bool {
let graph = &ctx.inner.graph;
let (Some(from), Some(target)) = (graph.module_of(importer), graph.module_of(imported)) else {
return false;
};
if from == target {
return false;
}
let mut visited = vec![false; graph.modules.len()];
visited[from] = true;
let mut pending = vec![from];
while let Some(module) = pending.pop() {
for &next in &graph.modules[module].imports {
if next == target {
return true;
}
if !visited[next] {
visited[next] = true;
pending.push(next);
}
}
}
false
}
pub fn is_community_plugin(ctx: &AppContext, module: ModuleId) -> bool {
ctx.plugin(module)
.is_some_and(|info| !ctx.inner.graph.first_party.contains(info.name))
}
pub fn acts_for(ctx: &AppContext, module: ModuleId) -> Option<&PluginInfo> {
let graph = &ctx.inner.graph;
let first = graph
.acts_for
.get(graph.module_of(module)?)
.copied()
.flatten()?;
graph.modules[first].plugin.as_ref()
}
pub fn is_app_module(ctx: &AppContext, module: ModuleId) -> bool {
let graph = &ctx.inner.graph;
graph
.module_of(module)
.is_some_and(|index| graph.acts_for.get(index).copied().flatten().is_none())
}