Skip to content

Commit

Permalink
feat: support npm config proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Dec 12, 2023
1 parent 96d1db3 commit d5f5908
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ pub mod proxy_manager {
use crate::NPM;

pub fn enable_proxy(proxy_url: &str) {
// git config
git_config("http.proxy", Some(proxy_url));

// npm config
npm_config("proxy", Some(proxy_url));

// export some proxy environment variables
std::env::set_var("all_proxy", proxy_url);
std::env::set_var("http_proxy", proxy_url);
std::env::set_var("https_proxy", proxy_url);
Expand All @@ -27,7 +23,6 @@ pub mod proxy_manager {

pub fn disable_proxy() {
git_config("http.proxy", None);

npm_config("proxy", None);

std::env::remove_var("all_proxy");
Expand All @@ -51,7 +46,7 @@ pub mod proxy_manager {
fn npm_config(key: &str, value: Option<&str>) {
let mut args = vec!["config"];
match value {
Some(v) => args.extend_from_slice(&[key, v]),
Some(v) => args.extend_from_slice(&["set", key, v]),
None => args.extend_from_slice(&["delete", key]),
}
Command::new(NPM).args(&args).output().ok();
Expand Down

0 comments on commit d5f5908

Please sign in to comment.