fix(steps/node): Only run global upgrade on Yarn 1.x (#112)
This commit is contained in:
committed by
Thomas Schönauer
parent
9a19b547c6
commit
7a83f38ca8
@@ -93,6 +93,17 @@ impl Yarn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_global_subcmd(&self) -> bool {
|
||||||
|
// Get the version of Yarn. After Yarn 2.x (berry),
|
||||||
|
// “yarn global” has been replaced with “yarn dlx”.
|
||||||
|
//
|
||||||
|
// As “yarn dlx” don't need to “upgrade”, we
|
||||||
|
// ignore the whole task if Yarn is 2.x or above.
|
||||||
|
let version = Command::new(&self.command).args(["--version"]).check_output();
|
||||||
|
|
||||||
|
matches!(version, Ok(ver) if ver.starts_with('1') || ver.starts_with('0'))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn root(&self) -> Result<PathBuf> {
|
fn root(&self) -> Result<PathBuf> {
|
||||||
let args = ["global", "dir"];
|
let args = ["global", "dir"];
|
||||||
@@ -178,6 +189,11 @@ pub fn run_npm_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
pub fn run_yarn_upgrade(ctx: &ExecutionContext) -> Result<()> {
|
||||||
let yarn = require("yarn").map(Yarn::new)?;
|
let yarn = require("yarn").map(Yarn::new)?;
|
||||||
|
|
||||||
|
if !yarn.has_global_subcmd() {
|
||||||
|
debug!("Yarn is 2.x or above, skipping global upgrade");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
yarn.upgrade(ctx.run_type(), should_use_sudo_yarn(&yarn, ctx)?)
|
yarn.upgrade(ctx.run_type(), should_use_sudo_yarn(&yarn, ctx)?)
|
||||||
|
|||||||
Reference in New Issue
Block a user