@@ -214,23 +214,32 @@ export class ProxyAgent extends Agent {
214
214
}
215
215
}
216
216
217
+ declare const __webpack_require__ : unknown ;
218
+
217
219
// Work around https://github.com/TooTallNate/proxy-agents/pull/329
218
220
// While the proxy-agent package implementation in this file,
219
221
// and in the original, properly check whether an 'upgrade' header
220
222
// is present and set to 'websocket', the pac-proxy-agent performs
221
223
// a similar 'CONNECT vs regular HTTP proxy' selection and doesn't
222
224
// account for this. We monkey-patch in this behavior ourselves.
223
225
function installPacHttpsHack ( ) {
224
- const pacProxyAgentPath = require . resolve ( 'pac-proxy-agent' ) ;
225
- const pacRequire = createRequire ( pacProxyAgentPath ) ;
226
- const { HttpProxyAgent } = pacRequire (
227
- 'http-proxy-agent'
228
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
229
- ) as typeof import ( 'http-proxy-agent' ) ;
230
- const { HttpsProxyAgent } = pacRequire (
231
- 'https-proxy-agent'
232
- // eslint-disable-next-line @typescript-eslint/consistent-type-imports
233
- ) as typeof import ( 'https-proxy-agent' ) ;
226
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
227
+ let HttpProxyAgent : typeof import ( 'http-proxy-agent' ) . HttpProxyAgent ;
228
+ // eslint-disable-next-line @typescript-eslint/consistent-type-imports
229
+ let HttpsProxyAgent : typeof import ( 'https-proxy-agent' ) . HttpsProxyAgent ;
230
+ if ( typeof __webpack_require__ === 'undefined' ) {
231
+ const pacProxyAgentPath = require . resolve ( 'pac-proxy-agent' ) ;
232
+ const pacRequire = createRequire ( pacProxyAgentPath ) ;
233
+ HttpProxyAgent = pacRequire ( 'http-proxy-agent' ) . HttpProxyAgent ;
234
+ HttpsProxyAgent = pacRequire ( 'https-proxy-agent' ) . HttpsProxyAgent ;
235
+ } else {
236
+ // No such thing as require.resolve() in webpack, just need to assume
237
+ // that everything is hoisted :(
238
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
239
+ HttpProxyAgent = require ( 'http-proxy-agent' ) . HttpProxyAgent ;
240
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
241
+ HttpsProxyAgent = require ( 'https-proxy-agent' ) . HttpsProxyAgent ;
242
+ }
234
243
235
244
const kCompanionHttpsProxyAgent = Symbol ( 'kCompanionHttpsProxyAgent' ) ;
236
245
// eslint-disable-next-line @typescript-eslint/unbound-method
0 commit comments