From 9a743e01c3168d75f1b618caf4baac26a67356e3 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Mon, 26 Aug 2024 22:46:15 +0800 Subject: [PATCH] refactor: skip Bun update if it is not installed via official script --- src/steps/generic.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 152c721c..860de45f 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1056,7 +1056,23 @@ pub fn run_zvm(ctx: &ExecutionContext) -> Result<()> { pub fn run_bun(ctx: &ExecutionContext) -> Result<()> { let bun = require("bun")?; - print_separator("Bun"); + // From the official install script (both install.sh and install.ps1), Bun uses + // the path set in this variable as the install root, and its defaults to + // `$HOME/.bun` + // + // UNIX: https://bun.sh/install.sh + // Windows:https://bun.sh/install.ps1 + let bun_install_env = env::var("BUN_INSTALL") + .map(PathBuf::from) + .unwrap_or(HOME_DIR.join(".bun")); + + // If `bun` is a descendant of `bun_install_env`, then Bun is installed + // through the official script + if bun.is_descendant_of(&bun_install_env) { + print_separator("Bun"); - ctx.run_type().execute(bun).arg("upgrade").status_checked() + ctx.run_type().execute(bun).arg("upgrade").status_checked() + } else { + Err(SkipStep("Bun is not installed through the official script, skip the update".into()).into()) + } }