Skip to content

Commit 568e5d2

Browse files
committed
build: lock file maintenance
See associated pull request for more information. Closes #30625 as a pr takeover
1 parent 9e292f1 commit 568e5d2

File tree

2 files changed

+560
-659
lines changed

2 files changed

+560
-659
lines changed

packages/angular/build/src/utils/index-file/inline-fonts.ts

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { HttpsProxyAgent } from 'https-proxy-agent';
1010
import { createHash } from 'node:crypto';
1111
import { readFile, rm, writeFile } from 'node:fs/promises';
12-
import * as https from 'node:https';
12+
import { Agent, get as httpsGet } from 'node:https';
1313
import { join } from 'node:path';
1414
import { NormalizedCachedOptions } from '../normalize-cache';
1515
import { htmlRewritingStream } from './html-rewriting-stream';
@@ -194,56 +194,49 @@ export class InlineFontsProcessor {
194194
} catch {}
195195
}
196196

197-
let agent: HttpsProxyAgent<string> | undefined;
198197
const httpsProxy = process.env.HTTPS_PROXY ?? process.env.https_proxy;
199-
200-
if (httpsProxy) {
201-
agent = new HttpsProxyAgent(httpsProxy);
202-
}
203-
204198
const data = await new Promise<string>((resolve, reject) => {
205199
let rawResponse = '';
206-
https
207-
.get(
208-
url,
209-
{
210-
agent,
211-
headers: {
212-
/**
213-
* Always use a Windows UA. This is because Google fonts will including hinting in fonts for Windows.
214-
* Hinting is a technique used with Windows files to improve appearance however
215-
* results in 20-50% larger file sizes.
216-
*
217-
* @see http://google3/java/com/google/fonts/css/OpenSansWebFontsCssBuilder.java?l=22
218-
* @see https://fonts.google.com/knowledge/glossary/hinting (short)
219-
* @see https://glyphsapp.com/learn/hinting-manual-truetype-hinting (deep dive)
220-
*/
221-
'user-agent':
222-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
223-
},
200+
httpsGet(
201+
url,
202+
{
203+
// TODO(alanagius): remove casting https://github.com/TooTallNate/proxy-agents/issues/379 is fixed.
204+
agent: httpsProxy ? (new HttpsProxyAgent(httpsProxy) as Agent) : undefined,
205+
headers: {
206+
/**
207+
* Always use a Windows UA. This is because Google fonts will including hinting in fonts for Windows.
208+
* Hinting is a technique used with Windows files to improve appearance however
209+
* results in 20-50% larger file sizes.
210+
*
211+
* @see http://google3/java/com/google/fonts/css/OpenSansWebFontsCssBuilder.java?l=22
212+
* @see https://fonts.google.com/knowledge/glossary/hinting (short)
213+
* @see https://glyphsapp.com/learn/hinting-manual-truetype-hinting (deep dive)
214+
*/
215+
'user-agent':
216+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
224217
},
225-
(res) => {
226-
if (res.statusCode !== 200) {
227-
reject(
228-
new Error(
229-
`Inlining of fonts failed. ${url} returned status code: ${res.statusCode}.`,
230-
),
231-
);
232-
233-
return;
234-
}
235-
236-
res.on('data', (chunk) => (rawResponse += chunk)).on('end', () => resolve(rawResponse));
237-
},
238-
)
239-
.on('error', (e) =>
240-
reject(
241-
new Error(
242-
`Inlining of fonts failed. An error has occurred while retrieving ${url} over the internet.\n` +
243-
e.message,
244-
),
218+
},
219+
(res) => {
220+
if (res.statusCode !== 200) {
221+
reject(
222+
new Error(
223+
`Inlining of fonts failed. ${url} returned status code: ${res.statusCode}.`,
224+
),
225+
);
226+
227+
return;
228+
}
229+
230+
res.on('data', (chunk) => (rawResponse += chunk)).on('end', () => resolve(rawResponse));
231+
},
232+
).on('error', (e) =>
233+
reject(
234+
new Error(
235+
`Inlining of fonts failed. An error has occurred while retrieving ${url} over the internet.\n` +
236+
e.message,
245237
),
246-
);
238+
),
239+
);
247240
});
248241

249242
if (cacheFile) {

0 commit comments

Comments
 (0)