-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathremove.rs
More file actions
66 lines (57 loc) · 1.74 KB
/
remove.rs
File metadata and controls
66 lines (57 loc) · 1.74 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
use std::process::ExitStatus;
use vite_install::{commands::remove::RemoveCommandOptions, package_manager::PackageManager};
use vite_path::AbsolutePathBuf;
use crate::Error;
/// Remove command for removing packages from dependencies.
///
/// This command automatically detects the package manager and translates
/// the remove command to the appropriate package manager-specific syntax.
pub struct RemoveCommand {
cwd: AbsolutePathBuf,
}
impl RemoveCommand {
pub fn new(cwd: AbsolutePathBuf) -> Self {
Self { cwd }
}
pub async fn execute(
self,
packages: &[String],
save_dev: bool,
save_optional: bool,
save_prod: bool,
filters: Option<&[String]>,
workspace_root: bool,
recursive: bool,
global: bool,
pass_through_args: Option<&[String]>,
) -> Result<ExitStatus, Error> {
// Detect package manager
let package_manager = PackageManager::builder(&self.cwd).build().await?;
let remove_command_options = RemoveCommandOptions {
packages,
filters,
workspace_root,
recursive,
global,
save_dev,
save_optional,
save_prod,
pass_through_args,
};
package_manager.run_remove_command(&remove_command_options, &self.cwd).await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_remove_command_new() {
let workspace_root = if cfg!(windows) {
AbsolutePathBuf::new("C:\\test".into()).unwrap()
} else {
AbsolutePathBuf::new("/test".into()).unwrap()
};
let cmd = RemoveCommand::new(workspace_root.clone());
assert_eq!(cmd.cwd, workspace_root);
}
}