Skip to content

Commit 081a1f1

Browse files
committed
chore: fix in prepare
1 parent 4493446 commit 081a1f1

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

scripts/post-build.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as fs from 'node:fs';
88
import * as path from 'node:path';
99

1010
import tsConfig from '../tsconfig.json' with {type: 'json'};
11+
import { sed } from './sed.ts';
1112

1213
const BUILD_DIR = path.join(process.cwd(), 'build');
1314

@@ -20,22 +21,6 @@ function writeFile(filePath: string, content: string): void {
2021
fs.writeFileSync(filePath, content, 'utf-8');
2122
}
2223

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-
3924
/**
4025
* Ensures that licenses for third party files we use gets copied into the build/ dir.
4126
*/

scripts/prepare.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {rm} from 'node:fs/promises';
88
import {resolve} from 'node:path';
9+
import { sed } from './sed.ts';
910

1011
const projectRoot = process.cwd();
1112

@@ -28,6 +29,24 @@ async function main() {
2829
process.exit(1);
2930
}
3031
}
32+
// TODO: remove once https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7072054 is available.
33+
sed('node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.ts', `declare global {
34+
// TS typedefs are not up to date
35+
interface URLPattern {
36+
hash: string;
37+
hostname: string;
38+
password: string;
39+
pathname: string;
40+
port: string;
41+
protocol: string;
42+
search: string;
43+
username: string;
44+
hasRegExpGroups: boolean;
45+
test(url: string): boolean;
46+
}
47+
/* eslint-disable-next-line @typescript-eslint/naming-convention */
48+
var URLPattern: {prototype: URLPattern, new (input: string): URLPattern};
49+
}`, '');
3150
console.log('Clean up of chrome-devtools-frontend complete.');
3251
}
3352

scripts/sed.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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(filePath: string, find: RegExp|string, replace: string): void {
16+
if (!fs.existsSync(filePath)) {
17+
console.warn(`File not found for sed operation: ${filePath}`);
18+
return;
19+
}
20+
const content = fs.readFileSync(filePath, 'utf-8');
21+
const newContent = content.replace(find, replace);
22+
fs.writeFileSync(filePath, newContent, 'utf-8');
23+
}

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)