pub trait FrameworkDetector: Send + Sync {
fn name(&self) -> &'static str;
fn get_entry_patterns(&self) -> Vec<String>;
fn get_special_exports(&self) -> Vec<&'static str>;
fn detect_from_dependencies(&self, deps: &[String]) -> bool;
}
pub struct PluginRegistry {
detectors: Vec<Box<dyn FrameworkDetector>>,
}
impl Default for PluginRegistry {
fn default() -> Self {
Self::new()
}
}
impl PluginRegistry {
pub fn new() -> Self {
Self {
detectors: Vec::new(),
}
}
pub fn register(&mut self, detector: Box<dyn FrameworkDetector>) {
self.detectors.push(detector);
}
pub fn detectors(&self) -> &[Box<dyn FrameworkDetector>] {
&self.detectors
}
pub fn with_builtins() -> Self {
use super::frameworks::*;
let mut registry = Self::new();
registry.register(Box::new(NextJsDetector::new()));
registry.register(Box::new(JestDetector::new()));
registry.register(Box::new(VitestDetector::new()));
registry.register(Box::new(ExpressDetector::new()));
registry
}
}