Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ steps = [
{ argv = ["vp", "add", "test-vite-plus-install", "--filter=*", "--filter=@vite-plus-test/utils"], snapshot = false },
{ argv = ["vp", "add", "test-vite-plus-package-optional", "-O", "--filter=*", "--filter=@vite-plus-test/utils"], snapshot = false, continue-on-failure = true },
{ argv = ["vpt", "print-file", "package.json", "packages/app/package.json", "packages/admin/package.json", "packages/utils/package.json"], comment = "prepare packages", continue-on-failure = true },
{ argv = ["vp", "remove", "testnpm2", "-r", "--workspace-root", "--filter=app", "--filter=@vite-plus-test/utils"], comment = "recursive remove affects only app and utils" },
{ argv = ["vpt", "print-file", "package.json", "packages/app/package.json", "packages/admin/package.json", "packages/utils/package.json"], comment = "root and admin keep testnpm2" },
{ argv = ["vp", "remove", "testnpm2", "-r"], comment = "should remove package from all workspaces and root" },
{ argv = ["vpt", "print-file", "package.json", "packages/app/package.json", "packages/admin/package.json", "packages/utils/package.json"], continue-on-failure = true },
{ argv = ["vp", "remove", "-O", "test-vite-plus-package-optional", "-r"], comment = "should remove optional package from all workspaces" },
{ argv = ["vpt", "print-file", "package.json", "packages/app/package.json", "packages/admin/package.json", "packages/utils/package.json"], continue-on-failure = true },
{ argv = ["vp", "remove", "test-vite-plus-install", "--filter=app"], comment = "should remove package by filter=app" },
{ argv = ["vp", "remove", "test-vite-plus-install", "-r", "--filter=app"], comment = "recursive remove affects only app" },
{ argv = ["vpt", "print-file", "package.json", "packages/app/package.json", "packages/admin/package.json", "packages/utils/package.json"], continue-on-failure = true },
{ argv = ["vp", "add", "test-vite-plus-install", "--filter=app"], comment = "should remove package by filter=*" },
["vp", "remove", "test-vite-plus-install", "--filter=*"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,92 @@ prepare packages
}
```

## `vp remove testnpm2 -r --workspace-root --filter=app --filter=@vite-plus-test/utils`

recursive remove affects only app and utils

```
warn: yarn does not support --workspace-root.
[app]: Process started
[app]: ➤ YN0000: · Yarn <version>
[app]: ➤ YN0000: ┌ Resolution step
[app]: ➤ YN0000: └ Completed
[app]: ➤ YN0000: ┌ Fetch step
[app]: ➤ YN0000: └ Completed
[app]: ➤ YN0000: ┌ Link step
[app]: ➤ YN0000: └ Completed
[app]: ➤ YN0000: · Done in <duration> <duration>
[app]: Process exited (exit code 0), completed in <duration> <duration>

[@vite-plus-test/utils]: Process started
[@vite-plus-test/utils]: ➤ YN0000: · Yarn <version>
[@vite-plus-test/utils]: ➤ YN0000: ┌ Resolution step
[@vite-plus-test/utils]: ➤ YN0000: └ Completed
[@vite-plus-test/utils]: ➤ YN0000: ┌ Fetch step
[@vite-plus-test/utils]: ➤ YN0000: └ Completed
[@vite-plus-test/utils]: ➤ YN0000: ┌ Link step
[@vite-plus-test/utils]: ➤ YN0000: └ Completed
[@vite-plus-test/utils]: ➤ YN0000: · Done in <duration> <duration>
[@vite-plus-test/utils]: Process exited (exit code 0), completed in <duration> <duration>

Done in <duration> <duration>
```

## `vpt print-file package.json packages/app/package.json packages/admin/package.json packages/utils/package.json`

root and admin keep testnpm2

```
{
"name": "command-remove-yarn4-with-workspace",
"version": "1.0.0",
"workspaces": [
"packages/*"
],
"packageManager": "yarn@4.10.3",
"devDependencies": {
"testnpm2": "^1.0.1"
},
"dependencies": {
"test-vite-plus-install": "^1.0.0"
},
"optionalDependencies": {
"test-vite-plus-package-optional": "^1.0.0"
}
}
{
"name": "app",
"dependencies": {
"test-vite-plus-install": "^1.0.0"
},
"optionalDependencies": {
"test-vite-plus-package-optional": "^1.0.0"
}
}
{
"name": "admin",
"devDependencies": {
"testnpm2": "^1.0.1"
},
"dependencies": {
"test-vite-plus-install": "^1.0.0"
},
"optionalDependencies": {
"test-vite-plus-package-optional": "^1.0.0"
}
}
{
"name": "@vite-plus-test/utils",
"version": "1.0.0",
"dependencies": {
"test-vite-plus-install": "^1.0.0"
},
"optionalDependencies": {
"test-vite-plus-package-optional": "^1.0.0"
}
}
```

## `vp remove testnpm2 -r`

should remove package from all workspaces and root
Expand Down Expand Up @@ -189,9 +275,9 @@ should remove optional package from all workspaces
}
```

## `vp remove test-vite-plus-install --filter=app`
## `vp remove test-vite-plus-install -r --filter=app`

should remove package by filter=app
recursive remove affects only app

```
[app]: Process started
Expand Down
44 changes: 37 additions & 7 deletions crates/vp_pm_cli/src/resolution/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct RemoveArgs {
pub(crate) filter: Vec<String>,

/// Remove from workspace root
#[arg(short = 'w', long, not_supported(bun))]
#[arg(short = 'w', long, not_supported(yarn, bun))]
pub(crate) workspace_root: bool,

/// Remove recursively from all workspace packages
Expand Down Expand Up @@ -111,13 +111,11 @@ impl Resolve<RemoveArgs> for Yarn {
);
}

if !args.recursive {
cmd.arg("workspaces").arg("foreach").arg("--all");
cmd.repeated("--include", args.filter.iter());
}
cmd.arg("workspaces").arg("foreach").arg("--all");
cmd.repeated("--include", args.filter.iter());
Comment thread
jong-kyung marked this conversation as resolved.
}
cmd.arg("remove")
.arg_if("--all", args.recursive)
.arg_if("--all", args.recursive && args.filter.is_empty())
Comment thread
jong-kyung marked this conversation as resolved.
.extend(args.pass_through_args.iter())
.extend(args.packages.iter());
cmd.into()
Expand Down Expand Up @@ -232,6 +230,25 @@ mod tests {
assert_eq!(command.args, vec!["remove", "lodash"]);
}

#[test]
fn yarn_drops_unsupported_workspace_root() {
for version in ["1.22.22", "4.0.0"] {
let mut options = remove_args(&["lodash"]);
options.workspace_root = true;
let resolution = resolve(&yarn(version), options);
let command = expect_run(resolution.outcome);

assert_eq!(command.program, "yarn");
assert_eq!(command.args, vec!["remove", "lodash"]);
let messages = resolution
.diagnostics
.iter()
.map(|entry| entry.message.as_str())
.collect::<Vec<_>>();
assert_eq!(messages, vec!["yarn does not support --workspace-root."]);
}
}

#[test]
fn test_yarn_classic_rejects_filtered_remove() {
for filters in
Expand Down Expand Up @@ -505,7 +522,20 @@ mod tests {
let command = expect_run(resolution.outcome);

assert_eq!(command.program, "yarn");
assert_eq!(command.args, vec!["remove", "--all", "lodash"]);
assert_eq!(
command.args,
vec![
"workspaces",
"foreach",
"--all",
"--include",
"app",
"--include",
"web",
"remove",
"lodash"
]
);
}

#[test]
Expand Down
Loading