diff --git a/crates/vite_js_runtime/src/providers/node.rs b/crates/vite_js_runtime/src/providers/node.rs index 5b1f2e764d..19edaa8884 100644 --- a/crates/vite_js_runtime/src/providers/node.rs +++ b/crates/vite_js_runtime/src/providers/node.rs @@ -558,7 +558,7 @@ fn calculate_expires_at(max_age: Option) -> u64 { /// Get the Node.js distribution base URL /// -/// Returns the value of `VITE_NODE_DIST_MIRROR` environment variable if set, +/// Returns the value of `VP_NODE_DIST_MIRROR` environment variable if set, /// otherwise returns the default `https://nodejs.org/dist`. fn get_dist_url() -> Str { vite_shared::EnvConfig::get().node_dist_mirror.map_or_else( diff --git a/crates/vite_shared/src/env_config.rs b/crates/vite_shared/src/env_config.rs index fcfa047c2f..95b198e1b2 100644 --- a/crates/vite_shared/src/env_config.rs +++ b/crates/vite_shared/src/env_config.rs @@ -65,7 +65,7 @@ pub struct EnvConfig { /// Node.js distribution mirror URL. /// - /// Env: `VITE_NODE_DIST_MIRROR` + /// Env: `VP_NODE_DIST_MIRROR` pub node_dist_mirror: Option, /// Whether running in a CI environment. @@ -136,7 +136,7 @@ impl EnvConfig { .unwrap_or_else(|_| "https://registry.npmjs.org".into()) .trim_end_matches('/') .to_string(), - node_dist_mirror: std::env::var(env_vars::VITE_NODE_DIST_MIRROR).ok(), + node_dist_mirror: std::env::var(env_vars::VP_NODE_DIST_MIRROR).ok(), is_ci: std::env::var("CI").is_ok(), bypass_shim: std::env::var(env_vars::VP_BYPASS).is_ok(), debug_shim: std::env::var(env_vars::VP_DEBUG_SHIM).is_ok(), diff --git a/crates/vite_shared/src/env_vars.rs b/crates/vite_shared/src/env_vars.rs index 821e384314..6a3ecd6b49 100644 --- a/crates/vite_shared/src/env_vars.rs +++ b/crates/vite_shared/src/env_vars.rs @@ -25,7 +25,7 @@ pub const NPM_CONFIG_REGISTRY: &str = "npm_config_registry"; pub const NPM_CONFIG_REGISTRY_UPPER: &str = "NPM_CONFIG_REGISTRY"; /// Node.js distribution mirror URL for downloads. -pub const VITE_NODE_DIST_MIRROR: &str = "VITE_NODE_DIST_MIRROR"; +pub const VP_NODE_DIST_MIRROR: &str = "VP_NODE_DIST_MIRROR"; /// Override Node.js version (takes highest priority in version resolution). pub const VP_NODE_VERSION: &str = "VP_NODE_VERSION"; diff --git a/docs/guide/env.md b/docs/guide/env.md index a7b22e3420..4807b0d84c 100644 --- a/docs/guide/env.md +++ b/docs/guide/env.md @@ -82,3 +82,18 @@ vp env list-remote --lts # List only LTS versions vp env exec --node lts npm i # Execute npm with latest LTS vp env exec node -v # Use shim mode with automatic version resolution ``` + +## Custom Node.js Mirror + +By default, Vite+ downloads Node.js from `https://nodejs.org/dist`. If you're behind a corporate proxy or need to use an internal mirror (e.g., Artifactory), set the `VP_NODE_DIST_MIRROR` environment variable: + +```bash +# Install a specific version from your custom mirror +VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist vp env install 22 + +# Set the global default version using a custom mirror +VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist vp env default lts + +# Set it permanently in your shell profile (.bashrc, .zshrc, etc.) +echo 'export VP_NODE_DIST_MIRROR=https://my-mirror.example.com/nodejs/dist' >> ~/.zshrc +``` diff --git a/rfcs/js-runtime.md b/rfcs/js-runtime.md index 81c6183e18..6bf64ea0db 100644 --- a/rfcs/js-runtime.md +++ b/rfcs/js-runtime.md @@ -434,10 +434,10 @@ https://nodejs.org/dist/v{version}/node-v{version}-{platform}.{ext} ### Custom Mirror Support -The distribution URL can be overridden using the `VITE_NODE_DIST_MIRROR` environment variable. This is useful for corporate environments or regions where nodejs.org might be slow or blocked. +The distribution URL can be overridden using the `VP_NODE_DIST_MIRROR` environment variable. This is useful for corporate environments or regions where nodejs.org might be slow or blocked. ```bash -VITE_NODE_DIST_MIRROR=https://example.com/mirrors/node vp build +VP_NODE_DIST_MIRROR=https://example.com/mirrors/node vp build ``` The mirror URL should have the same directory structure as the official distribution. Trailing slashes are automatically trimmed. @@ -680,7 +680,7 @@ pub enum Error { 4. ✅ Handles concurrent downloads safely 5. ✅ Returns version and binary path 6. ✅ Comprehensive test coverage -7. ✅ Custom mirrors via `VITE_NODE_DIST_MIRROR` environment variable +7. ✅ Custom mirrors via `VP_NODE_DIST_MIRROR` environment variable 8. ✅ Support `devEngines.runtime` from package.json 9. ✅ Support semver ranges (^, ~, etc.) with version resolution 10. ✅ Version index caching with 1-hour TTL