-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathadd.rs
More file actions
72 lines (62 loc) · 1.87 KB
/
add.rs
File metadata and controls
72 lines (62 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::process::ExitStatus;
use vite_install::{
commands::add::{AddCommandOptions, SaveDependencyType},
package_manager::PackageManager,
};
use vite_path::AbsolutePathBuf;
use crate::Error;
/// Add command for adding packages to dependencies.
///
/// This command automatically detects the package manager and translates
/// the add command to the appropriate package manager-specific syntax.
pub struct AddCommand {
cwd: AbsolutePathBuf,
}
impl AddCommand {
pub fn new(cwd: AbsolutePathBuf) -> Self {
Self { cwd }
}
pub async fn execute(
self,
packages: &[String],
save_dependency_type: Option<SaveDependencyType>,
save_exact: bool,
save_catalog_name: Option<&str>,
filters: Option<&[String]>,
workspace_root: bool,
workspace_only: bool,
global: bool,
allow_build: Option<&str>,
pass_through_args: Option<&[String]>,
) -> Result<ExitStatus, Error> {
let add_command_options = AddCommandOptions {
packages,
save_dependency_type,
save_exact,
filters,
workspace_root,
workspace_only,
global,
save_catalog_name,
allow_build,
pass_through_args,
};
// Detect package manager
let package_manager = PackageManager::builder(&self.cwd).build().await?;
package_manager.run_add_command(&add_command_options, &self.cwd).await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add_command_new() {
let workspace_root = if cfg!(windows) {
AbsolutePathBuf::new("C:\\test".into()).unwrap()
} else {
AbsolutePathBuf::new("/test".into()).unwrap()
};
let cmd = AddCommand::new(workspace_root.clone());
assert_eq!(cmd.cwd, workspace_root);
}
}