Skip to content

Commit

Permalink
feat: allow version specification for deno
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnryr committed Oct 27, 2024
1 parent ea2f3e0 commit 342a53e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@
# use_sudo = true


[deno]
# Upgrade deno executable to the given version.
# version = stable


[vim]
# For `vim-plug`, execute `PlugUpdate!` instead of `PlugUpdate`
# force_plug_update = true
Expand Down
14 changes: 14 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ pub struct NPM {
use_sudo: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
#[allow(clippy::upper_case_acronyms)]
pub struct Deno {
version: Option<String>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
#[allow(clippy::upper_case_acronyms)]
Expand Down Expand Up @@ -491,6 +498,9 @@ pub struct ConfigFile {
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
yarn: Option<Yarn>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
deno: Option<Deno>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
vim: Option<Vim>,

Expand Down Expand Up @@ -1526,6 +1536,10 @@ impl Config {
.unwrap_or(false)
}

pub fn deno_version(&self) -> Option<&str> {
self.config_file.deno.as_ref().and_then(|deno| deno.version.as_deref())
}

#[cfg(target_os = "linux")]
pub fn firmware_upgrade(&self) -> bool {
self.config_file
Expand Down
32 changes: 29 additions & 3 deletions src/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,32 @@ impl Yarn {
}
}

struct Deno {
command: PathBuf,
}

impl Deno {
fn new(command: PathBuf) -> Self {
Self { command }
}

fn upgrade(&self, ctx: &ExecutionContext) -> Result<()> {
let mut args = vec![];

let version = ctx.config().deno_version();
if let Some(version) = version {
args.push(version);
}

ctx.run_type()
.execute(&self.command)
.arg("upgrade")
.args(args)
.status_checked()?;
Ok(())
}
}

#[cfg(target_os = "linux")]
fn should_use_sudo(npm: &NPM, ctx: &ExecutionContext) -> Result<bool> {
if npm.should_use_sudo()? {
Expand Down Expand Up @@ -266,16 +292,16 @@ pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> {
}

pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {
let deno = require("deno")?;
let deno = require("deno").map(Deno::new)?;
let deno_dir = HOME_DIR.join(".deno");

if !deno.canonicalize()?.is_descendant_of(&deno_dir) {
if !deno.command.canonicalize()?.is_descendant_of(&deno_dir) {
let skip_reason = SkipStep(t!("Deno installed outside of .deno directory").to_string());
return Err(skip_reason.into());
}

print_separator("Deno");
ctx.run_type().execute(&deno).arg("upgrade").status_checked()
deno.upgrade(ctx)
}

/// There is no `volta upgrade` command, so we need to upgrade each package
Expand Down

0 comments on commit 342a53e

Please sign in to comment.