vx_dependency/
lib.rs

1//! # vx-dependency
2//!
3//! Advanced dependency resolution and management system for vx tools.
4//!
5//! This crate provides intelligent dependency resolution with support for:
6//! - Multi-layer dependency chains
7//! - Circular dependency detection
8//! - Version constraint resolution
9//! - Parallel dependency installation
10//! - Caching and performance optimization
11//!
12//! ## Example
13//!
14//! ```rust,no_run
15//! use vx_dependency::{DependencyResolver, ToolSpec, DependencySpec};
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
19//!     let mut resolver = DependencyResolver::new();
20//!     
21//!     // Register tools and their dependencies
22//!     resolver.register_tool(ToolSpec {
23//!         name: "yarn".to_string(),
24//!         dependencies: vec![
25//!             DependencySpec::required("node", ">=16.0.0")
26//!         ],
27//!         ..Default::default()
28//!     });
29//!     
30//!     // Resolve dependencies for yarn
31//!     let resolution = resolver.resolve("yarn").await?;
32//!     println!("Install order: {:?}", resolution.install_order);
33//!     
34//!     Ok(())
35//! }
36//! ```
37
38pub mod dependency;
39pub mod graph;
40pub mod resolver;
41pub mod types;
42pub mod version;
43
44// Re-export main types
45pub use graph::{
46    DependencyGraph, DependencyNode, GraphStats, NodeState, ResolutionResult, VersionConflict,
47};
48pub use resolver::{DependencyResolver, ResolutionOptions};
49pub use types::{DependencySpec, DependencyType, ToolSpec, VersionConstraint};
50pub use version::{Version, VersionMatcher, VersionRange};
51
52/// Result type for dependency operations
53pub type Result<T> = std::result::Result<T, Error>;
54
55/// Error types for dependency operations
56#[derive(thiserror::Error, Debug)]
57pub enum Error {
58    #[error("Tool '{tool}' not found")]
59    ToolNotFound { tool: String },
60
61    #[error("Circular dependency detected: {cycle:?}")]
62    CircularDependency { cycle: Vec<String> },
63
64    #[error("Version conflict for tool '{tool}': required {required}, found {found}")]
65    VersionConflict {
66        tool: String,
67        required: String,
68        found: String,
69    },
70
71    #[error("Dependency resolution failed: {message}")]
72    ResolutionFailed { message: String },
73
74    #[error("Invalid version constraint: {constraint}")]
75    InvalidVersionConstraint { constraint: String },
76
77    #[error("Tool '{tool}' has unresolvable dependencies: {dependencies:?}")]
78    UnresolvableDependencies {
79        tool: String,
80        dependencies: Vec<String>,
81    },
82
83    #[error("IO error: {0}")]
84    Io(#[from] std::io::Error),
85
86    #[error("Serialization error: {0}")]
87    Serialization(#[from] serde_json::Error),
88
89    #[error("Other error: {0}")]
90    Other(#[from] anyhow::Error),
91}
92
93/// Version information for the crate
94pub const VERSION: &str = env!("CARGO_PKG_VERSION");
95
96#[cfg(test)]
97mod tests {
98    use super::*;
99
100    #[test]
101    fn test_version_info() {
102        assert!(!VERSION.is_empty());
103    }
104}