Skip to content

Commit

Permalink
fix: deno upgrade for different executable versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnryr committed Oct 28, 2024
1 parent 144f0fb commit 5e89ef3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,46 @@ impl Deno {

let version = ctx.config().deno_version();
if let Some(version) = version {
args.push(version);
let bin_version = self.version()?;

if bin_version >= Version::new(2, 0, 0) {
args.push(version);
} else if bin_version >= Version::new(1, 6, 0) {
match version {
"stable" => {}
"rc" => {
return Err(SkipStep("Deno v1.x cannot be upgraded to a release candidate".to_string()).into());
}
"canary" => args.push("--canary"),
_ => {
if Version::parse(version).is_err() {
return Err(SkipStep("Invalid Deno version".to_string()).into());
}

args.push("--version");
args.push(version);
}
}
} else if bin_version >= Version::new(1, 0, 0) {
match version {
"stable" | "rc" | "canary" => {
// Prior to v1.6.0, `deno upgrade` is not able fetch the latest tag version.
return Err(SkipStep("Deno v1.x cannot be upgraded to a named channel".to_string()).into());
}
_ => {
if Version::parse(version).is_err() {
return Err(SkipStep("Invalid Deno version".to_string()).into());
}

args.push("--version");
args.push(version);
}
}
} else {
// v0.x cannot be upgraded with `deno upgrade` to v1.x or v2.x
// nor can be upgraded to a specific version.
return Err(SkipStep("Unsupported Deno version".to_string()).into());
}
}

ctx.run_type()
Expand All @@ -208,6 +247,14 @@ impl Deno {
.status_checked()?;
Ok(())
}

fn version(&self) -> Result<Version> {
let version_str = Command::new(&self.command)
.args(["-V"])
.output_checked_utf8()
.map(|s| s.stdout.trim().to_owned().split_off(5));
Version::parse(&version_str?).map_err(|err| err.into())
}
}

#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 5e89ef3

Please sign in to comment.