diff --git a/README.md b/README.md index 66bfbc3fb..8f72d2349 100644 --- a/README.md +++ b/README.md @@ -293,8 +293,8 @@ same major line. Should you need to upgrade to a new major, use an explicit environment variables are required and as plain text. If you want to send an empty password, explicitly set `COREPACK_NPM_PASSWORD` to an empty string. -- `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are supported through - [`node-proxy-agent`](https://github.com/TooTallNate/node-proxy-agent). +- `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` are supported through Undici's + [`EnvHttpProxyAgent`](https://undici.nodejs.org/#/docs/api/EnvHttpProxyAgent.md). - `COREPACK_INTEGRITY_KEYS` can be set to an empty string or `0` to instruct Corepack to skip integrity checks, or to a JSON string containing diff --git a/package.json b/package.json index 3bf2c3a9e..742623571 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "devDependencies": { "@types/debug": "^4.1.5", "@types/node": "^20.4.6", - "@types/proxy-from-env": "^1", "@types/semver": "^7.1.0", "@types/which": "^3.0.0", "@yarnpkg/eslint-config": "^2.0.0", @@ -31,7 +30,6 @@ "debug": "^4.1.1", "esbuild": "^0.24.2", "eslint": "^8.57.0", - "proxy-from-env": "^1.1.0", "semver": "^7.6.3", "supports-color": "^10.0.0", "tar": "^7.4.0", diff --git a/sources/httpUtils.ts b/sources/httpUtils.ts index 6c2dc9040..5e64a4121 100644 --- a/sources/httpUtils.ts +++ b/sources/httpUtils.ts @@ -90,30 +90,13 @@ export async function fetchUrlStream(input: string | URL, init?: RequestInit) { return stream; } -let ProxyAgent: typeof import('undici').ProxyAgent; +let ProxyAgent: typeof import('undici').EnvHttpProxyAgent; async function getProxyAgent(input: string | URL) { - const {getProxyForUrl} = await import(`proxy-from-env`); - - // @ts-expect-error - The internal implementation is compatible with a WHATWG URL instance - const proxy = getProxyForUrl(input); - - if (!proxy) return undefined; - if (ProxyAgent == null) { - // Doing a deep import here since undici isn't tree-shakeable - const [api, Dispatcher, _ProxyAgent] = await Promise.all([ - // @ts-expect-error internal module is untyped - import(`undici/lib/api/index.js`), - // @ts-expect-error internal module is untyped - import(`undici/lib/dispatcher/dispatcher.js`), - // @ts-expect-error internal module is untyped - import(`undici/lib/dispatcher/proxy-agent.js`), - ]); - - Object.assign(Dispatcher.default.prototype, api.default); - ProxyAgent = _ProxyAgent.default; + // @ts-expect-error internal module is untyped + const {default: EnvHttpProxyAgent} = await import(`undici/lib/dispatcher/env-http-proxy-agent.js`); + ProxyAgent = EnvHttpProxyAgent; } - - return new ProxyAgent(proxy); + return new ProxyAgent(); } diff --git a/yarn.lock b/yarn.lock index 1b44a9831..38fbb16f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -657,15 +657,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*": - version: 22.13.1 - resolution: "@types/node@npm:22.13.1" - dependencies: - undici-types: "npm:~6.20.0" - checksum: 10c0/d4e56d41d8bd53de93da2651c0a0234e330bd7b1b6d071b1a94bd3b5ee2d9f387519e739c52a15c1faa4fb9d97e825b848421af4b2e50e6518011e7adb4a34b7 - languageName: node - linkType: hard - "@types/node@npm:^20.4.6": version: 20.17.17 resolution: "@types/node@npm:20.17.17" @@ -675,15 +666,6 @@ __metadata: languageName: node linkType: hard -"@types/proxy-from-env@npm:^1": - version: 1.0.4 - resolution: "@types/proxy-from-env@npm:1.0.4" - dependencies: - "@types/node": "npm:*" - checksum: 10c0/ff2baedf8b5513ebf76bbe1b80079be45cc84c603951080656d2df64fcea2d3206489f22ec76f64cc3123b1c2a6836f97ed131a7456c769e22059dbca5904c35 - languageName: node - linkType: hard - "@types/semver@npm:^7.1.0": version: 7.5.8 resolution: "@types/semver@npm:7.5.8" @@ -1395,7 +1377,6 @@ __metadata: dependencies: "@types/debug": "npm:^4.1.5" "@types/node": "npm:^20.4.6" - "@types/proxy-from-env": "npm:^1" "@types/semver": "npm:^7.1.0" "@types/which": "npm:^3.0.0" "@yarnpkg/eslint-config": "npm:^2.0.0" @@ -1406,7 +1387,6 @@ __metadata: debug: "npm:^4.1.1" esbuild: "npm:^0.24.2" eslint: "npm:^8.57.0" - proxy-from-env: "npm:^1.1.0" semver: "npm:^7.6.3" supports-color: "npm:^10.0.0" tar: "npm:^7.4.0" @@ -3596,13 +3576,6 @@ __metadata: languageName: node linkType: hard -"proxy-from-env@npm:^1.1.0": - version: 1.1.0 - resolution: "proxy-from-env@npm:1.1.0" - checksum: 10c0/fe7dd8b1bdbbbea18d1459107729c3e4a2243ca870d26d34c2c1bcd3e4425b7bcc5112362df2d93cc7fb9746f6142b5e272fd1cc5c86ddf8580175186f6ad42b - languageName: node - linkType: hard - "pump@npm:^3.0.0": version: 3.0.2 resolution: "pump@npm:3.0.2"