|
1 | 1 | //! Setup command implementation for creating bin directory and shims. |
2 | 2 | //! |
3 | 3 | //! 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 |
5 | 5 | //! - ~/.vite-plus/current/ - Symlink to the installed version directory |
6 | 6 | //! |
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 |
9 | 9 |
|
10 | 10 | use std::process::ExitStatus; |
11 | 11 |
|
@@ -71,33 +71,25 @@ pub async fn execute(refresh: bool) -> Result<ExitStatus, Error> { |
71 | 71 | Ok(ExitStatus::default()) |
72 | 72 | } |
73 | 73 |
|
74 | | -/// Create wrapper script in bin/ that calls current/bin/vp. |
| 74 | +/// Create symlink in bin/ that points to current/bin/vp. |
75 | 75 | async fn setup_vp_wrapper(bin_dir: &vite_path::AbsolutePath, refresh: bool) -> Result<(), Error> { |
76 | 76 | #[cfg(unix)] |
77 | 77 | { |
78 | 78 | let bin_vp = bin_dir.join("vp"); |
79 | 79 |
|
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 |
82 | 82 | || !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 |
84 | 84 |
|
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) |
87 | 87 | if tokio::fs::try_exists(&bin_vp).await.unwrap_or(false) { |
88 | 88 | tokio::fs::remove_file(&bin_vp).await?; |
89 | 89 | } |
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); |
101 | 93 | } |
102 | 94 | } |
103 | 95 |
|
|
0 commit comments