feat(env): show message when switching version automatically#608
feat(env): show message when switching version automatically#608
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds automatic Node.js version switching when changing directories, improving the developer experience by eliminating the need to manually run vp env use when entering different projects.
Changes:
- Added
--silent-if-unchangedflag tovp env useto suppress output when the version is already active - Introduced
resolve_version_from_project()function to resolve versions from project files only, avoiding infinite recursion whenvp env useis called from cd hooks - Updated shell environment files (bash/zsh, fish, PowerShell) to automatically call
vp env use --silent-if-unchangedon directory changes - Improved message format from "Using Node.js v{version} (resolved from {source})" to "vp: Using Node.js v{version} (from {source})" for clarity and consistency
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/vite_global_cli/src/commands/env/use.rs | Updated to use resolve_version_from_project and improved status message format with "vp:" prefix |
| crates/vite_global_cli/src/commands/env/config.rs | Added new resolve_version_from_project function that skips session overrides, preventing infinite recursion |
| crates/vite_global_cli/src/commands/env/setup.rs | Added cd hooks for bash/zsh, fish, and PowerShell shells to auto-switch Node.js versions; includes comprehensive unit tests |
| packages/global/snap-tests/command-env-use/snap.txt | Updated to reflect new message format with "vp:" prefix |
| packages/global/snap-tests/command-env-use-silent-if-unchanged/* | New integration test suite verifying --silent-if-unchanged behavior across different scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f1fbb93 to
95c0fe7
Compare
95c0fe7 to
cc66aad
Compare
|
According to our current implementation logic, as long as the node command is executed it will run the correct version — so why do we still need to rely on |
I don't consider this as a functional feature but a dx improvement. I used fnm before it shows switched node version when entering project folder, gives you a clear hint it's working. I don't have a strong stand on this behavior, if we don't need it by design, it's ok to just close it. |
|
@hyf0 If the DX experience can be improved, then let's merge. |
| export VITE_PLUS_NODE_VERSION=20.18.0 | ||
|
|
||
| > VITE_PLUS_NODE_VERSION=22.0.0 vp env use --silent-if-unchanged --no-install # different version - should show message | ||
| export VITE_PLUS_NODE_VERSION=20.18.0 |
Let me do more investigation and ask for feedbacks |
Summary
Add shell cd hooks that auto-switch Node.js versions on directory change, similar to fnm/nvm.
What's new
~/.vite-plus/env*chpwd_functions), Bash (cdalias), Fish (--on-variable PWD), PowerShell (promptwrapper)resolve_versioncircular readvp env usewithout explicit version now callsresolve_version_from_project()which skipsVITE_PLUS_NODE_VERSIONenv var — previously the env var was read back as the "resolved" version, making--silent-if-unchangedalways matchUsing Node.js v{} (resolved from {})→vp: Using Node.js v{} (from {})Test plan
command-env-use-silent-if-unchanged— first call shows message, same version silent, different version triggers messagecommand-env-useupdated for new message format.node-versioncorrectly switches version