fix-pnpm (#3)
Authored-by: Ved Kothavade <ved.Kothavade@lucera.com> Approved-by: Thomas Schönauer <t.schoenauer@hgs-wt.at>
This commit is contained in:
@@ -20,15 +20,11 @@ use crate::{error::SkipStep, execution_context::ExecutionContext};
|
|||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
struct NPM {
|
struct NPM {
|
||||||
command: PathBuf,
|
command: PathBuf,
|
||||||
pnpm: Option<PathBuf>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NPM {
|
impl NPM {
|
||||||
fn new(command: PathBuf) -> Self {
|
fn new(command: PathBuf) -> Self {
|
||||||
Self {
|
Self { command }
|
||||||
command,
|
|
||||||
pnpm: require("pnpm").ok(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@@ -56,17 +52,13 @@ impl NPM {
|
|||||||
fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> {
|
fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> {
|
||||||
print_separator("Node Package Manager");
|
print_separator("Node Package Manager");
|
||||||
let version = self.version()?;
|
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"]
|
["update", "-g"]
|
||||||
} else {
|
} else {
|
||||||
["update", "--location=global"]
|
["update", "--location=global"]
|
||||||
};
|
};
|
||||||
if use_sudo {
|
if use_sudo {
|
||||||
run_type
|
run_type.execute("sudo").args(args).check_run()?;
|
||||||
.execute("sudo")
|
|
||||||
.arg(self.pnpm.as_ref().unwrap_or(&self.command))
|
|
||||||
.args(args)
|
|
||||||
.check_run()?;
|
|
||||||
} else {
|
} else {
|
||||||
run_type.execute(&self.command).args(args).check_run()?;
|
run_type.execute(&self.command).args(args).check_run()?;
|
||||||
}
|
}
|
||||||
@@ -170,7 +162,7 @@ fn should_use_sudo_yarn(yarn: &Yarn, ctx: &ExecutionContext) -> Result<bool> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_npm_upgrade(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")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user