Skip to content

Commit 97c7571

Browse files
authored
refactor(env)!: rename VITE_PLUS_* env vars to VP_* prefix (#1166)
## Summary Closes #1074 Rename all internal `VITE_PLUS_*` environment variables to `VP_*` prefix to avoid Vite's default `envPrefix: "VITE_"` from exposing them in bundled applications via `import.meta.env`. - Rename 25 env vars across Rust, TypeScript, shell scripts, CI workflows, and snap tests - Rename Rust constant identifiers and `get_vite_plus_home()` → `get_vp_home()` to match - Update all code comments and user-facing docs (`docs/guide/env.md`) - Env vars **not** renamed: `VITE_LOG`, `VITE_NODE_DIST_MIRROR`, `VITE_UPDATE_TASK_TYPES`, `VITE_GLOBAL_CLI_JS_SCRIPTS_DIR` — these use the `VITE_` prefix (not `VITE_PLUS_`) and are intentionally kept ### Prerequisite (merged) - vite-task: [voidzero-dev/vite-task#297](voidzero-dev/vite-task#297) — Add `VP_*` to `DEFAULT_UNTRACKED_ENV` so internal vars pass through to child processes without affecting cache keys
1 parent e3c79b9 commit 97c7571

88 files changed

Lines changed: 576 additions & 563 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ jobs:
277277
INSTALL_BASH="curl -fsSL https://vite.plus | bash"
278278
INSTALL_PS1="irm https://vite.plus/ps1 | iex"
279279
else
280-
INSTALL_BASH="curl -fsSL https://vite.plus | VITE_PLUS_VERSION=${{ env.VERSION }} bash"
281-
INSTALL_PS1="\\\$env:VITE_PLUS_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://vite.plus/ps1 | iex"
280+
INSTALL_BASH="curl -fsSL https://vite.plus | VP_VERSION=${{ env.VERSION }} bash"
281+
INSTALL_PS1="\\\$env:VP_VERSION=\\\"${{ env.VERSION }}\\\"; irm https://vite.plus/ps1 | iex"
282282
fi
283283
cat > ./RELEASE_BODY.md <<EOF
284284
## vite-plus v${{ env.VERSION }}

.github/workflows/test-standalone-install.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defaults:
1919
shell: bash
2020

2121
env:
22-
VITE_PLUS_VERSION: alpha
22+
VP_VERSION: alpha
2323

2424
jobs:
2525
test-install-sh:
@@ -166,7 +166,7 @@ jobs:
166166
run: |
167167
docker run --rm --platform linux/arm64 \
168168
-v "${{ github.workspace }}:/workspace" \
169-
-e VITE_PLUS_VERSION=alpha \
169+
-e VP_VERSION=alpha \
170170
ubuntu:20.04 bash -c "
171171
ls -al ~/
172172
apt-get update && apt-get install -y curl ca-certificates
@@ -225,7 +225,7 @@ jobs:
225225
run: |
226226
docker run --rm \
227227
-v "${{ github.workspace }}:/workspace" \
228-
-e VITE_PLUS_VERSION=alpha \
228+
-e VP_VERSION=alpha \
229229
-e CI=true \
230230
alpine:3.21 sh -c "
231231
# libstdc++: required by unofficial-builds Node.js musl binary
@@ -283,7 +283,7 @@ jobs:
283283
run: |
284284
docker run --rm --platform linux/arm64 \
285285
-v "${{ github.workspace }}:/workspace" \
286-
-e VITE_PLUS_VERSION=alpha \
286+
-e VP_VERSION=alpha \
287287
-e CI=true \
288288
alpine:3.21 sh -c "
289289
# libstdc++ is needed by unofficial-builds Node.js musl binary

Cargo.lock

Lines changed: 12 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_global_cli/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ pub enum EnvSubcommands {
751751
/// Enable system-first mode - shims prefer system Node.js, fallback to managed
752752
Off,
753753

754-
/// Create or update shims in VITE_PLUS_HOME/bin
754+
/// Create or update shims in VP_HOME/bin
755755
Setup {
756756
/// Force refresh shims even if they exist
757757
#[arg(long)]

crates/vite_global_cli/src/commands/env/bin_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use serde::{Deserialize, Serialize};
1111
use vite_path::AbsolutePathBuf;
1212

13-
use super::config::get_vite_plus_home;
13+
use super::config::get_vp_home;
1414
use crate::error::Error;
1515

1616
/// Source that installed a binary.
@@ -54,7 +54,7 @@ impl BinConfig {
5454

5555
/// Get the bins directory path (~/.vite-plus/bins/).
5656
pub fn bins_dir() -> Result<AbsolutePathBuf, Error> {
57-
Ok(get_vite_plus_home()?.join("bins"))
57+
Ok(get_vp_home()?.join("bins"))
5858
}
5959

6060
/// Get the path to a binary's config file.

crates/vite_global_cli/src/commands/env/config.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Configuration and version resolution for the env command.
22
//!
33
//! This module provides:
4-
//! - VITE_PLUS_HOME path resolution
4+
//! - VP_HOME path resolution
55
//! - Version resolution with priority order
66
//! - Config file management
77
@@ -27,7 +27,7 @@ pub enum ShimMode {
2727
SystemFirst,
2828
}
2929

30-
/// User configuration stored in VITE_PLUS_HOME/config.json
30+
/// User configuration stored in VP_HOME/config.json
3131
#[derive(Serialize, Deserialize, Default, Debug)]
3232
#[serde(rename_all = "camelCase")]
3333
pub struct Config {
@@ -60,26 +60,26 @@ pub struct VersionResolution {
6060
pub is_range: bool,
6161
}
6262

63-
/// Get the VITE_PLUS_HOME directory path.
63+
/// Get the VP_HOME directory path.
6464
///
65-
/// Uses `VITE_PLUS_HOME` environment variable if set, otherwise defaults to `~/.vite-plus`.
66-
pub fn get_vite_plus_home() -> Result<AbsolutePathBuf, Error> {
67-
Ok(vite_shared::get_vite_plus_home()?)
65+
/// Uses `VP_HOME` environment variable if set, otherwise defaults to `~/.vite-plus`.
66+
pub fn get_vp_home() -> Result<AbsolutePathBuf, Error> {
67+
Ok(vite_shared::get_vp_home()?)
6868
}
6969

7070
/// Get the bin directory path (~/.vite-plus/bin/).
7171
pub fn get_bin_dir() -> Result<AbsolutePathBuf, Error> {
72-
Ok(get_vite_plus_home()?.join("bin"))
72+
Ok(get_vp_home()?.join("bin"))
7373
}
7474

7575
/// Get the packages directory path (~/.vite-plus/packages/).
7676
pub fn get_packages_dir() -> Result<AbsolutePathBuf, Error> {
77-
Ok(get_vite_plus_home()?.join("packages"))
77+
Ok(get_vp_home()?.join("packages"))
7878
}
7979

8080
/// Get the tmp directory path for staging (~/.vite-plus/tmp/).
8181
pub fn get_tmp_dir() -> Result<AbsolutePathBuf, Error> {
82-
Ok(get_vite_plus_home()?.join("tmp"))
82+
Ok(get_vp_home()?.join("tmp"))
8383
}
8484

8585
/// Get the node_modules directory path for a package.
@@ -116,7 +116,7 @@ pub fn get_node_modules_dir(prefix: &AbsolutePath, package_name: &str) -> Absolu
116116

117117
/// Get the config file path.
118118
pub fn get_config_path() -> Result<AbsolutePathBuf, Error> {
119-
Ok(get_vite_plus_home()?.join(CONFIG_FILE))
119+
Ok(get_vp_home()?.join(CONFIG_FILE))
120120
}
121121

122122
/// Load configuration from disk.
@@ -135,7 +135,7 @@ pub async fn load_config() -> Result<Config, Error> {
135135
/// Save configuration to disk.
136136
pub async fn save_config(config: &Config) -> Result<(), Error> {
137137
let config_path = get_config_path()?;
138-
let vite_plus_home = get_vite_plus_home()?;
138+
let vite_plus_home = get_vp_home()?;
139139

140140
// Ensure directory exists
141141
tokio::fs::create_dir_all(&vite_plus_home).await?;
@@ -147,14 +147,14 @@ pub async fn save_config(config: &Config) -> Result<(), Error> {
147147

148148
/// Environment variable for per-shell session Node.js version override.
149149
/// Set by `vp env use` command.
150-
pub const VERSION_ENV_VAR: &str = vite_shared::env_vars::VITE_PLUS_NODE_VERSION;
150+
pub const VERSION_ENV_VAR: &str = vite_shared::env_vars::VP_NODE_VERSION;
151151

152152
/// Session version file name, written by `vp env use` so shims work without the shell eval wrapper.
153153
pub const SESSION_VERSION_FILE: &str = ".session-node-version";
154154

155155
/// Get the path to the session version file (~/.vite-plus/.session-node-version).
156156
pub fn get_session_version_path() -> Result<AbsolutePathBuf, Error> {
157-
Ok(get_vite_plus_home()?.join(SESSION_VERSION_FILE))
157+
Ok(get_vp_home()?.join(SESSION_VERSION_FILE))
158158
}
159159

160160
/// Read the session version file. Returns `None` if the file is missing or empty.
@@ -197,7 +197,7 @@ pub async fn delete_session_version() -> Result<(), Error> {
197197
/// Resolve Node.js version for a directory.
198198
///
199199
/// Resolution order:
200-
/// 0. `VITE_PLUS_NODE_VERSION` env var (session override from `vp env use`)
200+
/// 0. `VP_NODE_VERSION` env var (session override from `vp env use`)
201201
/// 1. `.session-node-version` file (session override written by `vp env use` for shell-wrapper-less environments)
202202
/// 2. `.node-version` file in current or parent directories
203203
/// 3. `package.json#engines.node` in current or parent directories
@@ -824,7 +824,7 @@ mod tests {
824824

825825
let resolution = resolve_version(&temp_path).await.unwrap();
826826

827-
// VITE_PLUS_NODE_VERSION should take priority over .node-version
827+
// VP_NODE_VERSION should take priority over .node-version
828828
assert_eq!(resolution.version, "22.0.0");
829829
assert_eq!(resolution.source, VERSION_ENV_VAR);
830830
assert!(resolution.source_path.is_none());

crates/vite_global_cli/src/commands/env/current.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ pub async fn execute(cwd: AbsolutePathBuf, json: bool) -> Result<ExitStatus, Err
4747
let resolution = resolve_version(&cwd).await?;
4848

4949
// Get the home directory for this version
50-
let home_dir = vite_shared::get_vite_plus_home()?
51-
.join("js_runtime")
52-
.join("node")
53-
.join(&resolution.version);
50+
let home_dir =
51+
vite_shared::get_vp_home()?.join("js_runtime").join("node").join(&resolution.version);
5452

5553
#[cfg(windows)]
5654
let (node_path, npm_path, npx_path) =

0 commit comments

Comments
 (0)