From 4c4a6035efbd4b84f464a6e0eccaa033c37b2900 Mon Sep 17 00:00:00 2001 From: stefdev49 Date: Wed, 28 Dec 2022 09:16:25 +0000 Subject: [PATCH] add support for .npmrc noproxy --- index.js | 2 +- test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index df75004..348bfdc 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ function getProxyForUrl(url) { * @private */ function shouldProxy(hostname, port) { - var NO_PROXY = + var NO_PROXY = getEnv('npm_config_noproxy') || (getEnv('npm_config_no_proxy') || getEnv('no_proxy')).toLowerCase(); if (!NO_PROXY) { return true; // Always proxy if NO_PROXY is not set. diff --git a/test.js b/test.js index abf6542..b725dee 100644 --- a/test.js +++ b/test.js @@ -479,5 +479,18 @@ describe('getProxyForUrl', function() { testProxyUrl(env, '', 'http://example'); testProxyUrl(env, 'http://proxy', 'http://otherwebsite'); }); + // eslint-disable-next-line max-len + describe('npm_config_noproxy should take precedence over npm_config_no_proxy and NO_PROXY', function() { + var env = {}; + env.HTTP_PROXY = 'http://proxy'; + env.NO_PROXY = 'otherwebsite'; + // eslint-disable-next-line camelcase + env.npm_config_no_proxy = 'anotherexample'; + // eslint-disable-next-line camelcase + env.npm_config_noproxy = 'example'; + testProxyUrl(env, '', 'http://example'); + testProxyUrl(env, 'http://proxy', 'http://anotherexample'); + testProxyUrl(env, 'http://proxy', 'http://otherwebsite'); + }); }); });