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