Commit 88bacaa
refactor: extract shared primitives into vite_powershell crate (#368)
## Summary
- New `vite_powershell` crate owns the platform-shared primitives
previously inlined in `vite_task_plan::ps1_shim`: `POWERSHELL_PREFIX`,
`powershell_host()` (LazyLock-cached `pwsh.exe`/`powershell.exe`
lookup), and `find_ps1_sibling()` (case-insensitive `.cmd` → sibling
`.ps1` resolution).
- `vite_task_plan::ps1_shim` keeps its task-specific layers — workspace
+ `node_modules/.bin` scope check, cwd-relative arg conversion,
`Arc<AbsolutePath>` / `Arc<[Str]>` return types — and now imports the
primitives from `vite_powershell`.
- No behavior change. All existing snapshot/unit/integration tests pass.
## Why
vite-plus is adding `vite_command::ps1_shim` (see
voidzero-dev/vite-plus#1489) to fix the same Ctrl+C terminal-corruption
symptom for package-manager-routed commands (`vp dlx`, `vp add`, `vp
update`, etc.). Without this extraction it would have to copy the
constant, the host-discovery LazyLock, and the sibling-`.ps1` check.
With this extraction both task scripts (vite-task) and pm commands (vp)
compose the same primitives with their own scope rules.
The two callers diverge intentionally and don't share enough to merge
into one helper:
- vite-task's wrapper produces `(Arc<AbsolutePath>, Arc<[Str]>)` with
**cwd-relative** `.ps1` paths because the args become part of the task
graph's spawn fingerprint and must stay portable across machines.
- vite-plus's wrapper (in vp's `vite_command`) produces
`(AbsolutePathBuf, Vec<OsString>)` with **absolute** `.ps1` paths
because there's no cache fingerprint at spawn time.
## Test plan
- [x] `cargo test -p vite_powershell` — 5 new tests pass (sibling found,
case-insensitive `.CMD`, no-sibling, non-`.cmd`, no-extension)
- [x] `cargo test -p vite_task_plan` — 39 unit + 45 integration tests
pass; the existing rewrite snapshot tests are preserved
- [x] `cargo clippy -p vite_powershell -p vite_task_plan --all-targets`
— clean
- [x] Companion vp PR to switch `vite_command::ps1_shim` to depend on
`vite_powershell` once this lands and a new vite-task SHA is pinned
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Mostly a dependency extraction/refactor with tests; behavior should
remain the same aside from potential edge-case differences in
`.cmd`/`.ps1` detection on Windows.
>
> **Overview**
> Extracts the Windows `.cmd`→`.ps1` PowerShell-shim primitives into a
new `vite_powershell` crate, including the `POWERSHELL_PREFIX` args,
cached `pwsh.exe`/`powershell.exe` host discovery, and sibling-`.ps1`
lookup.
>
> Updates `vite_task_plan::ps1_shim` to depend on and call these shared
helpers while keeping its workspace/`node_modules/.bin` scoping and
cwd-relative argument rewrite logic, and adds unit tests for the new
crate. Workspace `Cargo.toml`/`Cargo.lock` are updated to include the
new crate and dependency.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1e2b791. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: branchseer <3612422+branchseer@users.noreply.github.com>1 parent bf0753e commit 88bacaa
6 files changed
Lines changed: 215 additions & 58 deletions
File tree
- crates
- vite_powershell
- src
- vite_task_plan
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
0 commit comments