|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { HttpsProxyAgent } from 'https-proxy-agent'; |
10 | 9 | import { createHash } from 'node:crypto'; |
11 | 10 | import { readFile, rm, writeFile } from 'node:fs/promises'; |
12 | | -import { get as httpsGet } from 'node:https'; |
| 11 | +import { type Agent, get as httpsGet } from 'node:https'; |
13 | 12 | import { join } from 'node:path'; |
14 | 13 | import { NormalizedCachedOptions } from '../normalize-cache'; |
15 | 14 | import { htmlRewritingStream } from './html-rewriting-stream'; |
@@ -195,12 +194,28 @@ export class InlineFontsProcessor { |
195 | 194 | } |
196 | 195 |
|
197 | 196 | const httpsProxy = process.env.HTTPS_PROXY ?? process.env.https_proxy; |
| 197 | + let agent: Agent | undefined; |
| 198 | + if (httpsProxy) { |
| 199 | + // TODO: Remove `https-proxy-agent` usage once the min supported version of Node.js is 24.5.0 |
| 200 | + // https.globalAgent = new https.Agent({ |
| 201 | + // proxyEnv: { HTTPS_PROXY: 'http://proxy.company.com:8080' }, |
| 202 | + // }); |
| 203 | + // See: https://nodejs.org/en/learn/http/enterprise-network-configuration |
| 204 | + // See: https://nodejs.org/docs/latest/api/https.html |
| 205 | + |
| 206 | + const { HttpsProxyAgent } = (await import('https-proxy-agent' as string)) as typeof import( |
| 207 | + 'https-proxy-agent', |
| 208 | + { with: { 'resolution-mode': 'import' } } |
| 209 | + ); |
| 210 | + agent = new HttpsProxyAgent(httpsProxy) as unknown as Agent; |
| 211 | + } |
| 212 | + |
198 | 213 | const data = await new Promise<string>((resolve, reject) => { |
199 | 214 | let rawResponse = ''; |
200 | 215 | httpsGet( |
201 | 216 | url, |
202 | 217 | { |
203 | | - agent: httpsProxy ? new HttpsProxyAgent(httpsProxy) : undefined, |
| 218 | + agent, |
204 | 219 | headers: { |
205 | 220 | /** |
206 | 221 | * Always use a Windows UA. This is because Google fonts will including hinting in fonts for Windows. |
|
0 commit comments