@@ -7,9 +7,9 @@ import createDebug from 'debug';
77import { Readable } from 'stream' ;
88import { URL } from 'url' ;
99import { Agent , AgentConnectOpts , toBuffer } from 'agent-base' ;
10- import { HttpProxyAgent , HttpProxyAgentOptions } from 'http-proxy-agent' ;
11- import { HttpsProxyAgent , HttpsProxyAgentOptions } from 'https-proxy-agent' ;
12- import { SocksProxyAgent , SocksProxyAgentOptions } from 'socks-proxy-agent' ;
10+ import type { HttpProxyAgentOptions } from 'http-proxy-agent' ;
11+ import type { HttpsProxyAgentOptions } from 'https-proxy-agent' ;
12+ import type { SocksProxyAgentOptions } from 'socks-proxy-agent' ;
1313import {
1414 getUri ,
1515 protocols as gProtocols ,
@@ -41,6 +41,7 @@ const setServernameFromNonIpHost = <
4141 }
4242 return options ;
4343} ;
44+
4445type Protocols = keyof typeof gProtocols ;
4546
4647// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -245,9 +246,11 @@ export class PacProxyAgent<Uri extends string> extends Agent {
245246 }
246247 } else if ( type === 'SOCKS' || type === 'SOCKS5' ) {
247248 // Use a SOCKSv5h proxy
249+ const { SocksProxyAgent } = await import ( 'socks-proxy-agent' ) ;
248250 agent = new SocksProxyAgent ( `socks://${ target } ` , this . opts ) ;
249251 } else if ( type === 'SOCKS4' ) {
250252 // Use a SOCKSv4a proxy
253+ const { SocksProxyAgent } = await import ( 'socks-proxy-agent' ) ;
251254 agent = new SocksProxyAgent ( `socks4a://${ target } ` , this . opts ) ;
252255 } else if (
253256 type === 'PROXY' ||
@@ -260,8 +263,12 @@ export class PacProxyAgent<Uri extends string> extends Agent {
260263 type === 'HTTPS' ? 'https' : 'http'
261264 } ://${ target } `;
262265 if ( secureEndpoint || isWebSocket ) {
266+ const { HttpsProxyAgent } = await import (
267+ 'https-proxy-agent'
268+ ) ;
263269 agent = new HttpsProxyAgent ( proxyURL , this . opts ) ;
264270 } else {
271+ const { HttpProxyAgent } = await import ( 'http-proxy-agent' ) ;
265272 agent = new HttpProxyAgent ( proxyURL , this . opts ) ;
266273 }
267274 }
0 commit comments