Skip to content

Commit db67e9b

Browse files
zerone0xclaude
andauthored
fix(cli): strip trailing slash from registry URL in install script (#916)
## Summary Fixes the Windows install script failing with a 404 error when the user's npm registry URL has a trailing slash (e.g., `https://registry.npmmirror.com/`). The trailing slash causes a double slash in the constructed URL (`https://registry.npmmirror.com//pnpm/latest`), which returns 404. The install shell scripts (`install.ps1` and `install.sh`) already strip trailing slashes for their own URL construction, but the Rust binary (`vp.exe`) reads `NPM_CONFIG_REGISTRY` directly from the environment without stripping. **Fix:** Strip trailing slashes from the registry URL in two places: - `EnvConfig::from_env()` — where the registry URL is read from environment variables (affects all commands) - `resolve_version()` — where a registry override parameter is used for upgrades Fixes #904 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 90a23d5 commit db67e9b

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

crates/vite_global_cli/src/commands/upgrade/registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub async fn resolve_version(
4545
registry_override: Option<&str>,
4646
) -> Result<ResolvedVersion, Error> {
4747
let default_registry = npm_registry();
48-
let registry = registry_override.unwrap_or(&default_registry);
48+
let registry_raw = registry_override.unwrap_or(&default_registry);
49+
let registry = registry_raw.trim_end_matches('/');
4950
let client = HttpClient::new();
5051

5152
// Step 1: Fetch main package metadata to resolve version

crates/vite_shared/src/env_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ impl EnvConfig {
133133
vite_plus_home: std::env::var(env_vars::VITE_PLUS_HOME).ok().map(PathBuf::from),
134134
npm_registry: std::env::var(env_vars::NPM_CONFIG_REGISTRY)
135135
.or_else(|_| std::env::var(env_vars::NPM_CONFIG_REGISTRY_UPPER))
136-
.unwrap_or_else(|_| "https://registry.npmjs.org".into()),
136+
.unwrap_or_else(|_| "https://registry.npmjs.org".into())
137+
.trim_end_matches('/')
138+
.to_string(),
137139
node_dist_mirror: std::env::var(env_vars::VITE_NODE_DIST_MIRROR).ok(),
138140
is_ci: std::env::var("CI").is_ok(),
139141
bypass_shim: std::env::var(env_vars::VITE_PLUS_BYPASS).is_ok(),

0 commit comments

Comments
 (0)