Skip to content

Commit

Permalink
fix: The yarn and pnpm shims were added incorrectly when executin…
Browse files Browse the repository at this point in the history
…g the `corepack enable npm` command.

Signed-off-by: The1111mp <The1111mp@outlook.com>
  • Loading branch information
1111mp committed Dec 13, 2023
1 parent 5df64f6 commit 0e46a23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/run/corepack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn corepack_enable(args: &[OsString]) {
.map(|name| String::from(name.to_str().unwrap()))
.collect::<Vec<String>>();

if packages.is_empty() {
if packages.is_empty() && !args.contains(&OsString::from("npm")) {
packages.push(String::from("yarn"));
packages.push(String::from("pnpm"));
}
Expand All @@ -84,7 +84,7 @@ fn corepack_disable(args: &[OsString]) {
.map(|name| String::from(name.to_str().unwrap()))
.collect::<Vec<String>>();

if packages.is_empty() {
if packages.is_empty() && !args.contains(&OsString::from("npm")) {
packages.push(String::from("yarn"));
packages.push(String::from("pnpm"));
}
Expand Down
14 changes: 13 additions & 1 deletion src/run/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use super::{ExitStatus, OsStr, OsString};
use crate::{
command as CommandTool,
common::{link_package, unlink_package, ENV_PATH, NVMD_PATH, VERSION},
common::{link_package, unlink_package, ENV_PATH, INSTALLTION_PATH, NVMD_PATH, VERSION},
};

lazy_static! {
Expand All @@ -32,6 +32,18 @@ pub(super) fn command(exe: &OsStr, args: &[OsString]) -> Result<ExitStatus, Stri
return Err(String::from("command not found: ") + exe.to_str().unwrap());
}

let mut lib_path = INSTALLTION_PATH.clone();
lib_path.push(VERSION.clone());
if cfg!(unix) {
// unix
lib_path.push("bin");
}
lib_path.push(exe);

if !lib_path.exists() {
return Err(String::from("command not found: ") + exe.to_str().unwrap());
}

let is_global = args.contains(&SHORT_GLOBAL) || args.contains(&GLOBAL);
let is_global_uninstall = is_global && args.contains(&UNINSTALL);

Expand Down

0 comments on commit 0e46a23

Please sign in to comment.