Skip to content

Commit 8c62327

Browse files
committed
chore: fix in prepare
1 parent 4493446 commit 8c62327

File tree

5 files changed

+64
-26
lines changed

5 files changed

+64
-26
lines changed

scripts/post-build.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as path from 'node:path';
99

1010
import tsConfig from '../tsconfig.json' with {type: 'json'};
1111

12+
import {sed} from './sed.ts';
13+
1214
const BUILD_DIR = path.join(process.cwd(), 'build');
1315

1416
/**
@@ -20,22 +22,6 @@ function writeFile(filePath: string, content: string): void {
2022
fs.writeFileSync(filePath, content, 'utf-8');
2123
}
2224

23-
/**
24-
* Replaces content in a file.
25-
* @param filePath The path to the file.
26-
* @param find The regex to find.
27-
* @param replace The string to replace with.
28-
*/
29-
function sed(filePath: string, find: RegExp, replace: string): void {
30-
if (!fs.existsSync(filePath)) {
31-
console.warn(`File not found for sed operation: ${filePath}`);
32-
return;
33-
}
34-
const content = fs.readFileSync(filePath, 'utf-8');
35-
const newContent = content.replace(find, replace);
36-
fs.writeFileSync(filePath, newContent, 'utf-8');
37-
}
38-
3925
/**
4026
* Ensures that licenses for third party files we use gets copied into the build/ dir.
4127
*/

scripts/prepare.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import {rm} from 'node:fs/promises';
88
import {resolve} from 'node:path';
99

10+
import {sed} from './sed.ts';
11+
1012
const projectRoot = process.cwd();
1113

1214
const filesToRemove = [
@@ -28,6 +30,28 @@ async function main() {
2830
process.exit(1);
2931
}
3032
}
33+
// TODO: remove once https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7072054 is available.
34+
sed(
35+
'node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.ts',
36+
`declare global {
37+
// TS typedefs are not up to date
38+
interface URLPattern {
39+
hash: string;
40+
hostname: string;
41+
password: string;
42+
pathname: string;
43+
port: string;
44+
protocol: string;
45+
search: string;
46+
username: string;
47+
hasRegExpGroups: boolean;
48+
test(url: string): boolean;
49+
}
50+
/* eslint-disable-next-line @typescript-eslint/naming-convention */
51+
var URLPattern: {prototype: URLPattern, new (input: string): URLPattern};
52+
}`,
53+
'',
54+
);
3155
console.log('Clean up of chrome-devtools-frontend complete.');
3256
}
3357

scripts/sed.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as fs from 'node:fs';
8+
9+
/**
10+
* Replaces content in a file.
11+
* @param filePath The path to the file.
12+
* @param find The regex to find.
13+
* @param replace The string to replace with.
14+
*/
15+
export function sed(
16+
filePath: string,
17+
find: RegExp | string,
18+
replace: string,
19+
): void {
20+
if (!fs.existsSync(filePath)) {
21+
console.warn(`File not found for sed operation: ${filePath}`);
22+
return;
23+
}
24+
const content = fs.readFileSync(filePath, 'utf-8');
25+
const newContent = content.replace(find, replace);
26+
fs.writeFileSync(filePath, newContent, 'utf-8');
27+
}

tests/tools/performance.test.js.snapshot

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ We can break this time down into the 4 phases that combine to make the LCP time:
3838
## Estimated savings: none
3939

4040
## External resources:
41+
- https://developer.chrome.com/docs/performance/insights/lcp-breakdown
4142
- https://web.dev/articles/lcp
4243
- https://web.dev/articles/optimize-lcp
4344
`;
@@ -66,31 +67,31 @@ Metrics (lab / observed):
6667
Metrics (field / real users): n/a – no data for this page in CrUX
6768
Available insights:
6869
- insight name: LCPBreakdown
69-
description: Each [subpart has specific improvement strategies](https://web.dev/articles/optimize-lcp#lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.
70+
description: Each [subpart has specific improvement strategies](https://developer.chrome.com/docs/performance/insights/lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.
7071
relevant trace bounds: {min: 122410996889, max: 122411126100}
7172
example question: Help me optimize my LCP score
7273
example question: Which LCP phase was most problematic?
7374
example question: What can I do to reduce the LCP time for this page load?
7475
- insight name: LCPDiscovery
75-
description: Optimize LCP by making the LCP image [discoverable](https://web.dev/articles/optimize-lcp#1_eliminate_resource_load_delay) from the HTML immediately, and [avoiding lazy-loading](https://web.dev/articles/lcp-lazy-loading)
76+
description: [Optimize LCP](https://developer.chrome.com/docs/performance/insights/lcp-discovery) by making the LCP image discoverable from the HTML immediately, and avoiding lazy-loading
7677
relevant trace bounds: {min: 122411004828, max: 122411055039}
7778
example question: Suggest fixes to reduce my LCP
7879
example question: What can I do to reduce my LCP discovery time?
7980
example question: Why is LCP discovery time important?
8081
- insight name: RenderBlocking
81-
description: Requests are blocking the page's initial render, which may delay LCP. [Deferring or inlining](https://web.dev/learn/performance/understanding-the-critical-path#render-blocking_resources) can move these network requests out of the critical path.
82+
description: Requests are blocking the page's initial render, which may delay LCP. [Deferring or inlining](https://developer.chrome.com/docs/performance/insights/render-blocking) can move these network requests out of the critical path.
8283
relevant trace bounds: {min: 122411037528, max: 122411053852}
8384
example question: Show me the most impactful render blocking requests that I should focus on
8485
example question: How can I reduce the number of render blocking requests?
8586
- insight name: DocumentLatency
86-
description: Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.
87+
description: Your first network request is the most important. [Reduce its latency](https://developer.chrome.com/docs/performance/insights/document-latency) by avoiding redirects, ensuring a fast server response, and enabling text compression.
8788
relevant trace bounds: {min: 122410998910, max: 122411043781}
8889
estimated metric savings: FCP 0 ms, LCP 0 ms
8990
estimated wasted bytes: 77.1 kB
9091
example question: How do I decrease the initial loading time of my page?
9192
example question: Did anything slow down the request for this document?
9293
- insight name: ThirdParties
93-
description: 3rd party code can significantly impact load performance. [Reduce and defer loading of 3rd party code](https://web.dev/articles/optimizing-content-efficiency-loading-third-party-javascript/) to prioritize your page's content.
94+
description: 3rd party code can significantly impact load performance. [Reduce and defer loading of 3rd party code](https://developer.chrome.com/docs/performance/insights/third-parties) to prioritize your page's content.
9495
relevant trace bounds: {min: 122411037881, max: 122416229595}
9596
example question: Which third parties are having the largest impact on my page performance?
9697

tests/trace-processing/parse.test.js.snapshot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ Metrics (lab / observed):
1515
Metrics (field / real users): n/a – no data for this page in CrUX
1616
Available insights:
1717
- insight name: LCPBreakdown
18-
description: Each [subpart has specific improvement strategies](https://web.dev/articles/optimize-lcp#lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.
18+
description: Each [subpart has specific improvement strategies](https://developer.chrome.com/docs/performance/insights/lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.
1919
relevant trace bounds: {min: 122410996889, max: 122411126100}
2020
example question: Help me optimize my LCP score
2121
example question: Which LCP phase was most problematic?
2222
example question: What can I do to reduce the LCP time for this page load?
2323
- insight name: LCPDiscovery
24-
description: Optimize LCP by making the LCP image [discoverable](https://web.dev/articles/optimize-lcp#1_eliminate_resource_load_delay) from the HTML immediately, and [avoiding lazy-loading](https://web.dev/articles/lcp-lazy-loading)
24+
description: [Optimize LCP](https://developer.chrome.com/docs/performance/insights/lcp-discovery) by making the LCP image discoverable from the HTML immediately, and avoiding lazy-loading
2525
relevant trace bounds: {min: 122411004828, max: 122411055039}
2626
example question: Suggest fixes to reduce my LCP
2727
example question: What can I do to reduce my LCP discovery time?
2828
example question: Why is LCP discovery time important?
2929
- insight name: RenderBlocking
30-
description: Requests are blocking the page's initial render, which may delay LCP. [Deferring or inlining](https://web.dev/learn/performance/understanding-the-critical-path#render-blocking_resources) can move these network requests out of the critical path.
30+
description: Requests are blocking the page's initial render, which may delay LCP. [Deferring or inlining](https://developer.chrome.com/docs/performance/insights/render-blocking) can move these network requests out of the critical path.
3131
relevant trace bounds: {min: 122411037528, max: 122411053852}
3232
example question: Show me the most impactful render blocking requests that I should focus on
3333
example question: How can I reduce the number of render blocking requests?
3434
- insight name: DocumentLatency
35-
description: Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.
35+
description: Your first network request is the most important. [Reduce its latency](https://developer.chrome.com/docs/performance/insights/document-latency) by avoiding redirects, ensuring a fast server response, and enabling text compression.
3636
relevant trace bounds: {min: 122410998910, max: 122411043781}
3737
estimated metric savings: FCP 0 ms, LCP 0 ms
3838
estimated wasted bytes: 77.1 kB
3939
example question: How do I decrease the initial loading time of my page?
4040
example question: Did anything slow down the request for this document?
4141
- insight name: ThirdParties
42-
description: 3rd party code can significantly impact load performance. [Reduce and defer loading of 3rd party code](https://web.dev/articles/optimizing-content-efficiency-loading-third-party-javascript/) to prioritize your page's content.
42+
description: 3rd party code can significantly impact load performance. [Reduce and defer loading of 3rd party code](https://developer.chrome.com/docs/performance/insights/third-parties) to prioritize your page's content.
4343
relevant trace bounds: {min: 122411037881, max: 122416229595}
4444
example question: Which third parties are having the largest impact on my page performance?
4545

0 commit comments

Comments
 (0)