Skip to content

refactor: extract shared primitives into vite_powershell crate#368

Merged
fengmk2 merged 7 commits intomainfrom
shared-ps1-shim
Apr 30, 2026
Merged

refactor: extract shared primitives into vite_powershell crate#368
fengmk2 merged 7 commits intomainfrom
shared-ps1-shim

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Apr 29, 2026

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

  • cargo test -p vite_powershell — 5 new tests pass (sibling found, case-insensitive .CMD, no-sibling, non-.cmd, no-extension)
  • cargo test -p vite_task_plan — 39 unit + 45 integration tests pass; the existing rewrite snapshot tests are preserved
  • cargo clippy -p vite_powershell -p vite_task_plan --all-targets — clean
  • 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

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.

Reviewed by Cursor Bugbot for commit 1e2b791. Configure here.

Pull `POWERSHELL_PREFIX`, `powershell_host()`, and `find_ps1_sibling()`
out of `vite_task_plan::ps1_shim` and into a new `vite_powershell`
crate so vite-plus can reuse them for its package-manager command
spawn path.

`vite_task_plan::ps1_shim` keeps its workspace + `node_modules/.bin`
scope check and cwd-relative arg conversion; only the platform-shared
primitives moved.

Companion change in vite-plus: `vite_command::ps1_shim` (added in
voidzero-dev/vite-plus#1489 to fix Ctrl+C terminal corruption for pm
commands) will switch to `vite_powershell` once this lands.
@fengmk2 fengmk2 self-assigned this Apr 29, 2026
Restore the pre-extraction zero-clone path for vite_task_plan: caching
the host as Arc<AbsolutePath> means rewrite_with_host can do
Arc::clone(host) instead of allocating a fresh PathBuf+Arc on every
.cmd shim rewrite. Callers that need an owned AbsolutePathBuf
(e.g. vite-plus's vite_command::ps1_shim) call to_absolute_path_buf()
themselves.

Also drop the awkward `let Some(_) = parents.next() else { ... }` for
the discarded shim-filename component in is_in_workspace_node_modules_bin
in favor of a plain `parents.next();`.
fengmk2 added 2 commits April 29, 2026 20:04
Two CI failures from the previous commit:

1. `cargo shear` flagged `tracing` as unused in `vite_powershell` —
   the `tracing::debug!` call lives in callers (vite_task_plan and
   vite-plus's vite_command), not in the shared crate. Drop the dep.

2. Windows build flagged `use vite_path::AbsolutePathBuf` as unused
   under `#[cfg(any(windows, test))]`. Pre-extraction the production
   Windows path of `rewrite_with_host` and `find_ps1_sibling` named
   the type; after extraction only tests do. Tighten the gate to
   `#[cfg(test)]`.
Comment thread crates/vite_task_plan/src/ps1_shim.rs Outdated
@fengmk2
Copy link
Copy Markdown
Member Author

fengmk2 commented Apr 29, 2026

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1e2b791. Configure here.

…module

Per review on #368: instead of `#[cfg(test)] use vite_path::AbsolutePathBuf;`
at module level (and re-importing through `super::AbsolutePathBuf` in
the test module), import directly inside `mod tests` where it's used.
@fengmk2 fengmk2 marked this pull request as ready for review April 29, 2026 11:31
@fengmk2 fengmk2 requested a review from branchseer April 29, 2026 11:31
@fengmk2 fengmk2 changed the title refactor(ps1_shim): extract shared primitives into vite_powershell crate refactor: extract shared primitives into vite_powershell crate Apr 29, 2026
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 29, 2026
Switch `vite_command::ps1_shim` to depend on the new `vite_powershell`
crate (companion change in voidzero-dev/vite-task#368) for the
PowerShell host lookup, the fixed argument prefix, and the
sibling-`.ps1` discovery. This module now just composes those
primitives with vp's own conventions: absolute `.ps1` path in args
and `Vec<OsString>` return type to match the spawn API.

Bumps the vite-task git rev across all pinned crates to pick up the
extraction.
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 29, 2026
Picks up the test-only AbsolutePathBuf import move from
voidzero-dev/vite-task#368 review feedback.
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Switch `vite_command::ps1_shim` to depend on the new `vite_powershell`
crate (companion change in voidzero-dev/vite-task#368) for the
PowerShell host lookup, the fixed argument prefix, and the
sibling-`.ps1` discovery. This module now just composes those
primitives with vp's own conventions: absolute `.ps1` path in args
and `Vec<OsString>` return type to match the spawn API.

Bumps the vite-task git rev across all pinned crates to pick up the
extraction.
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Picks up the test-only AbsolutePathBuf import move from
voidzero-dev/vite-task#368 review feedback.
@fengmk2 fengmk2 merged commit 88bacaa into main Apr 30, 2026
12 checks passed
@fengmk2 fengmk2 deleted the shared-ps1-shim branch April 30, 2026 07:56
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Picks up the squash-merged voidzero-dev/vite-task#368 (the
`vite_powershell` crate extraction). Replaces the draft-branch SHA
`957278df` with the merged-to-main SHA across all 7 vite-task crate
pins (fspy, vite_glob, vite_path, vite_powershell, vite_str,
vite_task, vite_workspace).
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Switch `vite_command::ps1_shim` to depend on the new `vite_powershell`
crate (companion change in voidzero-dev/vite-task#368) for the
PowerShell host lookup, the fixed argument prefix, and the
sibling-`.ps1` discovery. This module now just composes those
primitives with vp's own conventions: absolute `.ps1` path in args
and `Vec<OsString>` return type to match the spawn API.

Bumps the vite-task git rev across all pinned crates to pick up the
extraction.
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Picks up the test-only AbsolutePathBuf import move from
voidzero-dev/vite-task#368 review feedback.
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Apr 30, 2026
Picks up the squash-merged voidzero-dev/vite-task#368 (the
`vite_powershell` crate extraction). Replaces the draft-branch SHA
`957278df` with the merged-to-main SHA across all 7 vite-task crate
pins (fspy, vite_glob, vite_path, vite_powershell, vite_str,
vite_task, vite_workspace).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants