fix(cli): keep env use session-scoped on Windows#1577
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
80bfa93 to
ab868d5
Compare
|
好的,请验证好功能,我的要求是跟fnm软件类似,在不同的PowerShell Tab窗口使用类似fnm use切换node版本,不影响其他的PowerShell Tab窗口里面的node版本,目前使用下来vp env use切换node版本其他PowerShell里面执行vp env list也跟着同步发送切换变化了,我希望跟fnm类似 |
dc48fe8 to
9072db7
Compare
|
这个功能大概什么时候发布正式? |
9072db7 to
c64eeda
Compare
|
@IHEL A new version will be released every Tuesday. |
…letes
- Remove the --use-no-cd flag: it was wired into the parser but never read
by print_shell_env, and env.ps1 has no directory-change hooks for it to
opt out of. Update the recommended PowerShell setup line everywhere
(cli help, print_path_instructions, wrapper-required warning, docs/RFC).
- Drop the duplicated config::delete_session_version() calls in use.rs:
the unconditional delete at the top of each branch already covers all
three sub-cases (eval-wrapper, session-file-allowed, Windows non-CI),
so the inner delete inside `else if can_use_session_file()` was a
guaranteed-NotFound syscall.
- Flatten three `else { if ... }` blocks into `else if ...` (silent-if-
unchanged, tail write block, unset branch) and drop the redundant
"Removed file-based ... if it existed" line that was superseded by the
existing "Reverted to file-based Node.js version resolution" message.
- Sync the `vp env --help` example for the PowerShell setup into
help.rs's hand-maintained mirror; the clap after_help in cli.rs is not
rendered for `vp env --help` (the unified renderer wins), so the
PowerShell example was previously invisible to users.
The full `vp env --shell powershell | Out-String | Invoke-Expression` line is much longer than the other Setup examples, so leaving it inline broke the `#`-comment column alignment. Move it into its own `PowerShell (add to $PROFILE):` subsection (matches the existing Setup/Manage/Inspect/Execute structure) and drop the inline comment. Update the cli-helper-message snapshot to match.
Promote the previous top-level `--shell <shell>` flag on `vp env` into a
proper `Profile { shell: Option<EnvShell> }` subcommand so the new
capability fits the existing noun-verb subcommand pattern (current,
print, default, on, off, setup, doctor, which, pin, unpin, list, ...)
instead of being the only top-level flag on the command. The recommended
PowerShell setup invocation becomes:
vp env profile --shell powershell | Out-String | Invoke-Expression
Side-effect-free implementation:
- Lift the four shell env-file templates (POSIX/Fish/Nushell/PowerShell)
and the cmd.exe wrapper to module-scope constants in setup.rs.
- Add `setup::render_env_content(shell, vite_plus_home) -> String` as a
pure helper that performs the placeholder substitution for one shell.
- `create_env_files` now loops over the four shells calling the helper,
removing the inline-template duplication.
- `vp env profile` builds the content directly via `render_env_content`
and prints it. No call to `create_env_files`, no read-back of a file
we just wrote — important because the recommended `$PROFILE` line runs
on every PowerShell startup, which previously rewrote all five env
files (~20KB of disk churn) on every shell launch.
Also reverts `create_env_files` from `pub(crate)` back to private now
that the profile path no longer needs it, syncs help.rs subcommand list
+ Examples block, and updates the use.rs warning text plus docs/RFC.
- Add `EnvShell::env_file_name() -> &'static str` so the per-shell file name (env, env.fish, env.nu, env.ps1) lives on the enum instead of the inline tuple in `create_env_files`. Removes one source of drift; the rest of the codebase (notably `commands/shell.rs::ALL_SHELL_PROFILES`) can migrate to this method in a follow-up. - Disambiguate the `print` subcommand description against the new `profile` subcommand in both clap (`vp env print --help`) and the unified renderer (`vp env --help`). The contrast between "current session" and "$PROFILE-style setup" is now explicit.
|
@cursor review |
`vp env setup` already writes `~/.vite-plus/env.ps1` to disk, so the new `vp env profile` subcommand was redundant: the recommended PowerShell `$PROFILE` line just needs to dot-source the existing file. That avoids spawning a `vp` subprocess on every shell startup, removes the chicken-and-egg requirement that `vp` already be on PATH, and matches the pattern used by rustup/mise/fnm/sdkman. . "$env:USERPROFILE\.vite-plus\env.ps1" Changes: - Remove `EnvSubcommands::Profile` and the `print_profile` handler. - Remove the `clap::ValueEnum` derive and `#[value(alias = ...)]` attributes on `EnvShell` — it is no longer exposed via the CLI, only used internally by `setup::create_env_files` / `render_env_content`. - Restore the original `print` subcommand description (the `profile` cross-reference is no longer needed). - Update the recommended PowerShell setup line everywhere (cli help examples, help.rs Examples block, print_path_instructions, the `print_windows_eval_wrapper_required` warning, docs/guide/env.md, rfcs/env-command.md). - Make `render_env_content` private again now that the `vp env profile` caller is gone; keep the lift-templates-to-consts cleanup since `create_env_files` still benefits.
…ed hint - Relocate `EnvShell` enum and `env_file_name()` from `cli.rs` into `commands/env/setup.rs`. With `vp env profile` gone, the type is no longer CLI surface — only `create_env_files` and `render_env_content` use it. Drop `pub`/`pub(crate)` since callers are now same-module. - Reword `print_windows_eval_wrapper_required`: the previous "Then start a new PowerShell session" hint left the user's current PowerShell still wrapper-less. Updated to "dot-source it now (or open a new PowerShell session)" so the user can re-run `vp env use` without restarting the shell.
The PowerShell setup line is documented in docs/guide/env.md and the RFC; including it inline in the `vp env --help` Examples is noise for the common (POSIX) audience and was the only Windows-specific example in the block.
|
@cursor review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e38069500
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
✅ 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 6e38069. Configure here.
`vp env setup` writes `env.ps1` under the actual `vite_plus_home`, but the printed PowerShell `$PROFILE` instruction was hardcoded to `$env:USERPROFILE\.vite-plus\env.ps1`. With a custom `VP_HOME` the file written and the file the user is told to dot-source did not match, so subsequent `vp env use` calls kept hitting the wrapper-required error even though setup succeeded. Use the same `home_path` already computed for the POSIX/Fish/Nushell instructions.
Summary
vp env useon Windows from writing the shared.session-node-versionfallbackvp env doctorVerification
.session-node-versionNote
Medium Risk
Changes Windows behavior for
vp env useby preventing session-file fallback outside CI and returning non-zero when the PowerShell eval wrapper isn’t loaded, which could break existing Windows workflows/scripts.Overview
Ensures
vp env usestays session-scoped on Windows by disallowing.session-node-versionwrites in interactive Windows shells unless the PowerShell wrapper is active (CI is still allowed to use the session file fallback).vp env use --unsetnow always deletes any existing session file, and new Windows-only tests cover direct invocation, CI fallback, and wrapper cleanup behavior.Refactors env setup script generation in
env setupinto per-shell templates with a shared renderer, and updates PowerShell setup guidance/output (including docs and RFC) to explicitly dot-source"$env:USERPROFILE\.vite-plus\env.ps1".Reviewed by Cursor Bugbot for commit 6e38069. Configure here.