use serde::{Deserialize, Serialize};
use sublime_standard_tools::config::{ConfigResult, Configurable};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct DependencyConfig {
pub propagation_bump: String,
pub propagate_dependencies: bool,
pub propagate_dev_dependencies: bool,
pub propagate_peer_dependencies: bool,
pub max_depth: usize,
pub fail_on_circular: bool,
pub skip_workspace_protocol: bool,
pub skip_file_protocol: bool,
pub skip_link_protocol: bool,
pub skip_portal_protocol: bool,
}
impl Default for DependencyConfig {
fn default() -> Self {
Self {
propagation_bump: "patch".to_string(),
propagate_dependencies: true,
propagate_dev_dependencies: false,
propagate_peer_dependencies: true,
max_depth: 10,
fail_on_circular: true,
skip_workspace_protocol: true,
skip_file_protocol: true,
skip_link_protocol: true,
skip_portal_protocol: true,
}
}
}
impl Configurable for DependencyConfig {
fn validate(&self) -> ConfigResult<()> {
match self.propagation_bump.as_str() {
"major" | "minor" | "patch" | "none" => {}
_ => {
return Err(sublime_standard_tools::config::ConfigError::ValidationError {
message: format!(
"dependency.propagation_bump: Invalid bump type '{}'. Must be one of: major, minor, patch, none",
self.propagation_bump
),
});
}
}
if !self.propagate_dependencies
&& !self.propagate_dev_dependencies
&& !self.propagate_peer_dependencies
{
return Err(sublime_standard_tools::config::ConfigError::ValidationError {
message: "dependency: At least one dependency type must be enabled for propagation"
.to_string(),
});
}
Ok(())
}
fn merge_with(&mut self, other: Self) -> ConfigResult<()> {
self.propagation_bump = other.propagation_bump;
self.propagate_dependencies = other.propagate_dependencies;
self.propagate_dev_dependencies = other.propagate_dev_dependencies;
self.propagate_peer_dependencies = other.propagate_peer_dependencies;
self.max_depth = other.max_depth;
self.fail_on_circular = other.fail_on_circular;
self.skip_workspace_protocol = other.skip_workspace_protocol;
self.skip_file_protocol = other.skip_file_protocol;
self.skip_link_protocol = other.skip_link_protocol;
self.skip_portal_protocol = other.skip_portal_protocol;
Ok(())
}
}