lighthouse 11.6.0-dev.20240304 → 11.6.0-dev.20240306

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/core/audits/prioritize-lcp-image.d.ts +1 -1
  2. package/core/computed/load-simulator.d.ts +3 -1
  3. package/core/computed/load-simulator.js +3 -1
  4. package/core/computed/metrics/lantern-metric.d.ts +1 -1
  5. package/core/computed/page-dependency-graph.d.ts +1 -54
  6. package/core/computed/page-dependency-graph.js +3 -450
  7. package/core/gather/gatherers/accessibility.js +2 -1
  8. package/core/gather/session.js +5 -0
  9. package/core/lib/emulation.js +0 -3
  10. package/core/lib/lantern/lantern.d.ts +0 -1
  11. package/core/lib/lantern/lantern.js +0 -3
  12. package/core/lib/lantern/network-node.d.ts +5 -4
  13. package/core/lib/lantern/network-node.js +7 -5
  14. package/core/lib/lantern/page-dependency-graph.d.ts +58 -0
  15. package/core/lib/lantern/page-dependency-graph.js +463 -0
  16. package/core/lib/lantern/simulator/connection-pool.d.ts +15 -14
  17. package/core/lib/lantern/simulator/connection-pool.js +9 -8
  18. package/core/lib/lantern/simulator/dns-cache.d.ts +11 -4
  19. package/core/lib/lantern/simulator/dns-cache.js +3 -3
  20. package/core/lib/lantern/simulator/network-analyzer.d.ts +30 -29
  21. package/core/lib/lantern/simulator/network-analyzer.js +15 -14
  22. package/core/lib/lantern/simulator/simulator.d.ts +20 -14
  23. package/core/lib/lantern/simulator/simulator.js +19 -11
  24. package/core/lib/network-recorder.js +1 -1
  25. package/core/lib/network-request.d.ts +4 -2
  26. package/core/lib/network-request.js +3 -2
  27. package/package.json +1 -1
  28. package/tsconfig.json +1 -0
  29. package/types/gatherer.d.ts +8 -35
  30. package/types/internal/lantern.d.ts +115 -73
@@ -4,8 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import * as LH from '../../../../types/lh.js';
8
- import * as Lantern from '../lantern.js';
7
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
8
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.Simulation.Options} SimulationOptions */
9
+
9
10
  import {NetworkAnalyzer} from './network-analyzer.js';
10
11
  import {TcpConnection} from './tcp-connection.js';
11
12
 
@@ -18,8 +19,8 @@ const CONNECTIONS_PER_ORIGIN = 6;
18
19
 
19
20
  export class ConnectionPool {
20
21
  /**
21
- * @param {Lantern.NetworkRequest[]} records
22
- * @param {Required<LH.Gatherer.Simulation.Options>} options
22
+ * @param {NetworkRequest[]} records
23
+ * @param {Required<SimulationOptions>} options
23
24
  */
24
25
  constructor(records, options) {
25
26
  this._options = options;
@@ -27,7 +28,7 @@ export class ConnectionPool {
27
28
  this._records = records;
28
29
  /** @type {Map<string, TcpConnection[]>} */
29
30
  this._connectionsByOrigin = new Map();
30
- /** @type {Map<Lantern.NetworkRequest, TcpConnection>} */
31
+ /** @type {Map<NetworkRequest, TcpConnection>} */
31
32
  this._connectionsByRecord = new Map();
32
33
  this._connectionsInUse = new Set();
33
34
  this._connectionReusedByRequestId = NetworkAnalyzer.estimateIfConnectionWasReused(records, {
@@ -125,7 +126,7 @@ export class ConnectionPool {
125
126
  * If ignoreConnectionReused is true, acquire will consider all connections not in use as available.
126
127
  * Otherwise, only connections that have matching "warmth" are considered available.
127
128
  *
128
- * @param {Lantern.NetworkRequest} record
129
+ * @param {NetworkRequest} record
129
130
  * @param {{ignoreConnectionReused?: boolean}} options
130
131
  * @return {?TcpConnection}
131
132
  */
@@ -151,7 +152,7 @@ export class ConnectionPool {
151
152
  * Return the connection currently being used to fetch a record. If no connection
152
153
  * currently being used for this record, an error will be thrown.
153
154
  *
154
- * @param {Lantern.NetworkRequest} record
155
+ * @param {NetworkRequest} record
155
156
  * @return {TcpConnection}
156
157
  */
157
158
  acquireActiveConnectionFromRecord(record) {
@@ -162,7 +163,7 @@ export class ConnectionPool {
162
163
  }
163
164
 
164
165
  /**
165
- * @param {Lantern.NetworkRequest} record
166
+ * @param {NetworkRequest} record
166
167
  */
167
168
  release(record) {
168
169
  const connection = this._connectionsByRecord.get(record);
@@ -1,3 +1,4 @@
1
+ export type NetworkRequest = import('../../../../types/internal/lantern.js').Lantern.NetworkRequest;
1
2
  export class DNSCache {
2
3
  /**
3
4
  * @param {{rtt: number}} options
@@ -11,19 +12,19 @@ export class DNSCache {
11
12
  resolvedAt: number;
12
13
  }>;
13
14
  /**
14
- * @param {Lantern.NetworkRequest} request
15
+ * @param {NetworkRequest} request
15
16
  * @param {{requestedAt: number, shouldUpdateCache: boolean}=} options
16
17
  * @return {number}
17
18
  */
18
- getTimeUntilResolution(request: import("../../../../types/internal/lantern.js").NetworkRequest<any>, options?: {
19
+ getTimeUntilResolution(request: NetworkRequest, options?: {
19
20
  requestedAt: number;
20
21
  shouldUpdateCache: boolean;
21
22
  } | undefined): number;
22
23
  /**
23
- * @param {Lantern.NetworkRequest} request
24
+ * @param {NetworkRequest} request
24
25
  * @param {number} resolvedAt
25
26
  */
26
- _updateCacheResolvedAtIfNeeded(request: import("../../../../types/internal/lantern.js").NetworkRequest<any>, resolvedAt: number): void;
27
+ _updateCacheResolvedAtIfNeeded(request: NetworkRequest, resolvedAt: number): void;
27
28
  /**
28
29
  * Forcefully sets the DNS resolution time for a record.
29
30
  * Useful for testing and alternate execution simulations.
@@ -36,6 +37,12 @@ export class DNSCache {
36
37
  export namespace DNSCache {
37
38
  export { DNS_RESOLUTION_RTT_MULTIPLIER as RTT_MULTIPLIER };
38
39
  }
40
+ /**
41
+ * @license
42
+ * Copyright 2018 Google LLC
43
+ * SPDX-License-Identifier: Apache-2.0
44
+ */
45
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
39
46
  declare const DNS_RESOLUTION_RTT_MULTIPLIER: 2;
40
47
  export {};
41
48
  //# sourceMappingURL=dns-cache.d.ts.map
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import * as Lantern from '../lantern.js';
7
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
8
8
 
9
9
  // A DNS lookup will usually take ~1-2 roundtrips of connection latency plus the extra DNS routing time.
10
10
  // Example: https://www.webpagetest.org/result/180703_3A_e33ec79747c002ed4d7bcbfc81462203/1/details/#waterfall_view_step1
@@ -25,7 +25,7 @@ class DNSCache {
25
25
  }
26
26
 
27
27
  /**
28
- * @param {Lantern.NetworkRequest} request
28
+ * @param {NetworkRequest} request
29
29
  * @param {{requestedAt: number, shouldUpdateCache: boolean}=} options
30
30
  * @return {number}
31
31
  */
@@ -47,7 +47,7 @@ class DNSCache {
47
47
  }
48
48
 
49
49
  /**
50
- * @param {Lantern.NetworkRequest} request
50
+ * @param {NetworkRequest} request
51
51
  * @param {number} resolvedAt
52
52
  */
53
53
  _updateCacheResolvedAtIfNeeded(request, resolvedAt) {
@@ -1,3 +1,4 @@
1
+ export type NetworkRequest = import('../../../../types/internal/lantern.js').Lantern.NetworkRequest;
1
2
  export type Summary = {
2
3
  min: number;
3
4
  max: number;
@@ -32,10 +33,10 @@ export class NetworkAnalyzer {
32
33
  */
33
34
  static get SUMMARY(): string;
34
35
  /**
35
- * @param {Lantern.NetworkRequest[]} records
36
- * @return {Map<string, Lantern.NetworkRequest[]>}
36
+ * @param {NetworkRequest[]} records
37
+ * @return {Map<string, NetworkRequest[]>}
37
38
  */
38
- static groupByOrigin(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[]): Map<string, import("../../../../types/internal/lantern.js").NetworkRequest<any>[]>;
39
+ static groupByOrigin(records: NetworkRequest[]): Map<string, NetworkRequest[]>;
39
40
  /**
40
41
  * @param {number[]} values
41
42
  * @return {Summary}
@@ -46,14 +47,14 @@ export class NetworkAnalyzer {
46
47
  * @return {Map<string, Summary>}
47
48
  */
48
49
  static summarize(values: Map<string, number[]>): Map<string, Summary>;
49
- /** @typedef {{record: Lantern.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
50
+ /** @typedef {{record: NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
50
51
  /**
51
- * @param {Lantern.NetworkRequest[]} records
52
+ * @param {NetworkRequest[]} records
52
53
  * @param {(e: RequestInfo) => number | number[] | undefined} iteratee
53
54
  * @return {Map<string, number[]>}
54
55
  */
55
- static _estimateValueByOrigin(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[], iteratee: (e: {
56
- record: import("../../../../types/internal/lantern.js").NetworkRequest<any>;
56
+ static _estimateValueByOrigin(records: NetworkRequest[], iteratee: (e: {
57
+ record: NetworkRequest;
57
58
  timing: LH.Crdp.Network.ResourceTiming;
58
59
  connectionReused?: boolean | undefined;
59
60
  }) => number | number[] | undefined): Map<string, number[]>;
@@ -69,7 +70,7 @@ export class NetworkAnalyzer {
69
70
  * @return {number[]|number|undefined}
70
71
  */
71
72
  static _estimateRTTViaConnectionTiming(info: {
72
- record: import("../../../../types/internal/lantern.js").NetworkRequest<any>;
73
+ record: NetworkRequest;
73
74
  timing: LH.Crdp.Network.ResourceTiming;
74
75
  connectionReused?: boolean | undefined;
75
76
  }): number[] | number | undefined;
@@ -82,7 +83,7 @@ export class NetworkAnalyzer {
82
83
  * @return {number|undefined}
83
84
  */
84
85
  static _estimateRTTViaDownloadTiming(info: {
85
- record: import("../../../../types/internal/lantern.js").NetworkRequest<any>;
86
+ record: NetworkRequest;
86
87
  timing: LH.Crdp.Network.ResourceTiming;
87
88
  connectionReused?: boolean | undefined;
88
89
  }): number | undefined;
@@ -96,7 +97,7 @@ export class NetworkAnalyzer {
96
97
  * @return {number|undefined}
97
98
  */
98
99
  static _estimateRTTViaSendStartTiming(info: {
99
- record: import("../../../../types/internal/lantern.js").NetworkRequest<any>;
100
+ record: NetworkRequest;
100
101
  timing: LH.Crdp.Network.ResourceTiming;
101
102
  connectionReused?: boolean | undefined;
102
103
  }): number | undefined;
@@ -110,32 +111,32 @@ export class NetworkAnalyzer {
110
111
  * @return {number|undefined}
111
112
  */
112
113
  static _estimateRTTViaHeadersEndTiming(info: {
113
- record: import("../../../../types/internal/lantern.js").NetworkRequest<any>;
114
+ record: NetworkRequest;
114
115
  timing: LH.Crdp.Network.ResourceTiming;
115
116
  connectionReused?: boolean | undefined;
116
117
  }): number | undefined;
117
118
  /**
118
119
  * Given the RTT to each origin, estimates the observed server response times.
119
120
  *
120
- * @param {Lantern.NetworkRequest[]} records
121
+ * @param {NetworkRequest[]} records
121
122
  * @param {Map<string, number>} rttByOrigin
122
123
  * @return {Map<string, number[]>}
123
124
  */
124
- static _estimateResponseTimeByOrigin(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[], rttByOrigin: Map<string, number>): Map<string, number[]>;
125
+ static _estimateResponseTimeByOrigin(records: NetworkRequest[], rttByOrigin: Map<string, number>): Map<string, number[]>;
125
126
  /**
126
- * @param {Lantern.NetworkRequest[]} records
127
+ * @param {NetworkRequest[]} records
127
128
  * @return {boolean}
128
129
  */
129
- static canTrustConnectionInformation(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[]): boolean;
130
+ static canTrustConnectionInformation(records: NetworkRequest[]): boolean;
130
131
  /**
131
132
  * Returns a map of requestId -> connectionReused, estimating the information if the information
132
133
  * available in the records themselves appears untrustworthy.
133
134
  *
134
- * @param {Lantern.NetworkRequest[]} records
135
+ * @param {NetworkRequest[]} records
135
136
  * @param {{forceCoarseEstimates: boolean}} [options]
136
137
  * @return {Map<string, boolean>}
137
138
  */
138
- static estimateIfConnectionWasReused(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[], options?: {
139
+ static estimateIfConnectionWasReused(records: NetworkRequest[], options?: {
139
140
  forceCoarseEstimates: boolean;
140
141
  } | undefined): Map<string, boolean>;
141
142
  /**
@@ -143,20 +144,20 @@ export class NetworkAnalyzer {
143
144
  * Attempts to use the most accurate information first and falls back to coarser estimates when it
144
145
  * is unavailable.
145
146
  *
146
- * @param {Lantern.NetworkRequest[]} records
147
+ * @param {NetworkRequest[]} records
147
148
  * @param {RTTEstimateOptions} [options]
148
149
  * @return {Map<string, Summary>}
149
150
  */
150
- static estimateRTTByOrigin(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[], options?: RTTEstimateOptions | undefined): Map<string, Summary>;
151
+ static estimateRTTByOrigin(records: NetworkRequest[], options?: RTTEstimateOptions | undefined): Map<string, Summary>;
151
152
  /**
152
153
  * Estimates the server response time of each origin. RTT times can be passed in or will be
153
154
  * estimated automatically if not provided.
154
155
  *
155
- * @param {Lantern.NetworkRequest[]} records
156
+ * @param {NetworkRequest[]} records
156
157
  * @param {RTTEstimateOptions & {rttByOrigin?: Map<string, number>}} [options]
157
158
  * @return {Map<string, Summary>}
158
159
  */
159
- static estimateServerResponseTimeByOrigin(records: import("../../../../types/internal/lantern.js").NetworkRequest<any>[], options?: (RTTEstimateOptions & {
160
+ static estimateServerResponseTimeByOrigin(records: NetworkRequest[], options?: (RTTEstimateOptions & {
160
161
  rttByOrigin?: Map<string, number> | undefined;
161
162
  }) | undefined): Map<string, Summary>;
162
163
  /**
@@ -164,32 +165,32 @@ export class NetworkAnalyzer {
164
165
  * Excludes data URI, failed or otherwise incomplete, and cached requests.
165
166
  * Returns Infinity if there were no analyzable network records.
166
167
  *
167
- * @param {Array<Lantern.NetworkRequest>} networkRecords
168
+ * @param {Array<NetworkRequest>} networkRecords
168
169
  * @return {number}
169
170
  */
170
- static estimateThroughput(networkRecords: Array<import("../../../../types/internal/lantern.js").NetworkRequest<any>>): number;
171
+ static estimateThroughput(networkRecords: Array<NetworkRequest>): number;
171
172
  /**
172
- * @template {Lantern.NetworkRequest} T
173
+ * @template {NetworkRequest} T
173
174
  * @param {Array<T>} records
174
175
  * @param {string} resourceUrl
175
176
  * @return {T|undefined}
176
177
  */
177
- static findResourceForUrl<T extends import("../../../../types/internal/lantern.js").NetworkRequest<any>>(records: T[], resourceUrl: string): T | undefined;
178
+ static findResourceForUrl<T extends import("../../../../types/internal/lantern.js").Lantern.NetworkRequest<any>>(records: T[], resourceUrl: string): T | undefined;
178
179
  /**
179
- * @template {Lantern.NetworkRequest} T
180
+ * @template {NetworkRequest} T
180
181
  * @param {Array<T>} records
181
182
  * @param {string} resourceUrl
182
183
  * @return {T|undefined}
183
184
  */
184
- static findLastDocumentForUrl<T_1 extends import("../../../../types/internal/lantern.js").NetworkRequest<any>>(records: T_1[], resourceUrl: string): T_1 | undefined;
185
+ static findLastDocumentForUrl<T_1 extends import("../../../../types/internal/lantern.js").Lantern.NetworkRequest<any>>(records: T_1[], resourceUrl: string): T_1 | undefined;
185
186
  /**
186
187
  * Resolves redirect chain given a main document.
187
188
  * See: {@link NetworkAnalyzer.findLastDocumentForUrl}) for how to retrieve main document.
188
189
  *
189
- * @template {Lantern.NetworkRequest} T
190
+ * @template {NetworkRequest} T
190
191
  * @param {T} request
191
192
  * @return {T}
192
193
  */
193
- static resolveRedirects<T_2 extends import("../../../../types/internal/lantern.js").NetworkRequest<any>>(request: T_2): T_2;
194
+ static resolveRedirects<T_2 extends import("../../../../types/internal/lantern.js").Lantern.NetworkRequest<any>>(request: T_2): T_2;
194
195
  }
195
196
  //# sourceMappingURL=network-analyzer.d.ts.map
@@ -4,7 +4,8 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import * as Lantern from '../lantern.js';
7
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
8
+
8
9
  import UrlUtils from '../../url-utils.js';
9
10
 
10
11
  const INITIAL_CWD = 14 * 1024;
@@ -32,8 +33,8 @@ class NetworkAnalyzer {
32
33
  }
33
34
 
34
35
  /**
35
- * @param {Lantern.NetworkRequest[]} records
36
- * @return {Map<string, Lantern.NetworkRequest[]>}
36
+ * @param {NetworkRequest[]} records
37
+ * @return {Map<string, NetworkRequest[]>}
37
38
  */
38
39
  static groupByOrigin(records) {
39
40
  const grouped = new Map();
@@ -88,10 +89,10 @@ class NetworkAnalyzer {
88
89
  return summaryByKey;
89
90
  }
90
91
 
91
- /** @typedef {{record: Lantern.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
92
+ /** @typedef {{record: NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
92
93
 
93
94
  /**
94
- * @param {Lantern.NetworkRequest[]} records
95
+ * @param {NetworkRequest[]} records
95
96
  * @param {(e: RequestInfo) => number | number[] | undefined} iteratee
96
97
  * @return {Map<string, number[]>}
97
98
  */
@@ -250,7 +251,7 @@ class NetworkAnalyzer {
250
251
  /**
251
252
  * Given the RTT to each origin, estimates the observed server response times.
252
253
  *
253
- * @param {Lantern.NetworkRequest[]} records
254
+ * @param {NetworkRequest[]} records
254
255
  * @param {Map<string, number>} rttByOrigin
255
256
  * @return {Map<string, number[]>}
256
257
  */
@@ -271,7 +272,7 @@ class NetworkAnalyzer {
271
272
  }
272
273
 
273
274
  /**
274
- * @param {Lantern.NetworkRequest[]} records
275
+ * @param {NetworkRequest[]} records
275
276
  * @return {boolean}
276
277
  */
277
278
  static canTrustConnectionInformation(records) {
@@ -291,7 +292,7 @@ class NetworkAnalyzer {
291
292
  * Returns a map of requestId -> connectionReused, estimating the information if the information
292
293
  * available in the records themselves appears untrustworthy.
293
294
  *
294
- * @param {Lantern.NetworkRequest[]} records
295
+ * @param {NetworkRequest[]} records
295
296
  * @param {{forceCoarseEstimates: boolean}} [options]
296
297
  * @return {Map<string, boolean>}
297
298
  */
@@ -335,7 +336,7 @@ class NetworkAnalyzer {
335
336
  * Attempts to use the most accurate information first and falls back to coarser estimates when it
336
337
  * is unavailable.
337
338
  *
338
- * @param {Lantern.NetworkRequest[]} records
339
+ * @param {NetworkRequest[]} records
339
340
  * @param {RTTEstimateOptions} [options]
340
341
  * @return {Map<string, Summary>}
341
342
  */
@@ -416,7 +417,7 @@ class NetworkAnalyzer {
416
417
  * Estimates the server response time of each origin. RTT times can be passed in or will be
417
418
  * estimated automatically if not provided.
418
419
  *
419
- * @param {Lantern.NetworkRequest[]} records
420
+ * @param {NetworkRequest[]} records
420
421
  * @param {RTTEstimateOptions & {rttByOrigin?: Map<string, number>}} [options]
421
422
  * @return {Map<string, Summary>}
422
423
  */
@@ -442,7 +443,7 @@ class NetworkAnalyzer {
442
443
  * Excludes data URI, failed or otherwise incomplete, and cached requests.
443
444
  * Returns Infinity if there were no analyzable network records.
444
445
  *
445
- * @param {Array<Lantern.NetworkRequest>} networkRecords
446
+ * @param {Array<NetworkRequest>} networkRecords
446
447
  * @return {number}
447
448
  */
448
449
  static estimateThroughput(networkRecords) {
@@ -495,7 +496,7 @@ class NetworkAnalyzer {
495
496
  }
496
497
 
497
498
  /**
498
- * @template {Lantern.NetworkRequest} T
499
+ * @template {NetworkRequest} T
499
500
  * @param {Array<T>} records
500
501
  * @param {string} resourceUrl
501
502
  * @return {T|undefined}
@@ -509,7 +510,7 @@ class NetworkAnalyzer {
509
510
  }
510
511
 
511
512
  /**
512
- * @template {Lantern.NetworkRequest} T
513
+ * @template {NetworkRequest} T
513
514
  * @param {Array<T>} records
514
515
  * @param {string} resourceUrl
515
516
  * @return {T|undefined}
@@ -529,7 +530,7 @@ class NetworkAnalyzer {
529
530
  * Resolves redirect chain given a main document.
530
531
  * See: {@link NetworkAnalyzer.findLastDocumentForUrl}) for how to retrieve main document.
531
532
  *
532
- * @template {Lantern.NetworkRequest} T
533
+ * @template {NetworkRequest} T
533
534
  * @param {T} request
534
535
  * @return {T}
535
536
  */
@@ -1,9 +1,16 @@
1
+ export type NetworkRequest = import('../../../../types/internal/lantern.js').Lantern.NetworkRequest;
2
+ export type SimulationOptions = import('../../../../types/internal/lantern.js').Lantern.Simulation.Options;
3
+ export type SimulationNodeTiming = import('../../../../types/internal/lantern.js').Lantern.Simulation.NodeTiming;
4
+ export type SimulationResult<T> = import('../../../../types/internal/lantern.js').Lantern.Simulation.Result<T>;
1
5
  export type Node = import('../base-node.js').Node;
2
6
  export type NetworkNode = import('../network-node.js').NetworkNode;
3
7
  export type CpuNode = import('../cpu-node.js').CPUNode;
4
8
  export type CompleteNodeTiming = import('./simulator-timing-map.js').CpuNodeTimingComplete | import('./simulator-timing-map.js').NetworkNodeTimingComplete;
5
9
  export type ConnectionTiming = import('./simulator-timing-map.js').ConnectionTiming;
6
- export class Simulator {
10
+ /**
11
+ * @template [T=any]
12
+ */
13
+ export class Simulator<T = any> {
7
14
  /** @return {Map<string, Map<Node, CompleteNodeTiming>>} */
8
15
  static get ALL_NODE_TIMINGS(): Map<string, Map<Node, CompleteNodeTiming>>;
9
16
  /**
@@ -14,11 +21,11 @@ export class Simulator {
14
21
  */
15
22
  static _computeNodeStartPosition(node: Node): number;
16
23
  /**
17
- * @param {LH.Gatherer.Simulation.Options} [options]
24
+ * @param {SimulationOptions} [options]
18
25
  */
19
- constructor(options?: LH.Gatherer.Simulation.Options | undefined);
20
- /** @type {Required<LH.Gatherer.Simulation.Options>} */
21
- _options: Required<LH.Gatherer.Simulation.Options>;
26
+ constructor(options?: import("../../../../types/internal/lantern.js").Lantern.Simulation.Options | undefined);
27
+ /** @type {Required<SimulationOptions>} */
28
+ _options: Required<SimulationOptions>;
22
29
  _rtt: number;
23
30
  _throughput: number;
24
31
  _maximumConcurrentRequests: number;
@@ -67,10 +74,10 @@ export class Simulator {
67
74
  */
68
75
  _markNodeAsComplete(node: Node, endTime: number, connectionTiming?: import("./simulator-timing-map.js").ConnectionTiming | undefined): void;
69
76
  /**
70
- * @param {Lantern.NetworkRequest} record
77
+ * @param {NetworkRequest} record
71
78
  * @return {?TcpConnection}
72
79
  */
73
- _acquireConnection(record: import("../../../../types/internal/lantern.js").NetworkRequest<any>): TcpConnection | null;
80
+ _acquireConnection(record: NetworkRequest): TcpConnection | null;
74
81
  /**
75
82
  * @return {Node[]}
76
83
  */
@@ -114,16 +121,16 @@ export class Simulator {
114
121
  */
115
122
  _updateProgressMadeInTimePeriod(node: Node, timePeriodLength: number, totalElapsedTime: number): number | void;
116
123
  /**
117
- * @return {{nodeTimings: Map<Node, LH.Gatherer.Simulation.NodeTiming>, completeNodeTimings: Map<Node, CompleteNodeTiming>}}
124
+ * @return {{nodeTimings: Map<Node, SimulationNodeTiming>, completeNodeTimings: Map<Node, CompleteNodeTiming>}}
118
125
  */
119
126
  _computeFinalNodeTimings(): {
120
- nodeTimings: Map<Node, LH.Gatherer.Simulation.NodeTiming>;
127
+ nodeTimings: Map<Node, SimulationNodeTiming>;
121
128
  completeNodeTimings: Map<Node, CompleteNodeTiming>;
122
129
  };
123
130
  /**
124
- * @return {Required<LH.Gatherer.Simulation.Options>}
131
+ * @return {Required<SimulationOptions>}
125
132
  */
126
- getOptions(): Required<LH.Gatherer.Simulation.Options>;
133
+ getOptions(): Required<SimulationOptions>;
127
134
  /**
128
135
  * Estimates the time taken to process all of the graph's nodes, returns the overall time along with
129
136
  * each node annotated by start/end times.
@@ -135,18 +142,17 @@ export class Simulator {
135
142
  *
136
143
  * @param {Node} graph
137
144
  * @param {{flexibleOrdering?: boolean, label?: string}=} options
138
- * @return {LH.Gatherer.Simulation.Result}
145
+ * @return {SimulationResult<T>}
139
146
  */
140
147
  simulate(graph: Node, options?: {
141
148
  flexibleOrdering?: boolean;
142
149
  label?: string;
143
- } | undefined): LH.Gatherer.Simulation.Result;
150
+ } | undefined): SimulationResult<T>;
144
151
  /**
145
152
  * @param {number} wastedBytes
146
153
  */
147
154
  computeWastedMsFromWastedBytes(wastedBytes: number): number;
148
155
  }
149
- import * as LH from '../../../../types/lh.js';
150
156
  import { SimulatorTimingMap } from './simulator-timing-map.js';
151
157
  import { DNSCache } from './dns-cache.js';
152
158
  import { ConnectionPool } from './connection-pool.js';
@@ -4,8 +4,13 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import * as Lantern from '../lantern.js';
8
- import * as LH from '../../../../types/lh.js';
7
+ // This could be replaced by jsdoc namespace import, when ready.
8
+ // https://github.com/microsoft/TypeScript/issues/41825
9
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
10
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.Simulation.Options} SimulationOptions */
11
+ /** @typedef {import('../../../../types/internal/lantern.js').Lantern.Simulation.NodeTiming} SimulationNodeTiming */
12
+ /** @template T @typedef {import('../../../../types/internal/lantern.js').Lantern.Simulation.Result<T>} SimulationResult */
13
+
9
14
  import {BaseNode} from '../base-node.js';
10
15
  import {TcpConnection} from './tcp-connection.js';
11
16
  import {ConnectionPool} from './connection-pool.js';
@@ -47,12 +52,15 @@ const PriorityStartTimePenalty = {
47
52
  /** @type {Map<string, Map<Node, CompleteNodeTiming>>} */
48
53
  const ALL_SIMULATION_NODE_TIMINGS = new Map();
49
54
 
55
+ /**
56
+ * @template [T=any]
57
+ */
50
58
  class Simulator {
51
59
  /**
52
- * @param {LH.Gatherer.Simulation.Options} [options]
60
+ * @param {SimulationOptions} [options]
53
61
  */
54
62
  constructor(options) {
55
- /** @type {Required<LH.Gatherer.Simulation.Options>} */
63
+ /** @type {Required<SimulationOptions>} */
56
64
  this._options = Object.assign(
57
65
  {
58
66
  rtt: mobileSlow4G.rttMs,
@@ -102,7 +110,7 @@ class Simulator {
102
110
  * @param {Node} graph
103
111
  */
104
112
  _initializeConnectionPool(graph) {
105
- /** @type {Lantern.NetworkRequest[]} */
113
+ /** @type {NetworkRequest[]} */
106
114
  const records = [];
107
115
  graph.getRootNode().traverse(node => {
108
116
  if (node.type === BaseNode.TYPES.NETWORK) {
@@ -191,7 +199,7 @@ class Simulator {
191
199
  }
192
200
 
193
201
  /**
194
- * @param {Lantern.NetworkRequest} record
202
+ * @param {NetworkRequest} record
195
203
  * @return {?TcpConnection}
196
204
  */
197
205
  _acquireConnection(record) {
@@ -385,7 +393,7 @@ class Simulator {
385
393
  }
386
394
 
387
395
  /**
388
- * @return {{nodeTimings: Map<Node, LH.Gatherer.Simulation.NodeTiming>, completeNodeTimings: Map<Node, CompleteNodeTiming>}}
396
+ * @return {{nodeTimings: Map<Node, SimulationNodeTiming>, completeNodeTimings: Map<Node, CompleteNodeTiming>}}
389
397
  */
390
398
  _computeFinalNodeTimings() {
391
399
  /** @type {Array<[Node, CompleteNodeTiming]>} */
@@ -396,8 +404,8 @@ class Simulator {
396
404
  // Most consumers will want the entries sorted by startTime, so insert them in that order
397
405
  completeNodeTimingEntries.sort((a, b) => a[1].startTime - b[1].startTime);
398
406
 
399
- // Trimmed version of type `LH.Gatherer.Simulation.NodeTiming`.
400
- /** @type {Array<[Node, LH.Gatherer.Simulation.NodeTiming]>} */
407
+ // Trimmed version of type `SimulationNodeTiming`.
408
+ /** @type {Array<[Node, SimulationNodeTiming]>} */
401
409
  const nodeTimingEntries = completeNodeTimingEntries.map(([node, timing]) => {
402
410
  return [node, {
403
411
  startTime: timing.startTime,
@@ -413,7 +421,7 @@ class Simulator {
413
421
  }
414
422
 
415
423
  /**
416
- * @return {Required<LH.Gatherer.Simulation.Options>}
424
+ * @return {Required<SimulationOptions>}
417
425
  */
418
426
  getOptions() {
419
427
  return this._options;
@@ -430,7 +438,7 @@ class Simulator {
430
438
  *
431
439
  * @param {Node} graph
432
440
  * @param {{flexibleOrdering?: boolean, label?: string}=} options
433
- * @return {LH.Gatherer.Simulation.Result}
441
+ * @return {SimulationResult<T>}
434
442
  */
435
443
  simulate(graph, options) {
436
444
  if (BaseNode.hasCycle(graph)) {
@@ -10,7 +10,7 @@ import log from 'lighthouse-logger';
10
10
 
11
11
  import * as LH from '../../types/lh.js';
12
12
  import {NetworkRequest} from './network-request.js';
13
- import {PageDependencyGraph} from '../computed/page-dependency-graph.js';
13
+ import {PageDependencyGraph} from '../lib/lantern/page-dependency-graph.js';
14
14
 
15
15
  /**
16
16
  * @typedef {{
@@ -1,3 +1,4 @@
1
+ export type LanternNetworkRequest<T> = import('../../types/internal/lantern.js').Lantern.NetworkRequest<T>;
1
2
  export type HeaderEntry = {
2
3
  name: string;
3
4
  value: string;
@@ -49,9 +50,9 @@ export class NetworkRequest {
49
50
  static get TYPES(): LH.Util.SelfMap<LH.Crdp.Network.ResourceType>;
50
51
  /**
51
52
  * @param {NetworkRequest} record
52
- * @return {Lantern.NetworkRequest<NetworkRequest>}
53
+ * @return {LanternNetworkRequest<NetworkRequest>}
53
54
  */
54
- static asLanternNetworkRequest(record: NetworkRequest): import("../../types/internal/lantern.js").NetworkRequest<any>;
55
+ static asLanternNetworkRequest(record: NetworkRequest): LanternNetworkRequest<NetworkRequest>;
55
56
  /**
56
57
  * @param {NetworkRequest} record
57
58
  * @return {boolean}
@@ -258,6 +259,7 @@ export namespace NetworkRequest {
258
259
  export { HEADER_PROTOCOL_IS_H2 };
259
260
  }
260
261
  import * as LH from '../../types/lh.js';
262
+ /** @template T @typedef {import('../../types/internal/lantern.js').Lantern.NetworkRequest<T>} LanternNetworkRequest */
261
263
  declare const HEADER_TCP: "X-TCPMs";
262
264
  declare const HEADER_SSL: "X-SSLMs";
263
265
  declare const HEADER_REQ: "X-RequestMs";
@@ -53,9 +53,10 @@
53
53
  */
54
54
 
55
55
  import * as LH from '../../types/lh.js';
56
- import * as Lantern from './lantern/lantern.js';
57
56
  import UrlUtils from './url-utils.js';
58
57
 
58
+ /** @template T @typedef {import('../../types/internal/lantern.js').Lantern.NetworkRequest<T>} LanternNetworkRequest */
59
+
59
60
  // Lightrider X-Header names for timing information.
60
61
  // See: _updateTransferSizeForLightrider and _updateTimingsForLightrider.
61
62
  const HEADER_TCP = 'X-TCPMs'; // Note: this should have been called something like ConnectMs, as it includes SSL.
@@ -571,7 +572,7 @@ class NetworkRequest {
571
572
 
572
573
  /**
573
574
  * @param {NetworkRequest} record
574
- * @return {Lantern.NetworkRequest<NetworkRequest>}
575
+ * @return {LanternNetworkRequest<NetworkRequest>}
575
576
  */
576
577
  static asLanternNetworkRequest(record) {
577
578
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lighthouse",
3
3
  "type": "module",
4
- "version": "11.6.0-dev.20240304",
4
+ "version": "11.6.0-dev.20240306",
5
5
  "description": "Automated auditing, performance metrics, and best practices for the web.",
6
6
  "main": "./core/index.js",
7
7
  "bin": {
package/tsconfig.json CHANGED
@@ -69,6 +69,7 @@
69
69
  "core/test/lib/i18n/i18n-test.js",
70
70
  "core/test/lib/icons-test.js",
71
71
  "core/test/lib/lantern/base-node-test.js",
72
+ "core/test/lib/lantern/page-dependency-graph-test.js",
72
73
  "core/test/lib/lantern/simulator/connection-pool-test.js",
73
74
  "core/test/lib/lantern/simulator/dns-cache-test.js",
74
75
  "core/test/lib/lantern/simulator/network-analyzer-test.js",