changepacks_core/
package.rs1use std::{collections::HashSet, path::Path};
2
3use crate::{Language, update_type::UpdateType};
4use anyhow::Result;
5use async_trait::async_trait;
6
7#[async_trait]
12pub trait Package: std::fmt::Debug + Send + Sync {
13 fn name(&self) -> Option<&str>;
14 fn version(&self) -> Option<&str>;
15 fn path(&self) -> &Path;
16 fn relative_path(&self) -> &Path;
17 async fn update_version(&mut self, update_type: UpdateType) -> Result<()>;
20 fn is_changed(&self) -> bool;
21 fn language(&self) -> Language;
22
23 fn dependencies(&self) -> &HashSet<String>;
24 fn add_dependency(&mut self, dependency: &str);
25
26 fn set_changed(&mut self, changed: bool);
27
28 fn set_name(&mut self, name: String);
31
32 fn default_publish_command(&self) -> String;
34
35 fn default_dry_run_publish_command(&self) -> Option<String>;
43
44 crate::impl_shared_project_defaults!();
45
46 fn inherits_workspace_version(&self) -> bool {
48 false
49 }
50
51 fn workspace_root_path(&self) -> Option<&Path> {
53 None
54 }
55
56 crate::impl_publish_flows!(crate::publish::PACKAGE_DIR_NOT_FOUND);
57
58 crate::impl_publish_command_resolvers!();
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64 use crate::test_support::MockPackage;
65
66 crate::test_support::shared_project_default_tests!(
71 mock: MockPackage,
72 trait_name: Package,
73 kind: "package",
74 dir_not_found: "Package directory not found",
75 publishable_test: test_package_is_publishable_by_default,
76 );
77
78 #[test]
79 fn test_inherits_workspace_version_default() {
80 let package =
81 MockPackage::with_paths(Some("test"), "/project/package.json", "package.json");
82 assert!(!package.inherits_workspace_version());
83 }
84
85 #[test]
86 fn test_workspace_root_path_default() {
87 let package =
88 MockPackage::with_paths(Some("test"), "/project/package.json", "package.json");
89 assert!(package.workspace_root_path().is_none());
90 }
91}