vx_tool_node/
plugin.rs

1//! Node.js plugin implementation
2
3use crate::tool::{NodeTool, NpmTool, NpxTool};
4use vx_plugin::{VxPackageManager, VxPlugin, VxTool};
5
6/// Node.js plugin that manages Node.js-related tools
7#[derive(Debug)]
8pub struct NodePlugin;
9
10impl NodePlugin {
11    pub fn new() -> Self {
12        Self
13    }
14}
15
16#[async_trait::async_trait]
17impl VxPlugin for NodePlugin {
18    fn name(&self) -> &str {
19        "node"
20    }
21
22    fn description(&self) -> &str {
23        "Node.js JavaScript runtime and package management tools"
24    }
25
26    fn version(&self) -> &str {
27        "1.0.0"
28    }
29
30    fn tools(&self) -> Vec<Box<dyn VxTool>> {
31        vec![
32            Box::new(NodeTool::new()),
33            Box::new(NpmTool::new()),
34            Box::new(NpxTool::new()),
35        ]
36    }
37
38    fn package_managers(&self) -> Vec<Box<dyn VxPackageManager>> {
39        vec![]
40    }
41
42    fn supports_tool(&self, tool_name: &str) -> bool {
43        matches!(tool_name, "node" | "npm" | "npx")
44    }
45}
46
47impl Default for NodePlugin {
48    fn default() -> Self {
49        Self::new()
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_node_plugin() {
59        let plugin = NodePlugin;
60
61        assert_eq!(plugin.name(), "node");
62        assert_eq!(
63            plugin.description(),
64            "Node.js JavaScript runtime and package management tools"
65        );
66        assert!(plugin.supports_tool("node"));
67        assert!(plugin.supports_tool("npm"));
68        assert!(plugin.supports_tool("npx"));
69        assert!(!plugin.supports_tool("python"));
70
71        let tools = plugin.tools();
72        assert_eq!(tools.len(), 3); // node, npm, npx
73
74        let tool_names: Vec<&str> = tools.iter().map(|t| t.name()).collect();
75        assert!(tool_names.contains(&"node"));
76        assert!(tool_names.contains(&"npm"));
77        assert!(tool_names.contains(&"npx"));
78    }
79}