From 00de512aaa4bf54ab107037390e11db3a73e8485 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 28 Feb 2024 15:05:40 -0800 Subject: [PATCH] core(lantern): move NetworkRequest to lib/dependency-graph --- .eslintrc.cjs | 2 +- .../efficient-animated-content.js | 2 +- .../byte-efficiency/offscreen-images.js | 2 +- .../render-blocking-resources.js | 2 +- .../byte-efficiency/total-byte-weight.js | 2 +- .../byte-efficiency/uses-long-cache-ttl.js | 2 +- .../byte-efficiency/uses-responsive-images.js | 2 +- core/audits/dobetterweb/uses-http2.js | 2 +- core/audits/is-on-https.js | 2 +- core/audits/prioritize-lcp-image.js | 2 +- core/audits/uses-rel-preload.js | 2 +- core/computed/critical-request-chains.js | 2 +- core/computed/metrics/lantern-interactive.js | 2 +- core/computed/metrics/lantern-metric.js | 2 +- core/computed/page-dependency-graph.js | 2 +- core/computed/resource-summary.js | 2 +- core/gather/driver/network-monitor.js | 2 +- core/gather/driver/network.js | 2 +- .../gatherers/dobetterweb/optimized-images.js | 2 +- .../dobetterweb/response-compression.js | 2 +- core/gather/gatherers/script-elements.js | 2 +- core/lib/dependency-graph/network-node.js | 8 ++--- .../{ => dependency-graph}/network-request.js | 6 ++-- .../simulator/connection-pool.js | 11 ++++--- .../dependency-graph/simulator/dns-cache.js | 6 ++-- .../simulator/network-analyzer.js | 33 ++++++++++--------- .../dependency-graph/simulator/simulator.js | 5 +-- core/lib/dependency-graph/types.d.ts | 7 ++++ core/lib/dependency-graph/types.js | 7 ++++ core/lib/navigation-error.js | 2 +- core/lib/network-recorder.js | 2 +- core/lib/script-helpers.js | 2 +- core/lib/tracehouse/task-summary.js | 2 +- core/lib/url-utils.js | 2 +- .../efficient-animated-content-test.js | 2 +- .../render-blocking-resources-test.js | 2 +- .../uses-long-cache-ttl-test.js | 2 +- .../computed/critical-request-chains-test.js | 2 +- core/test/computed/image-records-test.js | 2 +- .../computed/page-dependency-graph-test.js | 2 +- .../gather/driver/network-monitor-test.js | 2 +- .../dobetterweb/response-compression-test.js | 2 +- .../gather/gatherers/script-elements-test.js | 2 +- core/test/lib/navigation-error-test.js | 2 +- core/test/lib/network-recorder-test.js | 2 +- core/test/lib/network-request-test.js | 2 +- core/test/network-records-to-devtools-log.js | 2 +- types/artifacts.d.ts | 2 +- 48 files changed, 90 insertions(+), 73 deletions(-) rename core/lib/{ => dependency-graph}/network-request.js (99%) create mode 100644 core/lib/dependency-graph/types.d.ts create mode 100644 core/lib/dependency-graph/types.js diff --git a/.eslintrc.cjs b/.eslintrc.cjs index af71feccf169..ae8e16ac4841 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -76,7 +76,7 @@ module.exports = { vars: 'all', args: 'after-used', argsIgnorePattern: '(^reject$|^_+$)', - varsIgnorePattern: '(^_$|^LH$)', + varsIgnorePattern: '(^_$|^LH$|^Lantern$)', }], 'no-cond-assign': 2, 'space-infix-ops': 2, diff --git a/core/audits/byte-efficiency/efficient-animated-content.js b/core/audits/byte-efficiency/efficient-animated-content.js index 2138d24a5513..eb1f02d487ba 100644 --- a/core/audits/byte-efficiency/efficient-animated-content.js +++ b/core/audits/byte-efficiency/efficient-animated-content.js @@ -8,7 +8,7 @@ */ -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {ByteEfficiencyAudit} from './byte-efficiency-audit.js'; import * as i18n from '../../lib/i18n/i18n.js'; diff --git a/core/audits/byte-efficiency/offscreen-images.js b/core/audits/byte-efficiency/offscreen-images.js index 8acb5edd7890..94144debe103 100644 --- a/core/audits/byte-efficiency/offscreen-images.js +++ b/core/audits/byte-efficiency/offscreen-images.js @@ -10,7 +10,7 @@ import {ByteEfficiencyAudit} from './byte-efficiency-audit.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {Sentry} from '../../lib/sentry.js'; import UrlUtils from '../../lib/url-utils.js'; import * as i18n from '../../lib/i18n/i18n.js'; diff --git a/core/audits/byte-efficiency/render-blocking-resources.js b/core/audits/byte-efficiency/render-blocking-resources.js index a4f14f674c3a..ea2371c13d98 100644 --- a/core/audits/byte-efficiency/render-blocking-resources.js +++ b/core/audits/byte-efficiency/render-blocking-resources.js @@ -13,7 +13,7 @@ import {Audit} from '../audit.js'; import * as i18n from '../../lib/i18n/i18n.js'; import {BaseNode} from '../../lib/dependency-graph/base-node.js'; import {UnusedCSS} from '../../computed/unused-css.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {ProcessedNavigation} from '../../computed/processed-navigation.js'; import {LoadSimulator} from '../../computed/load-simulator.js'; import {FirstContentfulPaint} from '../../computed/metrics/first-contentful-paint.js'; diff --git a/core/audits/byte-efficiency/total-byte-weight.js b/core/audits/byte-efficiency/total-byte-weight.js index ab6d6289f39b..1a55c5b3206d 100644 --- a/core/audits/byte-efficiency/total-byte-weight.js +++ b/core/audits/byte-efficiency/total-byte-weight.js @@ -6,7 +6,7 @@ import {Audit} from '../audit.js'; import * as i18n from '../../lib/i18n/i18n.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {NetworkRecords} from '../../computed/network-records.js'; import {Util} from '../../../shared/util.js'; diff --git a/core/audits/byte-efficiency/uses-long-cache-ttl.js b/core/audits/byte-efficiency/uses-long-cache-ttl.js index f850f3220cd5..f92316156379 100644 --- a/core/audits/byte-efficiency/uses-long-cache-ttl.js +++ b/core/audits/byte-efficiency/uses-long-cache-ttl.js @@ -7,7 +7,7 @@ import parseCacheControl from 'parse-cache-control'; import {Audit} from '../audit.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import UrlUtils from '../../lib/url-utils.js'; import {linearInterpolation} from '../../../shared/statistics.js'; import * as i18n from '../../lib/i18n/i18n.js'; diff --git a/core/audits/byte-efficiency/uses-responsive-images.js b/core/audits/byte-efficiency/uses-responsive-images.js index 7d1aebd85750..548c756fb234 100644 --- a/core/audits/byte-efficiency/uses-responsive-images.js +++ b/core/audits/byte-efficiency/uses-responsive-images.js @@ -14,7 +14,7 @@ import {ByteEfficiencyAudit} from './byte-efficiency-audit.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {ImageRecords} from '../../computed/image-records.js'; import UrlUtils from '../../lib/url-utils.js'; import * as i18n from '../../lib/i18n/i18n.js'; diff --git a/core/audits/dobetterweb/uses-http2.js b/core/audits/dobetterweb/uses-http2.js index 81ef8d474278..31cb854ad1db 100644 --- a/core/audits/dobetterweb/uses-http2.js +++ b/core/audits/dobetterweb/uses-http2.js @@ -16,7 +16,7 @@ import {Audit} from '../audit.js'; import {EntityClassification} from '../../computed/entity-classification.js'; import UrlUtils from '../../lib/url-utils.js'; import {LanternInteractive} from '../../computed/metrics/lantern-interactive.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {NetworkRecords} from '../../computed/network-records.js'; import {LoadSimulator} from '../../computed/load-simulator.js'; import {PageDependencyGraph} from '../../computed/page-dependency-graph.js'; diff --git a/core/audits/is-on-https.js b/core/audits/is-on-https.js index 82019c22fe0b..0f3cc17b5f63 100644 --- a/core/audits/is-on-https.js +++ b/core/audits/is-on-https.js @@ -6,7 +6,7 @@ import {Audit} from './audit.js'; import UrlUtils from '../lib/url-utils.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {NetworkRecords} from '../computed/network-records.js'; import * as i18n from '../lib/i18n/i18n.js'; diff --git a/core/audits/prioritize-lcp-image.js b/core/audits/prioritize-lcp-image.js index 2b61a209471f..d93601dc71f1 100644 --- a/core/audits/prioritize-lcp-image.js +++ b/core/audits/prioritize-lcp-image.js @@ -6,7 +6,7 @@ import {Audit} from './audit.js'; import * as i18n from '../lib/i18n/i18n.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {MainResource} from '../computed/main-resource.js'; import {LanternLargestContentfulPaint} from '../computed/metrics/lantern-largest-contentful-paint.js'; import {LoadSimulator} from '../computed/load-simulator.js'; diff --git a/core/audits/uses-rel-preload.js b/core/audits/uses-rel-preload.js index 8582616be956..606c66c4d3bd 100644 --- a/core/audits/uses-rel-preload.js +++ b/core/audits/uses-rel-preload.js @@ -5,7 +5,7 @@ */ import UrlUtils from '../lib/url-utils.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {Audit} from './audit.js'; import {CriticalRequestChains} from '../computed/critical-request-chains.js'; import * as i18n from '../lib/i18n/i18n.js'; diff --git a/core/computed/critical-request-chains.js b/core/computed/critical-request-chains.js index 05635f16a9e7..af5fa1092371 100644 --- a/core/computed/critical-request-chains.js +++ b/core/computed/critical-request-chains.js @@ -5,7 +5,7 @@ */ import {makeComputedArtifact} from './computed-artifact.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {MainResource} from './main-resource.js'; import {PageDependencyGraph} from './page-dependency-graph.js'; diff --git a/core/computed/metrics/lantern-interactive.js b/core/computed/metrics/lantern-interactive.js index de008726662c..67d67e1eabf4 100644 --- a/core/computed/metrics/lantern-interactive.js +++ b/core/computed/metrics/lantern-interactive.js @@ -7,7 +7,7 @@ import {makeComputedArtifact} from '../computed-artifact.js'; import {LanternMetric} from './lantern-metric.js'; import {BaseNode} from '../../lib/dependency-graph/base-node.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {LanternFirstMeaningfulPaint} from './lantern-first-meaningful-paint.js'; /** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */ diff --git a/core/computed/metrics/lantern-metric.js b/core/computed/metrics/lantern-metric.js index 1f8197fd6fd7..9ce6c68675b3 100644 --- a/core/computed/metrics/lantern-metric.js +++ b/core/computed/metrics/lantern-metric.js @@ -5,7 +5,7 @@ */ import {BaseNode} from '../../lib/dependency-graph/base-node.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {ProcessedNavigation} from '../processed-navigation.js'; import {PageDependencyGraph} from '../page-dependency-graph.js'; import {LoadSimulator} from '../load-simulator.js'; diff --git a/core/computed/page-dependency-graph.js b/core/computed/page-dependency-graph.js index 0428c993e854..da94c23804f1 100644 --- a/core/computed/page-dependency-graph.js +++ b/core/computed/page-dependency-graph.js @@ -8,7 +8,7 @@ import {makeComputedArtifact} from './computed-artifact.js'; import {NetworkNode} from '../lib/dependency-graph/network-node.js'; import {CPUNode} from '../lib/dependency-graph/cpu-node.js'; import {TraceProcessor} from '../lib/tracehouse/trace-processor.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {ProcessedTrace} from './processed-trace.js'; import {NetworkRecords} from './network-records.js'; import {NetworkAnalyzer} from '../lib/dependency-graph/simulator/network-analyzer.js'; diff --git a/core/computed/resource-summary.js b/core/computed/resource-summary.js index ed50bd4629a7..78f9c46e9c37 100644 --- a/core/computed/resource-summary.js +++ b/core/computed/resource-summary.js @@ -7,7 +7,7 @@ import {EntityClassification} from './entity-classification.js'; import {makeComputedArtifact} from './computed-artifact.js'; import {NetworkRecords} from './network-records.js'; -import {NetworkRequest} from '../lib/network-request.js'; +import {NetworkRequest} from '../lib/dependency-graph/network-request.js'; import {Budget} from '../config/budget.js'; import UrlUtils from '../lib/url-utils.js'; diff --git a/core/gather/driver/network-monitor.js b/core/gather/driver/network-monitor.js index 8c6dc73f22f8..f9eb11e68f9d 100644 --- a/core/gather/driver/network-monitor.js +++ b/core/gather/driver/network-monitor.js @@ -15,7 +15,7 @@ import log from 'lighthouse-logger'; import * as LH from '../../../types/lh.js'; import {NetworkRecorder} from '../../lib/network-recorder.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import UrlUtils from '../../lib/url-utils.js'; /** @typedef {import('../../lib/network-recorder.js').NetworkRecorderEventMap} NetworkRecorderEventMap */ diff --git a/core/gather/driver/network.js b/core/gather/driver/network.js index f9e88cba6134..4be7988576a5 100644 --- a/core/gather/driver/network.js +++ b/core/gather/driver/network.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; /** * Return the body of the response with the given ID. Rejects if getting the diff --git a/core/gather/gatherers/dobetterweb/optimized-images.js b/core/gather/gatherers/dobetterweb/optimized-images.js index 037c3526db26..ca28d9224a62 100644 --- a/core/gather/gatherers/dobetterweb/optimized-images.js +++ b/core/gather/gatherers/dobetterweb/optimized-images.js @@ -14,7 +14,7 @@ import log from 'lighthouse-logger'; import BaseGatherer from '../../base-gatherer.js'; import UrlUtils from '../../../lib/url-utils.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; import {Sentry} from '../../../lib/sentry.js'; import {NetworkRecords} from '../../../computed/network-records.js'; import DevtoolsLog from '../devtools-log.js'; diff --git a/core/gather/gatherers/dobetterweb/response-compression.js b/core/gather/gatherers/dobetterweb/response-compression.js index 2b5631219675..c39cd98b296b 100644 --- a/core/gather/gatherers/dobetterweb/response-compression.js +++ b/core/gather/gatherers/dobetterweb/response-compression.js @@ -17,7 +17,7 @@ import log from 'lighthouse-logger'; import BaseGatherer from '../../base-gatherer.js'; import UrlUtils from '../../../lib/url-utils.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; import DevtoolsLog from '../devtools-log.js'; import {fetchResponseBodyFromCache} from '../../driver/network.js'; import {NetworkRecords} from '../../../computed/network-records.js'; diff --git a/core/gather/gatherers/script-elements.js b/core/gather/gatherers/script-elements.js index 83ef33d8683c..9bbbf0aaa3c6 100644 --- a/core/gather/gatherers/script-elements.js +++ b/core/gather/gatherers/script-elements.js @@ -6,7 +6,7 @@ import BaseGatherer from '../base-gatherer.js'; import {NetworkRecords} from '../../computed/network-records.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {pageFunctions} from '../../lib/page-functions.js'; import DevtoolsLog from './devtools-log.js'; diff --git a/core/lib/dependency-graph/network-node.js b/core/lib/dependency-graph/network-node.js index 3d5405532273..77831353c57f 100644 --- a/core/lib/dependency-graph/network-node.js +++ b/core/lib/dependency-graph/network-node.js @@ -4,13 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as LH from '../../../types/lh.js'; +import * as Lantern from './types.js'; import {BaseNode} from './base-node.js'; -import {NetworkRequest} from '../network-request.js'; +import {NetworkRequest} from './network-request.js'; class NetworkNode extends BaseNode { /** - * @param {LH.Artifacts.NetworkRequest} networkRecord + * @param {Lantern.NetworkRequest} networkRecord */ constructor(networkRecord) { super(networkRecord.requestId); @@ -37,7 +37,7 @@ class NetworkNode extends BaseNode { } /** - * @return {LH.Artifacts.NetworkRequest} + * @return {Lantern.NetworkRequest} */ get record() { return this._record; diff --git a/core/lib/network-request.js b/core/lib/dependency-graph/network-request.js similarity index 99% rename from core/lib/network-request.js rename to core/lib/dependency-graph/network-request.js index 5374f3c7bcc5..4d74fce4534e 100644 --- a/core/lib/network-request.js +++ b/core/lib/dependency-graph/network-request.js @@ -52,8 +52,8 @@ Trace: ResourceFinish.ts */ -import * as LH from '../../types/lh.js'; -import UrlUtils from './url-utils.js'; +import * as LH from '../../../types/lh.js'; +import UrlUtils from '../url-utils.js'; // Lightrider X-Header names for timing information. // See: _updateTransferSizeForLightrider and _updateTimingsForLightrider. @@ -569,7 +569,7 @@ class NetworkRequest { } /** - * @param {NetworkRequest} record + * @param {{protocol: string, parsedURL: ParsedURL}} record * @return {boolean} */ static isNonNetworkRequest(record) { diff --git a/core/lib/dependency-graph/simulator/connection-pool.js b/core/lib/dependency-graph/simulator/connection-pool.js index fc61ec770518..9d7195653d6f 100644 --- a/core/lib/dependency-graph/simulator/connection-pool.js +++ b/core/lib/dependency-graph/simulator/connection-pool.js @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Lantern from '../types.js'; import * as LH from '../../../../types/lh.js'; import {NetworkAnalyzer} from './network-analyzer.js'; import {TcpConnection} from './tcp-connection.js'; @@ -17,7 +18,7 @@ const CONNECTIONS_PER_ORIGIN = 6; export class ConnectionPool { /** - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {Required} options */ constructor(records, options) { @@ -26,7 +27,7 @@ export class ConnectionPool { this._records = records; /** @type {Map} */ this._connectionsByOrigin = new Map(); - /** @type {Map} */ + /** @type {Map} */ this._connectionsByRecord = new Map(); this._connectionsInUse = new Set(); this._connectionReusedByRequestId = NetworkAnalyzer.estimateIfConnectionWasReused(records, { @@ -124,7 +125,7 @@ export class ConnectionPool { * If ignoreConnectionReused is true, acquire will consider all connections not in use as available. * Otherwise, only connections that have matching "warmth" are considered available. * - * @param {LH.Artifacts.NetworkRequest} record + * @param {Lantern.NetworkRequest} record * @param {{ignoreConnectionReused?: boolean}} options * @return {?TcpConnection} */ @@ -150,7 +151,7 @@ export class ConnectionPool { * Return the connection currently being used to fetch a record. If no connection * currently being used for this record, an error will be thrown. * - * @param {LH.Artifacts.NetworkRequest} record + * @param {Lantern.NetworkRequest} record * @return {TcpConnection} */ acquireActiveConnectionFromRecord(record) { @@ -161,7 +162,7 @@ export class ConnectionPool { } /** - * @param {LH.Artifacts.NetworkRequest} record + * @param {Lantern.NetworkRequest} record */ release(record) { const connection = this._connectionsByRecord.get(record); diff --git a/core/lib/dependency-graph/simulator/dns-cache.js b/core/lib/dependency-graph/simulator/dns-cache.js index d405f76f9fb5..4b1394d786ec 100644 --- a/core/lib/dependency-graph/simulator/dns-cache.js +++ b/core/lib/dependency-graph/simulator/dns-cache.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import * as LH from '../../../../types/lh.js'; +import * as Lantern from '../types.js'; // A DNS lookup will usually take ~1-2 roundtrips of connection latency plus the extra DNS routing time. // Example: https://www.webpagetest.org/result/180703_3A_e33ec79747c002ed4d7bcbfc81462203/1/details/#waterfall_view_step1 @@ -25,7 +25,7 @@ class DNSCache { } /** - * @param {LH.Artifacts.NetworkRequest} request + * @param {Lantern.NetworkRequest} request * @param {{requestedAt: number, shouldUpdateCache: boolean}=} options * @return {number} */ @@ -47,7 +47,7 @@ class DNSCache { } /** - * @param {LH.Artifacts.NetworkRequest} request + * @param {Lantern.NetworkRequest} request * @param {number} resolvedAt */ _updateCacheResolvedAtIfNeeded(request, resolvedAt) { diff --git a/core/lib/dependency-graph/simulator/network-analyzer.js b/core/lib/dependency-graph/simulator/network-analyzer.js index 2b574a600d36..ee259fa54a54 100644 --- a/core/lib/dependency-graph/simulator/network-analyzer.js +++ b/core/lib/dependency-graph/simulator/network-analyzer.js @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Lantern from '../types.js'; import UrlUtils from '../../url-utils.js'; const INITIAL_CWD = 14 * 1024; @@ -31,8 +32,8 @@ class NetworkAnalyzer { } /** - * @param {LH.Artifacts.NetworkRequest[]} records - * @return {Map} + * @param {Lantern.NetworkRequest[]} records + * @return {Map} */ static groupByOrigin(records) { const grouped = new Map(); @@ -87,10 +88,10 @@ class NetworkAnalyzer { return summaryByKey; } - /** @typedef {{record: LH.Artifacts.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */ + /** @typedef {{record: Lantern.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */ /** - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {(e: RequestInfo) => number | number[] | undefined} iteratee * @return {Map} */ @@ -249,7 +250,7 @@ class NetworkAnalyzer { /** * Given the RTT to each origin, estimates the observed server response times. * - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {Map} rttByOrigin * @return {Map} */ @@ -270,7 +271,7 @@ class NetworkAnalyzer { } /** - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @return {boolean} */ static canTrustConnectionInformation(records) { @@ -290,7 +291,7 @@ class NetworkAnalyzer { * Returns a map of requestId -> connectionReused, estimating the information if the information * available in the records themselves appears untrustworthy. * - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {{forceCoarseEstimates: boolean}} [options] * @return {Map} */ @@ -334,7 +335,7 @@ class NetworkAnalyzer { * Attempts to use the most accurate information first and falls back to coarser estimates when it * is unavailable. * - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {RTTEstimateOptions} [options] * @return {Map} */ @@ -415,7 +416,7 @@ class NetworkAnalyzer { * Estimates the server response time of each origin. RTT times can be passed in or will be * estimated automatically if not provided. * - * @param {LH.Artifacts.NetworkRequest[]} records + * @param {Lantern.NetworkRequest[]} records * @param {RTTEstimateOptions & {rttByOrigin?: Map}} [options] * @return {Map} */ @@ -441,7 +442,7 @@ class NetworkAnalyzer { * Excludes data URI, failed or otherwise incomplete, and cached requests. * Returns Infinity if there were no analyzable network records. * - * @param {Array} networkRecords + * @param {Array} networkRecords * @return {number} */ static estimateThroughput(networkRecords) { @@ -494,9 +495,9 @@ class NetworkAnalyzer { } /** - * @param {Array} records + * @param {Array} records * @param {string} resourceUrl - * @return {LH.Artifacts.NetworkRequest|undefined} + * @return {Lantern.NetworkRequest|undefined} */ static findResourceForUrl(records, resourceUrl) { // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first @@ -507,9 +508,9 @@ class NetworkAnalyzer { } /** - * @param {Array} records + * @param {Array} records * @param {string} resourceUrl - * @return {LH.Artifacts.NetworkRequest|undefined} + * @return {Lantern.NetworkRequest|undefined} */ static findLastDocumentForUrl(records, resourceUrl) { // equalWithExcludedFragments is expensive, so check that the resourceUrl starts with the request url first @@ -526,8 +527,8 @@ class NetworkAnalyzer { * Resolves redirect chain given a main document. * See: {@link NetworkAnalyzer.findLastDocumentForUrl}) for how to retrieve main document. * - * @param {LH.Artifacts.NetworkRequest} request - * @return {LH.Artifacts.NetworkRequest} + * @param {Lantern.NetworkRequest} request + * @return {Lantern.NetworkRequest} */ static resolveRedirects(request) { while (request.redirectDestination) request = request.redirectDestination; diff --git a/core/lib/dependency-graph/simulator/simulator.js b/core/lib/dependency-graph/simulator/simulator.js index ff14f35e0b74..842a936218b3 100644 --- a/core/lib/dependency-graph/simulator/simulator.js +++ b/core/lib/dependency-graph/simulator/simulator.js @@ -5,6 +5,7 @@ */ import * as LH from '../../../../types/lh.js'; +import * as Lantern from '../types.js'; import {BaseNode} from '../base-node.js'; import {TcpConnection} from './tcp-connection.js'; import {ConnectionPool} from './connection-pool.js'; @@ -101,7 +102,7 @@ class Simulator { * @param {Node} graph */ _initializeConnectionPool(graph) { - /** @type {LH.Artifacts.NetworkRequest[]} */ + /** @type {Lantern.NetworkRequest[]} */ const records = []; graph.getRootNode().traverse(node => { if (node.type === BaseNode.TYPES.NETWORK) { @@ -190,7 +191,7 @@ class Simulator { } /** - * @param {LH.Artifacts.NetworkRequest} record + * @param {Lantern.NetworkRequest} record * @return {?TcpConnection} */ _acquireConnection(record) { diff --git a/core/lib/dependency-graph/types.d.ts b/core/lib/dependency-graph/types.d.ts new file mode 100644 index 000000000000..3db2fa0b2227 --- /dev/null +++ b/core/lib/dependency-graph/types.d.ts @@ -0,0 +1,7 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +export type NetworkRequest = LH.Artifacts.NetworkRequest; diff --git a/core/lib/dependency-graph/types.js b/core/lib/dependency-graph/types.js new file mode 100644 index 000000000000..2740c5b56c64 --- /dev/null +++ b/core/lib/dependency-graph/types.js @@ -0,0 +1,7 @@ +/** + * @license + * Copyright 2024 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +export {}; diff --git a/core/lib/navigation-error.js b/core/lib/navigation-error.js index d7fc35c3ce47..b33f7b2ae017 100644 --- a/core/lib/navigation-error.js +++ b/core/lib/navigation-error.js @@ -6,7 +6,7 @@ import {LighthouseError} from './lh-error.js'; import {NetworkAnalyzer} from './dependency-graph/simulator/network-analyzer.js'; -import {NetworkRequest} from './network-request.js'; +import {NetworkRequest} from './dependency-graph/network-request.js'; import * as i18n from '../lib/i18n/i18n.js'; const UIStrings = { diff --git a/core/lib/network-recorder.js b/core/lib/network-recorder.js index fa0b3af8bd4c..742ba50e35ea 100644 --- a/core/lib/network-recorder.js +++ b/core/lib/network-recorder.js @@ -9,7 +9,7 @@ import {EventEmitter} from 'events'; import log from 'lighthouse-logger'; import * as LH from '../../types/lh.js'; -import {NetworkRequest} from './network-request.js'; +import {NetworkRequest} from './dependency-graph/network-request.js'; import {PageDependencyGraph} from '../computed/page-dependency-graph.js'; /** diff --git a/core/lib/script-helpers.js b/core/lib/script-helpers.js index 5329f5fd046e..dadee6150feb 100644 --- a/core/lib/script-helpers.js +++ b/core/lib/script-helpers.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {NetworkRequest} from './network-request.js'; +import {NetworkRequest} from './dependency-graph/network-request.js'; /** * @param {LH.Artifacts.Script} script diff --git a/core/lib/tracehouse/task-summary.js b/core/lib/tracehouse/task-summary.js index 187df6b61ee3..a95a3d487200 100644 --- a/core/lib/tracehouse/task-summary.js +++ b/core/lib/tracehouse/task-summary.js @@ -8,7 +8,7 @@ * @fileoverview Utility functions for grouping and summarizing tasks. */ -import {NetworkRequest} from '../network-request.js'; +import {NetworkRequest} from '../dependency-graph/network-request.js'; // These trace events, when not triggered by a script inside a particular task, are just general Chrome overhead. const BROWSER_TASK_NAMES_SET = new Set([ diff --git a/core/lib/url-utils.js b/core/lib/url-utils.js index cd379b38e0f1..5deb695d148f 100644 --- a/core/lib/url-utils.js +++ b/core/lib/url-utils.js @@ -9,7 +9,7 @@ import {getDomain} from 'tldts-icann'; import {Util} from '../../shared/util.js'; import {LighthouseError} from './lh-error.js'; -/** @typedef {import('./network-request.js').NetworkRequest} NetworkRequest */ +/** @typedef {import('./dependency-graph/network-request.js').NetworkRequest} NetworkRequest */ const allowedProtocols = [ 'https:', 'http:', 'chrome:', 'chrome-extension:', diff --git a/core/test/audits/byte-efficiency/efficient-animated-content-test.js b/core/test/audits/byte-efficiency/efficient-animated-content-test.js index 8dff0e2c858c..f22a2b1b5e28 100644 --- a/core/test/audits/byte-efficiency/efficient-animated-content-test.js +++ b/core/test/audits/byte-efficiency/efficient-animated-content-test.js @@ -8,7 +8,7 @@ import assert from 'assert/strict'; import EfficientAnimatedContent from '../../../audits/byte-efficiency/efficient-animated-content.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; describe('Page uses videos for animated GIFs', () => { it('should flag gifs above 100kb as unoptimized', async () => { diff --git a/core/test/audits/byte-efficiency/render-blocking-resources-test.js b/core/test/audits/byte-efficiency/render-blocking-resources-test.js index cd63fa5d9f83..2985c1a000ee 100644 --- a/core/test/audits/byte-efficiency/render-blocking-resources-test.js +++ b/core/test/audits/byte-efficiency/render-blocking-resources-test.js @@ -11,7 +11,7 @@ import * as constants from '../../../config/constants.js'; import {NetworkNode} from '../../../lib/dependency-graph/network-node.js'; import {CPUNode} from '../../../lib/dependency-graph/cpu-node.js'; import {Simulator} from '../../../lib/dependency-graph/simulator/simulator.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; import {getURLArtifactFromDevtoolsLog, readJson} from '../../test-utils.js'; const trace = readJson('../../fixtures/traces/progressive-app-m60.json', import.meta); diff --git a/core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js b/core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js index 1b8f1799e286..8b5b255a9baf 100644 --- a/core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js +++ b/core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js @@ -7,7 +7,7 @@ import assert from 'assert/strict'; import CacheHeadersAudit from '../../../audits/byte-efficiency/uses-long-cache-ttl.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; import {networkRecordsToDevtoolsLog} from '../../network-records-to-devtools-log.js'; const options = CacheHeadersAudit.defaultOptions; diff --git a/core/test/computed/critical-request-chains-test.js b/core/test/computed/critical-request-chains-test.js index 448df62f2681..ad969c8ed381 100644 --- a/core/test/computed/critical-request-chains-test.js +++ b/core/test/computed/critical-request-chains-test.js @@ -7,7 +7,7 @@ import assert from 'assert/strict'; import {CriticalRequestChains} from '../../computed/critical-request-chains.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {createTestTrace} from '../create-test-trace.js'; import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js'; import {getURLArtifactFromDevtoolsLog, readJson} from '../test-utils.js'; diff --git a/core/test/computed/image-records-test.js b/core/test/computed/image-records-test.js index 29eee214f550..7058872a9270 100644 --- a/core/test/computed/image-records-test.js +++ b/core/test/computed/image-records-test.js @@ -5,7 +5,7 @@ */ import {ImageRecords} from '../../computed/image-records.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; /** * @param {Partial=} partial diff --git a/core/test/computed/page-dependency-graph-test.js b/core/test/computed/page-dependency-graph-test.js index 97951065e092..4fdd0f2f4725 100644 --- a/core/test/computed/page-dependency-graph-test.js +++ b/core/test/computed/page-dependency-graph-test.js @@ -8,7 +8,7 @@ import assert from 'assert/strict'; import {PageDependencyGraph} from '../../computed/page-dependency-graph.js'; import {BaseNode} from '../../lib/dependency-graph/base-node.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {getURLArtifactFromDevtoolsLog, readJson} from '../test-utils.js'; const sampleTrace = readJson('../fixtures/traces/iframe-m79.trace.json', import.meta); diff --git a/core/test/gather/driver/network-monitor-test.js b/core/test/gather/driver/network-monitor-test.js index 80337d65cb94..5bbdafdce73b 100644 --- a/core/test/gather/driver/network-monitor-test.js +++ b/core/test/gather/driver/network-monitor-test.js @@ -6,7 +6,7 @@ import {createMockCdpSession} from '../mock-driver.js'; import {NetworkMonitor} from '../../../gather/driver/network-monitor.js'; -import {NetworkRequest} from '../../../lib/network-request.js'; +import {NetworkRequest} from '../../../lib/dependency-graph/network-request.js'; import {networkRecordsToDevtoolsLog} from '../../network-records-to-devtools-log.js'; import {TargetManager} from '../../../gather/driver/target-manager.js'; diff --git a/core/test/gather/gatherers/dobetterweb/response-compression-test.js b/core/test/gather/gatherers/dobetterweb/response-compression-test.js index f3f93d2f8ab8..394377118e80 100644 --- a/core/test/gather/gatherers/dobetterweb/response-compression-test.js +++ b/core/test/gather/gatherers/dobetterweb/response-compression-test.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {NetworkRequest} from '../../../../lib/network-request.js'; +import {NetworkRequest} from '../../../../lib/dependency-graph/network-request.js'; import {createMockContext, mockDriverSubmodules} from '../../../gather/mock-driver.js'; const mocks = await mockDriverSubmodules(); diff --git a/core/test/gather/gatherers/script-elements-test.js b/core/test/gather/gatherers/script-elements-test.js index a51d0819351d..d65b3ad54974 100644 --- a/core/test/gather/gatherers/script-elements-test.js +++ b/core/test/gather/gatherers/script-elements-test.js @@ -12,7 +12,7 @@ const mocks = await mockDriverSubmodules(); // https://github.com/GoogleChrome/lighthouse/blob/main/docs/hacking-tips.md#mocking-modules-with-testdouble /** @typedef {import('../../../gather/gatherers/script-elements.js').default} ScriptElements */ const ScriptElements = (await import('../../../gather/gatherers/script-elements.js')).default; -const {NetworkRequest} = await import('../../../lib/network-request.js'); +const {NetworkRequest} = await import('../../../lib/dependency-graph/network-request.js'); /** * @param {Partial=} partial diff --git a/core/test/lib/navigation-error-test.js b/core/test/lib/navigation-error-test.js index 51aa9c68362c..456412440ed4 100644 --- a/core/test/lib/navigation-error-test.js +++ b/core/test/lib/navigation-error-test.js @@ -10,7 +10,7 @@ import { getPageLoadError, getNonHtmlError, } from '../../lib/navigation-error.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; const LoadFailureMode = /** @type {const} */ ({ fatal: 'fatal', diff --git a/core/test/lib/network-recorder-test.js b/core/test/lib/network-recorder-test.js index 3eba3bc9d464..fa5aeaae4f7b 100644 --- a/core/test/lib/network-recorder-test.js +++ b/core/test/lib/network-recorder-test.js @@ -9,7 +9,7 @@ import assert from 'assert/strict'; import {NetworkRecorder} from '../../lib/network-recorder.js'; import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js'; import {readJson} from '../test-utils.js'; -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; const devtoolsLogItems = readJson('../fixtures/artifacts/perflog/defaultPass.devtoolslog.json', import.meta); const prefetchedScriptDevtoolsLog = readJson('../fixtures/prefetched-script.devtoolslog.json', import.meta); diff --git a/core/test/lib/network-request-test.js b/core/test/lib/network-request-test.js index cc25dd691889..4297b06910cd 100644 --- a/core/test/lib/network-request-test.js +++ b/core/test/lib/network-request-test.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {NetworkRequest} from '../../lib/network-request.js'; +import {NetworkRequest} from '../../lib/dependency-graph/network-request.js'; import {NetworkRecorder} from '../../lib/network-recorder.js'; import {networkRecordsToDevtoolsLog} from '../network-records-to-devtools-log.js'; diff --git a/core/test/network-records-to-devtools-log.js b/core/test/network-records-to-devtools-log.js index 7b4fdfba9eda..efd3088f6130 100644 --- a/core/test/network-records-to-devtools-log.js +++ b/core/test/network-records-to-devtools-log.js @@ -9,7 +9,7 @@ import assert from 'assert/strict'; import {NetworkRecorder} from '../../core/lib/network-recorder.js'; -/** @typedef {import('../../core/lib/network-request.js').NetworkRequest} NetworkRequest */ +/** @typedef {import('../lib/dependency-graph/network-request.js').NetworkRequest} NetworkRequest */ const idBase = '127122'; const exampleUrl = 'https://testingurl.com/'; diff --git a/types/artifacts.d.ts b/types/artifacts.d.ts index c0207607f476..e1c80b134813 100644 --- a/types/artifacts.d.ts +++ b/types/artifacts.d.ts @@ -11,7 +11,7 @@ import {LayoutShiftRootCausesData} from '@paulirish/trace_engine/models/trace/ro import {parseManifest} from '../core/lib/manifest-parser.js'; import {Simulator} from '../core/lib/dependency-graph/simulator/simulator.js'; import {LighthouseError} from '../core/lib/lh-error.js'; -import {NetworkRequest as _NetworkRequest} from '../core/lib/network-request.js'; +import {NetworkRequest as _NetworkRequest} from '../core/lib/dependency-graph/network-request.js'; import speedline from 'speedline-core'; import * as CDTSourceMap from '../core/lib/cdt/generated/SourceMap.js'; import {ArbitraryEqualityMap} from '../core/lib/arbitrary-equality-map.js';