Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions crates/vite_global_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,13 @@ pub enum EnvSubcommands {
Print,

/// Set or show the global default Node.js version
#[command(after_long_help = "\
Examples:
vp env default # Show the current default
vp env default lts # Set the default")]
Default {
/// Version to set as default (e.g., "20.18.0", "lts", "latest")
/// If not provided, shows the current default
/// Version to set as default (e.g., "20.18.0", "lts", "latest").
/// If omitted, prints the current default.
version: Option<String>,
},

Expand Down Expand Up @@ -330,9 +334,14 @@ pub enum EnvSubcommands {
},

/// Pin a Node.js version in the current directory (creates .node-version)
#[command(after_long_help = "\
Examples:
vp env pin lts # Pin to latest LTS
vp env pin --unpin # Remove .node-version
vp env pin \"^20.0.0\" --force # Overwrite existing pin")]
Pin {
/// Version to pin (e.g., "20.18.0", "lts", "latest", "^20.0.0")
/// If not provided, shows the current pinned version
/// Version to pin (e.g., "20.18.0", "lts", "latest", "^20.0.0").
/// If omitted, prints the currently pinned version.
version: Option<String>,

/// Remove the .node-version file from current directory
Expand Down Expand Up @@ -383,11 +392,17 @@ pub enum EnvSubcommands {
},

/// Execute a command with a specific Node.js version
#[command(visible_alias = "run")]
#[command(
visible_alias = "run",
after_long_help = "\
Examples:
vp env exec --node lts npm install # Pin version for this invocation
vp env exec node -v # Shim mode: version auto-resolved"
)]
Exec {
/// Node.js version to use (e.g., "20.18.0", "lts", "^20.0.0")
/// If not provided and command is node/npm/npx or a global package binary,
/// version is resolved automatically (same as shim behavior)
/// Node.js version to use (e.g., "20.18.0", "lts", "^20.0.0").
/// If omitted and command is node/npm/npx or a global package binary,
/// version is resolved automatically (same as shim behavior).
#[arg(long)]
node: Option<String>,

Expand Down Expand Up @@ -417,9 +432,13 @@ pub enum EnvSubcommands {
},

/// Use a specific Node.js version for this shell session
#[command(after_long_help = "\
Examples:
vp env use lts # Override session with latest LTS
vp env use --unset # Clear the session override")]
Use {
/// Version to use (e.g., "20", "20.18.0", "lts", "latest")
/// If not provided, reads from .node-version or package.json
/// Version to use (e.g., "20", "20.18.0", "lts", "latest").
/// If omitted, reads from .node-version or package.json.
version: Option<String>,

/// Remove session override (revert to file-based resolution)
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/snap-tests-global/command-env-use/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ Usage: vp env use [OPTIONS] [VERSION]
Use a specific Node.js version for this shell session

Arguments:
[VERSION] Version to use (e.g., "20", "20.18.0", "lts", "latest") If not provided, reads from .node-version or package.json
[VERSION] Version to use (e.g., "20", "20.18.0", "lts", "latest"). If omitted, reads from .node-version or package.json

Options:
--unset Remove session override (revert to file-based resolution)
--no-install Skip auto-installation if version not present
--silent-if-unchanged Suppress output if version is already active
-h, --help Print help

Examples:
vp env use lts # Override session with latest LTS
vp env use --unset # Clear the session override

Documentation: https://viteplus.dev/guide/env


Expand Down
Loading