diff --git a/bin/io/setGlobalProxyAgent.js b/bin/io/setGlobalProxyAgent.js new file mode 100644 index 000000000..08b319e37 --- /dev/null +++ b/bin/io/setGlobalProxyAgent.js @@ -0,0 +1,15 @@ +import https from 'https'; +import HttpsProxyAgent from 'https-proxy-agent'; + +const setGlobalProxyAgent = ({ log }) => { + const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy; + const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy; + const noProxy = process.env.NO_PROXY || process.env.no_proxy; + + if ((httpsProxy || httpProxy) && !noProxy) { + https.globalAgent = new HttpsProxyAgent(httpsProxy || httpProxy); + log.info(`Using proxy server: ${httpsProxy || httpProxy}`); + } +}; + +export default setGlobalProxyAgent; diff --git a/bin/main.js b/bin/main.js index d647608db..6df70ced3 100755 --- a/bin/main.js +++ b/bin/main.js @@ -4,6 +4,7 @@ import pkgUp from 'pkg-up'; import { v4 as uuid } from 'uuid'; import GraphQLClient from './io/GraphQLClient'; +import setGlobalProxyAgent from './io/setGlobalProxyAgent'; import checkForUpdates from './lib/checkForUpdates'; import checkPackageJson from './lib/checkPackageJson'; import getEnv from './lib/getEnv'; @@ -37,6 +38,9 @@ export async function main(argv) { } export async function runAll(ctx) { + // Configure the proxy (if available) before we make any requests. + setGlobalProxyAgent(ctx); + // Run these in parallel; neither should ever reject await Promise.all([runBuild(ctx), checkForUpdates(ctx)]); diff --git a/package.json b/package.json index c6b4e5ff4..7e8fa82ea 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "execa": "^5.0.0", "fake-tag": "^2.0.0", "fs-extra": "^9.1.0", + "https-proxy-agent": "^5.0.0", "jsonfile": "^6.0.1", "junit-report-builder": "2.1.0", "listr": "0.14.3", diff --git a/yarn.lock b/yarn.lock index 86eeee386..61e942bde 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3308,6 +3308,13 @@ address@1.1.2, address@^1.0.1: resolved "https://registry.yarnpkg.com/address/-/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6" integrity sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA== +agent-base@6: + version "6.0.2" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" + integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== + dependencies: + debug "4" + aggregate-error@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.1.0.tgz#92670ff50f5359bdb7a3e0d40d0ec30c5737687a" @@ -5222,6 +5229,13 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9: dependencies: ms "2.0.0" +debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" + integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== + dependencies: + ms "2.1.2" + debug@^3.0.0, debug@^3.0.1: version "3.2.7" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a" @@ -5229,13 +5243,6 @@ debug@^3.0.0, debug@^3.0.1: dependencies: ms "^2.1.1" -debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1: - version "4.3.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" - integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== - dependencies: - ms "2.1.2" - decamelize-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9" @@ -7255,6 +7262,14 @@ https-browserify@^1.0.0: resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73" integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM= +https-proxy-agent@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" + integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA== + dependencies: + agent-base "6" + debug "4" + human-signals@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"