Skip to content

Commit 4068290

Browse files
committed
refactor(env): use symlink instead of wrapper script for bin/vp on Unix
Change bin/vp back to a symlink pointing to ../current/bin/vp (the correct path after the directory structure consolidation).
1 parent 9abf488 commit 4068290

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

  • crates/vite_global_cli/src/commands/env

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Setup command implementation for creating bin directory and shims.
22
//!
33
//! Creates the following structure:
4-
//! - ~/.vite-plus/bin/ - Contains vp wrapper and node/npm/npx shims
4+
//! - ~/.vite-plus/bin/ - Contains vp symlink and node/npm/npx shims
55
//! - ~/.vite-plus/current/ - Symlink to the installed version directory
66
//!
7-
//! On Unix: bin/vp is a wrapper script that calls current/bin/vp
8-
//! On Windows: bin/vp.cmd is a wrapper script that calls current\bin\vp.exe
7+
//! On Unix: bin/vp is a symlink to ../current/bin/vp
8+
//! On Windows: bin/vp.cmd is a wrapper script that calls ..\current\bin\vp.exe
99
1010
use std::process::ExitStatus;
1111

@@ -71,33 +71,25 @@ pub async fn execute(refresh: bool) -> Result<ExitStatus, Error> {
7171
Ok(ExitStatus::default())
7272
}
7373

74-
/// Create wrapper script in bin/ that calls current/bin/vp.
74+
/// Create symlink in bin/ that points to current/bin/vp.
7575
async fn setup_vp_wrapper(bin_dir: &vite_path::AbsolutePath, refresh: bool) -> Result<(), Error> {
7676
#[cfg(unix)]
7777
{
7878
let bin_vp = bin_dir.join("vp");
7979

80-
// Create wrapper script bin/vp that calls current/bin/vp
81-
let should_create_wrapper = refresh
80+
// Create symlink bin/vp -> ../current/bin/vp
81+
let should_create_symlink = refresh
8282
|| !tokio::fs::try_exists(&bin_vp).await.unwrap_or(false)
83-
|| is_symlink(&bin_vp).await; // Replace symlink with wrapper
83+
|| !is_symlink(&bin_vp).await; // Replace non-symlink with symlink
8484

85-
if should_create_wrapper {
86-
// Remove existing if present (could be old symlink or file)
85+
if should_create_symlink {
86+
// Remove existing if present (could be old wrapper script or file)
8787
if tokio::fs::try_exists(&bin_vp).await.unwrap_or(false) {
8888
tokio::fs::remove_file(&bin_vp).await?;
8989
}
90-
// Create wrapper shell script with absolute path
91-
let wrapper_content = r#"#!/bin/sh
92-
VITE_PLUS_HOME="$(cd "$(dirname "$0")/.." && pwd)"
93-
exec "$VITE_PLUS_HOME/current/bin/vp" "$@"
94-
"#;
95-
tokio::fs::write(&bin_vp, wrapper_content).await?;
96-
// Make executable
97-
use std::os::unix::fs::PermissionsExt;
98-
let perms = std::fs::Permissions::from_mode(0o755);
99-
tokio::fs::set_permissions(&bin_vp, perms).await?;
100-
tracing::debug!("Created wrapper script {:?}", bin_vp);
90+
// Create relative symlink
91+
tokio::fs::symlink("../current/bin/vp", &bin_vp).await?;
92+
tracing::debug!("Created symlink {:?} -> ../current/bin/vp", bin_vp);
10193
}
10294
}
10395

0 commit comments

Comments
 (0)