Skip to main content

fallow_core/plugins/
federation_source.rs

1use std::path::PathBuf;
2
3use super::PathRule;
4
5/// What a Module Federation config declares, and where, for the trace output.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct FederationSource {
8    /// What the config names.
9    pub target: FederationSourceTarget,
10    /// The absolute path of the config file.
11    pub config_path: PathBuf,
12    /// The plugin that read the config, as it labels itself.
13    pub plugin: String,
14    /// The config key that names the target.
15    pub key: &'static str,
16}
17
18/// The thing a [`FederationSource`] names.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum FederationSourceTarget {
21    /// An `exposes` target, as the entry-point rule it became.
22    Exposed(PathRule),
23    /// A `remotes` alias.
24    Remote(String),
25}
26
27impl FederationSource {
28    #[must_use]
29    pub(super) fn prefixed(&self, ws_prefix: &str) -> Self {
30        let target = match &self.target {
31            FederationSourceTarget::Exposed(rule) => {
32                FederationSourceTarget::Exposed(rule.prefixed(ws_prefix))
33            }
34            FederationSourceTarget::Remote(alias) => FederationSourceTarget::Remote(alias.clone()),
35        };
36        Self {
37            target,
38            config_path: self.config_path.clone(),
39            plugin: self.plugin.clone(),
40            key: self.key,
41        }
42    }
43}