From 3b417055cf07c4ef8e4c5063f00d3c24b5f5cbd2 Mon Sep 17 00:00:00 2001 From: zhaoxuxu Date: Fri, 18 Sep 2020 18:21:07 +0800 Subject: [PATCH] add proxy PR-URL: https://github.com/npm/cli/pull/1859 Credit: @badeggg Close: #1859 Reviewed-by: @isaacs EDIT: changed flatOptions.noproxy to flatOptions.noProxy, since make-fetch-happen reads it from the camel-cased property. --- lib/utils/flat-options.js | 8 +++++++- tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js | 2 ++ test/lib/utils/flat-options.js | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/flat-options.js b/lib/utils/flat-options.js index 54ba22d6c8ffb..721bbbde76651 100644 --- a/lib/utils/flat-options.js +++ b/lib/utils/flat-options.js @@ -209,7 +209,13 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({ ...getScopesAndAuths(npm), // npm fund exclusive option to select an item from a funding list - which: npm.config.get('which') + which: npm.config.get('which'), + + // socks proxy can be configured in https-proxy or proxy field + // note that the various (HTTPS_|HTTP_|)PROXY environs will be + // respected if this is not set. + proxy: npm.config.get('https-proxy') || npm.config.get('proxy'), + noProxy: npm.config.get('noproxy') }) const getPreferOnline = npm => { diff --git a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js index 0e7b7c33e6c92..cd41d33cbb26c 100644 --- a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js @@ -66,6 +66,7 @@ Object { "metricsRegistry": "metrics-registry", "nodeBin": "/path/to/some/node", "nodeVersion": "1.2.3", + "noProxy": "noproxy", "npmBin": "/path/to/npm/bin.js", "npmCommand": null, "npmSession": "12345", @@ -83,6 +84,7 @@ Object { "prefix": "/path/to/npm/cli", "preid": "preid", "projectScope": "@npmcli", + "proxy": "proxy", "readOnly": "read-only", "rebuildBundle": "rebuild-bundle", "registry": "registry", diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js index 162e698daf29e..f18ce828c3e1d 100644 --- a/test/lib/utils/flat-options.js +++ b/test/lib/utils/flat-options.js @@ -110,6 +110,8 @@ class MockConfig { 'user-agent': 'user-agent', '@scope:registry': '@scope:registry', '//nerf.dart:_authToken': '//nerf.dart:_authToken', + 'proxy': 'proxy', + 'noproxy': 'noproxy', ...opts }] }