From 27349b1571b0765ac428c8e428afec636c531553 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:23:51 +0000 Subject: [PATCH] fix-pnpm (#3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Ved Kothavade Approved-by: Thomas Schönauer --- src/steps/node.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/steps/node.rs b/src/steps/node.rs index c27b4b45..91837673 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -20,15 +20,11 @@ use crate::{error::SkipStep, execution_context::ExecutionContext}; #[allow(clippy::upper_case_acronyms)] struct NPM { command: PathBuf, - pnpm: Option, } impl NPM { fn new(command: PathBuf) -> Self { - Self { - command, - pnpm: require("pnpm").ok(), - } + Self { command } } #[cfg(target_os = "linux")] @@ -56,17 +52,13 @@ impl NPM { fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> { print_separator("Node Package Manager"); let version = self.version()?; - let args = if version < Version::new(8, 11, 0) || self.pnpm.is_some() { + let args = if version < Version::new(8, 11, 0) { ["update", "-g"] } else { ["update", "--location=global"] }; if use_sudo { - run_type - .execute("sudo") - .arg(self.pnpm.as_ref().unwrap_or(&self.command)) - .args(args) - .check_run()?; + run_type.execute("sudo").args(args).check_run()?; } else { run_type.execute(&self.command).args(args).check_run()?; } @@ -170,7 +162,7 @@ fn should_use_sudo_yarn(yarn: &Yarn, ctx: &ExecutionContext) -> Result { } pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> { - let npm = require("npm").map(NPM::new)?; + let npm = require("pnpm").or_else(|_| require("npm")).map(NPM::new)?; #[cfg(target_os = "linux")] {