sampo_core/
adapters.rs

1/// Ecosystem-specific adapters (Cargo, npm, etc.) for all package operations.
2pub mod cargo;
3
4use crate::errors::{Result, WorkspaceError};
5use crate::types::PackageInfo;
6use std::path::Path;
7
8/// Package ecosystem adapter (Cargo, npm, etc.).
9#[derive(Debug, Clone, Copy)]
10pub enum PackageAdapter {
11    Cargo,
12}
13
14impl PackageAdapter {
15    /// All registered adapters, checked in order during workspace discovery.
16    /// TODO: it's fine for now, but eventually we could using strum or enum-iterators here.
17    pub fn all() -> &'static [PackageAdapter] {
18        &[PackageAdapter::Cargo]
19    }
20
21    /// Check if this adapter can handle the given directory.
22    pub fn can_discover(&self, root: &Path) -> bool {
23        match self {
24            Self::Cargo => cargo::CargoAdapter.can_discover(root),
25        }
26    }
27
28    /// Discover all packages in the workspace.
29    pub fn discover(&self, root: &Path) -> std::result::Result<Vec<PackageInfo>, WorkspaceError> {
30        match self {
31            Self::Cargo => cargo::CargoAdapter.discover(root),
32        }
33    }
34
35    /// Get the path to the manifest file for a package directory.
36    pub fn manifest_path(&self, package_dir: &Path) -> std::path::PathBuf {
37        match self {
38            Self::Cargo => cargo::CargoAdapter.manifest_path(package_dir),
39        }
40    }
41
42    /// Check if a package is publishable to its primary registry.
43    pub fn is_publishable(&self, manifest_path: &Path) -> Result<bool> {
44        match self {
45            Self::Cargo => cargo::CargoAdapter.is_publishable(manifest_path),
46        }
47    }
48
49    /// Check if a specific version already exists on the registry.
50    pub fn version_exists(&self, package_name: &str, version: &str) -> Result<bool> {
51        match self {
52            Self::Cargo => cargo::CargoAdapter.version_exists(package_name, version),
53        }
54    }
55
56    /// Execute the publish command for a package.
57    pub fn publish(
58        &self,
59        manifest_path: &Path,
60        dry_run: bool,
61        extra_args: &[String],
62    ) -> Result<()> {
63        match self {
64            Self::Cargo => cargo::CargoAdapter.publish(manifest_path, dry_run, extra_args),
65        }
66    }
67
68    /// Regenerate the workspace lockfile after version updates.
69    pub fn regenerate_lockfile(&self, workspace_root: &Path) -> Result<()> {
70        match self {
71            Self::Cargo => cargo::CargoAdapter.regenerate_lockfile(workspace_root),
72        }
73    }
74}