Commit 70a9b1a
committed
fix(pm-cli): honor -g and reject -g --dry-run on the local CLI
Two local-CLI safety bugs on the new shared PM dispatcher (flagged by
the codex adversarial review on PR #1495):
1. `vp install -g <pkg>` was downgraded into a project add. The shared
`Install` arm dropped `global` and the `install <packages>` →
`add` alias hardcoded `AddCommandOptions.global = false`, so the
command silently ran `pnpm add <pkg>` (project) instead of
`pnpm add -g <pkg>` (global). Worse, `run_add` always called
`ensure_package_json`, so invoking `vp install -g foo` from an
empty directory created a fresh `package.json` and added the
package as a project dependency.
Pass `global` through from `Install` to `AddCommandOptions`, and in
`run_add` skip `ensure_package_json` when `options.global` is
true, falling back to npm-default PM detection so we still have a
binary to dispatch to in an empty directory. Same fix mirrored on
`run_remove` so `vp remove -g <pkg>` works in an empty dir too.
2. `vp remove -g --dry-run <pkg>` could perform a real uninstall.
The dispatcher bound `dry_run: _` and never forwarded it; the
underlying `RemoveCommandOptions` has no preview field.
Reject the combination in the dispatcher with a clear user message
pointing the user at the globally-installed `vp` CLI. The global
CLI's `run_package_manager_command` intercepts `Remove { global:
true }` before reaching this path, so it keeps using its
vite-plus-managed `managed_uninstall` flow with `dry_run` honored;
the new error only fires on the local CLI.
Verified end-to-end on the local CLI in an empty tmp dir:
- `vp install -g testnpm2` installs globally, no package.json created
- `vp remove -g testnpm2` removes globally, exit 0
- `vp remove -g --dry-run testnpm2` exits 1 with the new message and
does not touch the global store
Snap-test deltas: only the local `command-remove-pnpm10` fixture
regenerates to capture the new error message; the global fixture is
unchanged because the managed-uninstall path still handles `--dry-run`.1 parent 97b89f2 commit 70a9b1a
3 files changed
Lines changed: 31 additions & 14 deletions
File tree
- crates/vite_pm_cli/src
- packages/cli/snap-tests/command-remove-pnpm10
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
148 | 159 | | |
149 | 160 | | |
150 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
72 | 84 | | |
73 | 85 | | |
74 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 100 | + | |
| 101 | + | |
108 | 102 | | |
109 | 103 | | |
110 | 104 | | |
| |||
0 commit comments