Skip to content

Commit

Permalink
core(lantern): move NetworkRequest to lib/dependency-graph
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Feb 28, 2024
1 parent 88d0d97 commit 00de512
Show file tree
Hide file tree
Showing 48 changed files with 90 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/efficient-animated-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/offscreen-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/render-blocking-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/total-byte-weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/uses-long-cache-ttl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/uses-responsive-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/dobetterweb/uses-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/is-on-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion core/audits/prioritize-lcp-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/uses-rel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/computed/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion core/computed/metrics/lantern-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion core/computed/metrics/lantern-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/computed/resource-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion core/gather/driver/network-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion core/gather/driver/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/gather/gatherers/dobetterweb/optimized-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/gather/gatherers/dobetterweb/response-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion core/gather/gatherers/script-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions core/lib/dependency-graph/network-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,7 +37,7 @@ class NetworkNode extends BaseNode {
}

/**
* @return {LH.Artifacts.NetworkRequest}
* @return {Lantern.NetworkRequest}
*/
get record() {
return this._record;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -569,7 +569,7 @@ class NetworkRequest {
}

/**
* @param {NetworkRequest} record
* @param {{protocol: string, parsedURL: ParsedURL}} record
* @return {boolean}
*/
static isNonNetworkRequest(record) {
Expand Down
11 changes: 6 additions & 5 deletions core/lib/dependency-graph/simulator/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,7 +18,7 @@ const CONNECTIONS_PER_ORIGIN = 6;

export class ConnectionPool {
/**
* @param {LH.Artifacts.NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {Required<LH.Gatherer.Simulation.Options>} options
*/
constructor(records, options) {
Expand All @@ -26,7 +27,7 @@ export class ConnectionPool {
this._records = records;
/** @type {Map<string, TcpConnection[]>} */
this._connectionsByOrigin = new Map();
/** @type {Map<LH.Artifacts.NetworkRequest, TcpConnection>} */
/** @type {Map<Lantern.NetworkRequest, TcpConnection>} */
this._connectionsByRecord = new Map();
this._connectionsInUse = new Set();
this._connectionReusedByRequestId = NetworkAnalyzer.estimateIfConnectionWasReused(records, {
Expand Down Expand Up @@ -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}
*/
Expand All @@ -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) {
Expand All @@ -161,7 +162,7 @@ export class ConnectionPool {
}

/**
* @param {LH.Artifacts.NetworkRequest} record
* @param {Lantern.NetworkRequest} record
*/
release(record) {
const connection = this._connectionsByRecord.get(record);
Expand Down
6 changes: 3 additions & 3 deletions core/lib/dependency-graph/simulator/dns-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +25,7 @@ class DNSCache {
}

/**
* @param {LH.Artifacts.NetworkRequest} request
* @param {Lantern.NetworkRequest} request
* @param {{requestedAt: number, shouldUpdateCache: boolean}=} options
* @return {number}
*/
Expand All @@ -47,7 +47,7 @@ class DNSCache {
}

/**
* @param {LH.Artifacts.NetworkRequest} request
* @param {Lantern.NetworkRequest} request
* @param {number} resolvedAt
*/
_updateCacheResolvedAtIfNeeded(request, resolvedAt) {
Expand Down
Loading

0 comments on commit 00de512

Please sign in to comment.