Skip to content

Commit e2374ce

Browse files
committed
refactor(setup): move create_env_files from vite_installer to vite_setup
This function follows the same pattern as refresh_shims (spawn vp with different args) and belongs in the shared library alongside it.
1 parent a02e336 commit e2374ce

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

crates/vite_installer/src/main.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async fn do_install(
207207
print_warn(&format!("Node.js manager setup failed (non-fatal): {e}"));
208208
}
209209
} else {
210-
if let Err(e) = create_env_files(install_dir).await {
210+
if let Err(e) = install::create_env_files(install_dir).await {
211211
print_warn(&format!("Env file creation failed (non-fatal): {e}"));
212212
}
213213
}
@@ -353,23 +353,6 @@ async fn download_with_progress(
353353
Ok(data)
354354
}
355355

356-
async fn create_env_files(
357-
install_dir: &vite_path::AbsolutePath,
358-
) -> Result<(), Box<dyn std::error::Error>> {
359-
let vp_binary = install_dir.join("current").join("bin").join(VP_BINARY_NAME);
360-
361-
if !tokio::fs::try_exists(&vp_binary).await.unwrap_or(false) {
362-
return Ok(());
363-
}
364-
365-
tokio::process::Command::new(vp_binary.as_path())
366-
.args(["env", "setup", "--env-only"])
367-
.output()
368-
.await?;
369-
370-
Ok(())
371-
}
372-
373356
fn resolve_install_dir(opts: &cli::Options) -> Result<AbsolutePathBuf, Box<dyn std::error::Error>> {
374357
if let Some(ref dir) = opts.install_dir {
375358
let path = std::path::PathBuf::from(dir);

crates/vite_setup/src/install.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,26 @@ pub async fn refresh_shims(install_dir: &AbsolutePath) -> Result<(), Error> {
319319
Ok(())
320320
}
321321

322+
/// Create shell env files by running `vp env setup --env-only`.
323+
///
324+
/// Used when the Node.js manager is disabled — ensures env files exist
325+
/// even without a full shim refresh.
326+
pub async fn create_env_files(install_dir: &AbsolutePath) -> Result<(), Error> {
327+
let vp_binary =
328+
install_dir.join("current").join("bin").join(if cfg!(windows) { "vp.exe" } else { "vp" });
329+
330+
if !tokio::fs::try_exists(&vp_binary).await.unwrap_or(false) {
331+
return Ok(());
332+
}
333+
334+
tokio::process::Command::new(vp_binary.as_path())
335+
.args(["env", "setup", "--env-only"])
336+
.output()
337+
.await?;
338+
339+
Ok(())
340+
}
341+
322342
/// Clean up old version directories, keeping at most `max_keep` versions.
323343
///
324344
/// Sorts by creation time (newest first, matching install.sh behavior) and removes

0 commit comments

Comments
 (0)