Skip to content

Commit

Permalink
feat: add volta packages (#883)
Browse files Browse the repository at this point in the history
add print_info when no packages found

apply review feedback
  • Loading branch information
diogonr authored Aug 1, 2024
1 parent 55f672e commit a1f3c86
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub enum Step {
Vagrant,
Vcpkg,
Vim,
VoltaPackages,
Vscode,
Waydroid,
Winget,
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ fn run() -> Result<()> {
runner.execute(Step::Node, "npm", || node::run_npm_upgrade(&ctx))?;
runner.execute(Step::Yarn, "yarn", || node::run_yarn_upgrade(&ctx))?;
runner.execute(Step::Pnpm, "pnpm", || node::run_pnpm_upgrade(&ctx))?;
runner.execute(Step::VoltaPackages, "volta packages", || {
node::run_volta_packages_upgrade(&ctx)
})?;
runner.execute(Step::Containers, "Containers", || containers::run_containers(&ctx))?;
runner.execute(Step::Deno, "deno", || node::deno_upgrade(&ctx))?;
runner.execute(Step::Composer, "composer", || generic::run_composer_update(&ctx))?;
Expand Down
47 changes: 46 additions & 1 deletion src/steps/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use semver::Version;
use tracing::debug;

use crate::command::CommandExt;
use crate::terminal::print_separator;
use crate::terminal::{print_info, print_separator};
use crate::utils::{require, PathExt};
use crate::{error::SkipStep, execution_context::ExecutionContext};

Expand Down Expand Up @@ -276,3 +276,48 @@ pub fn deno_upgrade(ctx: &ExecutionContext) -> Result<()> {
print_separator("Deno");
ctx.run_type().execute(&deno).arg("upgrade").status_checked()
}

/// There is no `volta upgrade` command, so we need to upgrade each package
pub fn run_volta_packages_upgrade(ctx: &ExecutionContext) -> Result<()> {
let volta = require("volta")?;

print_separator("Volta");

if ctx.run_type().dry() {
print_info("Updating Volta packages...");
return Ok(());
}

let list_output = ctx
.run_type()
.execute(&volta)
.args(["list", "--format=plain"])
.output_checked_utf8()?
.stdout;

let installed_packages: Vec<&str> = list_output
.lines()
.filter_map(|line| {
// format is 'kind package@version ...'
let mut parts = line.split_whitespace();
parts.next();
let package_part = parts.next()?;
let version_index = package_part.rfind('@').unwrap_or(package_part.len());
Some(package_part[..version_index].trim())
})
.collect();

if installed_packages.is_empty() {
print_info("No packages installed with Volta");
return Ok(());
}

for package in installed_packages.iter() {
ctx.run_type()
.execute(&volta)
.args(["install", package])
.status_checked()?;
}

Ok(())
}

0 comments on commit a1f3c86

Please sign in to comment.