Skip to main content

fallow_engine/
plugins.rs

1//! Plugin registry helpers and types exposed through the engine boundary.
2
3use std::path::Path;
4
5use fallow_config::{ExternalPluginDef, PackageJson};
6
7use crate::core_backend;
8
9/// External-plugin dry-run primitives for the CLI's `plugin-check` command.
10pub use crate::core_backend::{
11    CheckWarning, ManifestResult, RuleReport, WarningKind, check_manifest_entries,
12    is_external_plugin_active,
13};
14
15/// Built-in plugin name roster.
16pub mod registry {
17    use crate::core_backend;
18
19    /// Names of every built-in framework plugin in registry order.
20    ///
21    /// Delegates to the core registry rather than mirroring it. A hand-kept
22    /// copy drifted here once already, silently omitting `deno`, and nothing
23    /// pinned the two together.
24    #[must_use]
25    pub fn builtin_plugin_names() -> Vec<&'static str> {
26        core_backend::builtin_plugin_names()
27    }
28
29    /// The config globs that the named built-in plugin reads by file name,
30    /// and the binaries whose `--config` / `-c` package script argument names
31    /// a config of the plugin. `None` when no built-in plugin has this name.
32    #[must_use]
33    pub fn builtin_config_lookup(
34        plugin_name: &str,
35    ) -> Option<(&'static [&'static str], &'static [&'static str])> {
36        core_backend::builtin_config_lookup(plugin_name)
37    }
38}
39
40/// Aggregated results from all active plugins for a project.
41#[derive(Debug, Clone, Default)]
42pub struct AggregatedPluginResult {
43    inner: core_backend::BackendAggregatedPluginResult,
44}
45
46impl AggregatedPluginResult {
47    /// Names of active plugins.
48    #[must_use]
49    pub fn active_plugins(&self) -> &[String] {
50        self.inner.active_plugins()
51    }
52
53    /// The plugin stage's advisories (`plugin-config-unreadable`,
54    /// `plugin-effect-not-modeled`), with paths rendered against `root`.
55    #[must_use]
56    pub fn plugin_diagnostics(&self, root: &Path) -> Vec<fallow_config::WorkspaceDiagnostic> {
57        self.inner.plugin_diagnostics(root)
58    }
59
60    pub(crate) fn backend(&self) -> &core_backend::BackendAggregatedPluginResult {
61        &self.inner
62    }
63}
64
65impl From<core_backend::BackendAggregatedPluginResult> for AggregatedPluginResult {
66    fn from(inner: core_backend::BackendAggregatedPluginResult) -> Self {
67        Self { inner }
68    }
69}
70
71/// Registry of all available plugins.
72pub struct PluginRegistry {
73    inner: core_backend::BackendPluginRegistry,
74}
75
76impl PluginRegistry {
77    /// Create a registry with all built-in plugins and optional external plugins.
78    #[must_use]
79    pub(crate) fn new(external: Vec<ExternalPluginDef>) -> Self {
80        Self {
81            inner: core_backend::BackendPluginRegistry::new(external),
82        }
83    }
84
85    /// Hidden directory names that should be traversed before full plugin execution.
86    #[must_use]
87    pub(crate) fn discovery_hidden_dirs(&self, pkg: &PackageJson, root: &Path) -> Vec<String> {
88        self.inner.discovery_hidden_dirs(pkg, root)
89    }
90}
91
92impl Default for PluginRegistry {
93    fn default() -> Self {
94        Self::new(vec![])
95    }
96}
97
98#[cfg(test)]
99mod roster_tests {
100    /// The engine mirrored core's roster by hand and the copy drifted, omitting
101    /// `deno`. Delegation removes the copy, so there is nothing left to diverge;
102    /// this pins the name the drift lost and that the roster is really populated.
103    ///
104    /// The roster is read through `core_backend`, not from `fallow_core`
105    /// directly, because the boundary guard requires every crossing to go
106    /// through that adapter.
107    #[test]
108    fn roster_carries_every_registered_plugin() {
109        let names = super::registry::builtin_plugin_names();
110        assert!(
111            names.contains(&"deno"),
112            "deno is registered in core and must reach the roster"
113        );
114        assert!(
115            names.len() > 100,
116            "roster looks truncated: {} names",
117            names.len()
118        );
119    }
120}