diff --git a/packages/compile-solidity/package.json b/packages/compile-solidity/package.json index ca1dfcbbfb1..5e78990fb5f 100644 --- a/packages/compile-solidity/package.json +++ b/packages/compile-solidity/package.json @@ -28,6 +28,7 @@ "axios-retry": "^3.1.9", "debug": "^4.3.1", "fs-extra": "^9.1.0", + "https-proxy-agent": "^5.0.0", "iter-tools": "^7.0.2", "lodash": "^4.17.21", "node-abort-controller": "^3.0.1", diff --git a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/VersionRange.ts b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/VersionRange.ts index ccba5381081..9744d55b1e1 100644 --- a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/VersionRange.ts +++ b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/VersionRange.ts @@ -6,7 +6,19 @@ import originalRequire from "original-require"; // must polyfill AbortController to use axios >=0.20.0, <=0.27.2 on node <= v14.x import "../../polyfill"; -import { default as axios, AxiosResponse } from "axios"; +import { default as axiosPlain, AxiosResponse } from "axios"; +import { HttpsProxyAgent } from "https-proxy-agent"; + +const environmentProxy = process.env.https_proxy || process.env.http_proxy; +let axios; +if (environmentProxy) { + const agent = new HttpsProxyAgent(environmentProxy); + axios = axiosPlain.create({ + httpsAgent: agent + }); +} else { + axios = axiosPlain; +} import semver from "semver"; @@ -186,7 +198,7 @@ export class VersionRange { return this.compilerFromString(response.data); } - async getSolcFromCacheOrUrl(versionConstraint: string, index: number = 0) { + async getSolcFromCacheOrUrl(versionConstraint: string, index = 0) { // go through all sources (compilerRoots) trying to locate a // suitable version of the Solidity compiler const { compilerRoots, events } = this.config; @@ -257,7 +269,7 @@ export class VersionRange { version.includes("nightly") || version.includes("commit"); if (isPrerelease) { - for (let build of allVersions.builds) { + for (const build of allVersions.builds) { const exists = build["prerelease"] === version || build["build"] === version ||