Skip to content

Commit

Permalink
fix(cli): use ProxyAgent instead of HttpsProxyAgent (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
l00sed authored Jun 20, 2024
1 parent 8a0e3dc commit cdf4605
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"compression": "^1.7.4",
"debug": "^4.3.1",
"express": "^4.17.1",
"https-proxy-agent": "^5.0.0",
"proxy-agent": "^6.4.0",
"inquirer": "^6.3.1",
"isomorphic-fetch": "^3.0.0",
"lighthouse": "12.1.0",
Expand Down
11 changes: 7 additions & 4 deletions packages/cli/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
'use strict';

const fetch = require('isomorphic-fetch');
const {HttpsProxyAgent} = require('https-proxy-agent');
const {ProxyAgent} = require('proxy-agent');

/** @type import('isomorphic-fetch') */
module.exports = (url, options) => {
/** @type {Parameters<import('isomorphic-fetch')>[1] & { agent?: import('https-proxy-agent').HttpsProxyAgent }} */
/** @type {Parameters<import('isomorphic-fetch')>[1] & { agent?: import('proxy-agent').ProxyAgent }} */
const instanceOptions = {
...options,
};

if (!instanceOptions.agent && process.env.HTTP_PROXY) {
instanceOptions.agent = new HttpsProxyAgent(process.env.HTTP_PROXY);
if (
!instanceOptions.agent &&
(process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.NO_PROXY)
) {
instanceOptions.agent = new ProxyAgent();
}

return fetch(url, instanceOptions);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15822,7 +15822,7 @@ [email protected]:
proxy-from-env "^1.1.0"
socks-proxy-agent "^8.0.2"

[email protected]:
[email protected], proxy-agent@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-6.4.0.tgz#b4e2dd51dee2b377748aef8d45604c2d7608652d"
integrity sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ==
Expand Down

0 comments on commit cdf4605

Please sign in to comment.