@@ -7,9 +7,9 @@ import createDebug from 'debug';
7
7
import { Readable } from 'stream' ;
8
8
import { URL } from 'url' ;
9
9
import { 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' ;
13
13
import {
14
14
getUri ,
15
15
protocols as gProtocols ,
@@ -41,6 +41,7 @@ const setServernameFromNonIpHost = <
41
41
}
42
42
return options ;
43
43
} ;
44
+
44
45
type Protocols = keyof typeof gProtocols ;
45
46
46
47
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -245,9 +246,11 @@ export class PacProxyAgent<Uri extends string> extends Agent {
245
246
}
246
247
} else if ( type === 'SOCKS' || type === 'SOCKS5' ) {
247
248
// Use a SOCKSv5h proxy
249
+ const { SocksProxyAgent } = await import ( 'socks-proxy-agent' ) ;
248
250
agent = new SocksProxyAgent ( `socks://${ target } ` , this . opts ) ;
249
251
} else if ( type === 'SOCKS4' ) {
250
252
// Use a SOCKSv4a proxy
253
+ const { SocksProxyAgent } = await import ( 'socks-proxy-agent' ) ;
251
254
agent = new SocksProxyAgent ( `socks4a://${ target } ` , this . opts ) ;
252
255
} else if (
253
256
type === 'PROXY' ||
@@ -260,8 +263,12 @@ export class PacProxyAgent<Uri extends string> extends Agent {
260
263
type === 'HTTPS' ? 'https' : 'http'
261
264
} ://${ target } `;
262
265
if ( secureEndpoint || isWebSocket ) {
266
+ const { HttpsProxyAgent } = await import (
267
+ 'https-proxy-agent'
268
+ ) ;
263
269
agent = new HttpsProxyAgent ( proxyURL , this . opts ) ;
264
270
} else {
271
+ const { HttpProxyAgent } = await import ( 'http-proxy-agent' ) ;
265
272
agent = new HttpProxyAgent ( proxyURL , this . opts ) ;
266
273
}
267
274
}
0 commit comments