Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 4a7de60

Browse files
author
Mark Nefedov
authored
npm/cli 8.11.0 deprecated -g flags (#949)
1 parent 717674e commit 4a7de60

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ tokio = { version = "1.5.0", features = ["process", "rt-multi-thread"] }
3434
futures = "0.3.14"
3535
regex = "1.5.3"
3636
sys-info = "0.9"
37+
semver = "1.0"
3738

3839
[target.'cfg(target_os = "macos")'.dependencies]
3940
notify-rust = "4.5.0"

src/steps/node.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use directories::BaseDirs;
1010
use log::debug;
1111
#[cfg(unix)]
1212
use nix::unistd::Uid;
13+
use semver::Version;
1314

1415
use crate::executor::{CommandExt, RunType};
1516
use crate::terminal::print_separator;
@@ -32,23 +33,42 @@ impl NPM {
3233

3334
#[cfg(target_os = "linux")]
3435
fn root(&self) -> Result<PathBuf> {
36+
let version = self.version()?;
37+
let args = if version < Version::new(8, 11, 0) {
38+
["root", "-g"]
39+
} else {
40+
["root", "--location=global"]
41+
};
3542
Command::new(&self.command)
36-
.args(&["root", "-g"])
43+
.args(args)
3744
.check_output()
3845
.map(|s| PathBuf::from(s.trim()))
3946
}
4047

48+
fn version(&self) -> Result<Version> {
49+
let version_str = Command::new(&self.command)
50+
.args(&["--version"])
51+
.check_output()
52+
.map(|s| s.trim().to_owned());
53+
Version::parse(&version_str?).map_err(|err| err.into())
54+
}
55+
4156
fn upgrade(&self, run_type: RunType, use_sudo: bool) -> Result<()> {
4257
print_separator("Node Package Manager");
43-
58+
let version = self.version()?;
59+
let args = if version < Version::new(8, 11, 0) || self.pnpm.is_some() {
60+
["update", "-g"]
61+
} else {
62+
["update", "--location=global"]
63+
};
4464
if use_sudo {
4565
run_type
4666
.execute("sudo")
4767
.arg(self.pnpm.as_ref().unwrap_or(&self.command))
48-
.args(&["update", "-g"])
68+
.args(args)
4969
.check_run()?;
5070
} else {
51-
run_type.execute(&self.command).args(&["update", "-g"]).check_run()?;
71+
run_type.execute(&self.command).args(args).check_run()?;
5272
}
5373

5474
Ok(())

0 commit comments

Comments
 (0)