From 12dca8f92e30fa7c24efd0dbda5646b0c3988b08 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 17 Aug 2024 09:46:45 -0700 Subject: [PATCH] fix: lazy load ProxyAgent to avoid bundling all the undici --- packages/http-client/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts index 6f575f7d..d0f13a94 100644 --- a/packages/http-client/src/index.ts +++ b/packages/http-client/src/index.ts @@ -6,7 +6,7 @@ import * as ifm from './interfaces' import * as net from 'net' import * as pm from './proxy' import * as tunnel from 'tunnel' -import {ProxyAgent} from 'undici' +import type ProxyAgent from 'undici/types/proxy-agent' export enum HttpCodes { OK = 200, @@ -722,6 +722,12 @@ export class HttpClient { } const usingSsl = parsedUrl.protocol === 'https:' + + // Lazy load ProxyAgent to avoid bundling all the undici + const ProxyAgent = + // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires + require('undici/lib/proxy-agent') as typeof import('undici/types/proxy-agent').default + proxyAgent = new ProxyAgent({ uri: proxyUrl.href, pipelining: !this._keepAlive ? 0 : 1,