Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: skip Bun update if it is not installed via official script #894

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}