Skip to content

Commit

Permalink
refactor: skip Bun update if it is not installed via official script
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Aug 26, 2024
1 parent ca8558d commit 9a743e0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 9a743e0

Please sign in to comment.