Skip to content

Commit

Permalink
fix: Match more rules for the command of npm install -g.
Browse files Browse the repository at this point in the history
Signed-off-by: The1111mp <[email protected]>
  • Loading branch information
1111mp committed Oct 26, 2023
1 parent 2471c47 commit 93b8b6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/run/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ pub(super) fn command(exe: &OsStr, args: &[OsString]) -> Result<ExitStatus, Stri
}

fn global_install_packages(args: &[OsString]) {
let re: Regex = Regex::new(r"@[0-9]|@latest").unwrap();
let re_str = "@[0-9]|@latest|@\"|@npm:";
let re: Regex = Regex::new(re_str).unwrap();
let packages = &args
.into_iter()
.filter(is_positional)
Expand All @@ -81,22 +82,24 @@ fn global_install_packages(args: &[OsString]) {
Some(mat) => {
let str = &package[0..(mat.start())];

return OsString::from(str);
OsString::from(str)
}
};

return OsString::from(new_package);
OsString::from(new_package)
})
.collect();

let npm_perfix = get_npm_perfix();

let package_bin_names = get_package_bin_names(&npm_perfix, packages);

record_installed_package(&package_bin_names);
if !package_bin_names.is_empty() {
record_installed_package(&package_bin_names);

for name in &package_bin_names {
link_package(name);
for name in &package_bin_names {
link_package(name);
}
}
}

Expand Down Expand Up @@ -210,28 +213,29 @@ fn collection_packages_name(args: &[OsString]) {
.filter(is_positional)
.map(|x| {
let package = String::from(x.to_str().unwrap());
// let mat = re.find(&package).unwrap();

let new_package = match re.find(&package) {
None => OsString::from(&package),
Some(mat) => {
let str = &package[0..(mat.start())];

return OsString::from(str);
OsString::from(str)
}
};

return OsString::from(new_package);
OsString::from(new_package)
})
.collect();

let npm_perfix = get_npm_perfix();

let package_bin_names = get_package_bin_names(&npm_perfix, packages);

let mut global_names = UNINSTALL_PACKAGES_NAME.lock().unwrap();
for name in package_bin_names {
global_names.push(name);
if !package_bin_names.is_empty() {
let mut global_names = UNINSTALL_PACKAGES_NAME.lock().unwrap();
for name in package_bin_names {
global_names.push(name);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/run/nvmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::common::{NVMD_PATH, VERSION};
#[command(name=env!("CARGO_PKG_NAME"), author=env!("CARGO_PKG_AUTHORS"), version=env!("CARGO_PKG_VERSION"), about="command tools for nvm-desktop", after_help="Please download new version of Node.js in nvm-desktop.", long_about = None)]
#[command(help_template = "\
{before-help}{name} ({version})
{author-with-newline}{about-with-newline}
{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
Expand Down

0 comments on commit 93b8b6d

Please sign in to comment.