Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lantern): refactor to DevTools modules convention #16071

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/audits/byte-efficiency/byte-efficiency-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {LCPImageRecord} from '../../computed/lcp-image-record.js';

const str_ = i18n.createIcuMessageFn(import.meta.url, {});

/** @typedef {import('../../lib/lantern/simulator/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/simulation/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/BaseNode.js').Node<LH.Artifacts.NetworkRequest>} Node */

// Parameters for log-normal distribution scoring. These values were determined by fitting the
Expand Down
4 changes: 2 additions & 2 deletions core/audits/byte-efficiency/render-blocking-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import {Audit} from '../audit.js';
import * as i18n from '../../lib/i18n/i18n.js';
import {BaseNode} from '../../lib/lantern/BaseNode.js';
import {BaseNode} from '../../lib/lantern/lantern.js';
import {UnusedCSS} from '../../computed/unused-css.js';
import {NetworkRequest} from '../../lib/network-request.js';
import {LoadSimulator} from '../../computed/load-simulator.js';
Expand All @@ -20,7 +20,7 @@ import {LCPImageRecord} from '../../computed/lcp-image-record.js';
import {NavigationInsights} from '../../computed/navigation-insights.js';


/** @typedef {import('../../lib/lantern/simulator/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/simulation/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/BaseNode.js').Node<LH.Artifacts.NetworkRequest>} Node */
/** @typedef {import('../../lib/lantern/NetworkNode.js').NetworkNode<LH.Artifacts.NetworkRequest>} NetworkNode */

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 @@ -9,7 +9,7 @@
* origin are over the http/2 protocol.
*/

/** @typedef {import('../../lib/lantern/simulator/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/simulation/Simulator.js').Simulator} Simulator */
/** @typedef {import('../../lib/lantern/BaseNode.js').Node<LH.Artifacts.NetworkRequest>} Node */

import {Audit} from '../audit.js';
Expand Down
2 changes: 1 addition & 1 deletion core/audits/long-tasks.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 Lantern from '../lib/lantern/types/lantern.js';
import * as Lantern from '../lib/lantern/lantern.js';
import {Audit} from './audit.js';
import {NetworkRecords} from '../computed/network-records.js';
import * as i18n from '../lib/i18n/i18n.js';
Expand Down
5 changes: 3 additions & 2 deletions core/computed/document-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {NetworkAnalyzer} from '../lib/lantern/simulator/NetworkAnalyzer.js';
import * as Lantern from '../lib/lantern/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {NetworkRecords} from './network-records.js';
import {ProcessedTrace} from './processed-trace.js';
Expand Down Expand Up @@ -41,7 +41,8 @@ class DocumentUrls {
}
if (!requestedUrl || !mainDocumentUrl) throw new Error('No main frame navigations found');

const initialRequest = NetworkAnalyzer.findResourceForUrl(networkRecords, requestedUrl);
const initialRequest =
Lantern.Simulation.NetworkAnalyzer.findResourceForUrl(networkRecords, requestedUrl);
if (initialRequest?.redirects?.length) requestedUrl = initialRequest.redirects[0].url;

return {requestedUrl, mainDocumentUrl};
Expand Down
6 changes: 3 additions & 3 deletions core/computed/load-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*/

import {makeComputedArtifact} from './computed-artifact.js';
import {Simulator} from '../lib/lantern/simulator/Simulator.js';
import * as Lantern from '../lib/lantern/lantern.js';
import {NetworkAnalysis} from './network-analysis.js';

class LoadSimulator {
/**
* @param {{devtoolsLog: LH.DevtoolsLog, settings: LH.Audit.Context['settings']}} data
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<Simulator>}
* @return {Promise<Lantern.Simulation.Simulator>}
*/
static async compute_(data, context) {
const networkAnalysis = await NetworkAnalysis.request(data.devtoolsLog, context);
return Simulator.createSimulator({...data.settings, networkAnalysis});
return Lantern.Simulation.Simulator.createSimulator({...data.settings, networkAnalysis});
}

/**
Expand Down
5 changes: 3 additions & 2 deletions core/computed/main-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {NetworkRecords} from './network-records.js';
import {NetworkAnalyzer} from '../lib/lantern/simulator/NetworkAnalyzer.js';

/**
* @fileoverview This artifact identifies the main resource on the page. Current solution assumes
Expand All @@ -28,7 +28,8 @@ class MainResource {
// document request, we should return the last candidate here. Besides, the browser
// would have evicted the first request by the time `MainDocumentRequest` (a consumer
// of this computed artifact) attempts to fetch the contents, resulting in a protocol error.
const mainResource = NetworkAnalyzer.findLastDocumentForUrl(records, mainDocumentUrl);
const mainResource =
Lantern.Simulation.NetworkAnalyzer.findLastDocumentForUrl(records, mainDocumentUrl);
if (!mainResource) {
throw new Error('Unable to identify the main resource');
}
Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-first-contentful-paint.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 Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {getComputationDataParams, lanternErrorAdapter} from './lantern-metric.js';
import {FirstContentfulPaint} from '../../lib/lantern/metrics/FirstContentfulPaint.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternFirstContentfulPaint extends FirstContentfulPaint {
class LanternFirstContentfulPaint extends Lantern.Metrics.FirstContentfulPaint {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {LanternLargestContentfulPaint} from './lantern-largest-contentful-paint.js';
import {Interactive} from '../../lib/lantern/metrics/Interactive.js';
import {getComputationDataParams, lanternErrorAdapter} from './lantern-metric.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternInteractive extends Interactive {
class LanternInteractive extends Lantern.Metrics.Interactive {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-largest-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {LargestContentfulPaint} from '../../lib/lantern/metrics/LargestContentfulPaint.js';
import {getComputationDataParams, lanternErrorAdapter} from './lantern-metric.js';
import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternLargestContentfulPaint extends LargestContentfulPaint {
class LanternLargestContentfulPaint extends Lantern.Metrics.LargestContentfulPaint {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {MaxPotentialFID} from '../../lib/lantern/metrics/MaxPotentialFID.js';
import {getComputationDataParams, lanternErrorAdapter} from './lantern-metric.js';
import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternMaxPotentialFID extends MaxPotentialFID {
class LanternMaxPotentialFID extends Lantern.Metrics.MaxPotentialFID {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
8 changes: 4 additions & 4 deletions core/computed/metrics/lantern-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {LanternError} from '../../lib/lantern/LanternError.js';
import * as Lantern from '../../lib/lantern/lantern.js';
import {LighthouseError} from '../../lib/lh-error.js';
import {LoadSimulator} from '../load-simulator.js';
import {ProcessedNavigation} from '../processed-navigation.js';
import {PageDependencyGraph} from '../page-dependency-graph.js';
import {TraceEngineResult} from '../trace-engine-result.js';
import {createProcessedNavigation} from '../../lib/lantern/TraceEngineComputationData.js';

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
Expand Down Expand Up @@ -39,7 +38,8 @@ async function getComputationDataParamsFromTrace(data, context) {

const graph = await PageDependencyGraph.request({...data, fromTrace: true}, context);
const traceEngineResult = await TraceEngineResult.request(data, context);
const processedNavigation = createProcessedNavigation(traceEngineResult.data);
const processedNavigation =
Lantern.TraceEngineComputationData.createProcessedNavigation(traceEngineResult.data);
const simulator = data.simulator || (await LoadSimulator.request(data, context));

return {simulator, graph, processedNavigation};
Expand All @@ -50,7 +50,7 @@ async function getComputationDataParamsFromTrace(data, context) {
* @return {never}
*/
function lanternErrorAdapter(err) {
if (!(err instanceof LanternError)) {
if (!(err instanceof Lantern.Error)) {
throw err;
}

Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {getComputationDataParams, lanternErrorAdapter} from './lantern-metric.js';
import {Speedline} from '../speedline.js';
import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';
import {SpeedIndex} from '../../lib/lantern/metrics/SpeedIndex.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternSpeedIndex extends SpeedIndex {
class LanternSpeedIndex extends Lantern.Metrics.SpeedIndex {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
4 changes: 2 additions & 2 deletions core/computed/metrics/lantern-total-blocking-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {TotalBlockingTime} from '../../lib/lantern/metrics/TotalBlockingTime.js';
import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';
import {LanternInteractive} from './lantern-interactive.js';
import {getComputationDataParams} from './lantern-metric.js';

/** @typedef {import('../../lib/lantern/Metric.js').Extras} Extras */

class LanternTotalBlockingTime extends TotalBlockingTime {
class LanternTotalBlockingTime extends Lantern.Metrics.TotalBlockingTime {
/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Artifacts.ComputedContext} context
Expand Down
4 changes: 3 additions & 1 deletion core/computed/metrics/total-blocking-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../../lib/lantern/lantern.js';
import {makeComputedArtifact} from '../computed-artifact.js';
import ComputedMetric from './metric.js';
import {TraceProcessor} from '../../lib/tracehouse/trace-processor.js';
import {LanternTotalBlockingTime} from './lantern-total-blocking-time.js';
import {Interactive} from './interactive.js';
import {calculateSumOfBlockingTime} from '../../lib/lantern/TBTUtils.js';

const {calculateSumOfBlockingTime} = Lantern.TBTUtils;

/**
* @fileoverview This audit determines Total Blocking Time.
Expand Down
4 changes: 2 additions & 2 deletions core/computed/network-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {NetworkAnalyzer} from '../lib/lantern/simulator/NetworkAnalyzer.js';
import {NetworkRecords} from './network-records.js';

class NetworkAnalysis {
Expand All @@ -16,7 +16,7 @@ class NetworkAnalysis {
*/
static async compute_(devtoolsLog, context) {
const records = await NetworkRecords.request(devtoolsLog, context);
return NetworkAnalyzer.analyze(records);
return Lantern.Simulation.NetworkAnalyzer.analyze(records);
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {PageDependencyGraph as LanternPageDependencyGraph} from '../lib/lantern/PageDependencyGraph.js';
import {NetworkRequest} from '../lib/network-request.js';
import {ProcessedTrace} from './processed-trace.js';
import {NetworkRecords} from './network-records.js';
import {TraceEngineResult} from './trace-engine-result.js';
import * as TraceEngineComputationData from '../lib/lantern/TraceEngineComputationData.js';

/** @typedef {import('../lib/lantern/BaseNode.js').Node<LH.Artifacts.NetworkRequest>} Node */

Expand All @@ -30,14 +29,15 @@ class PageDependencyGraph {
if (data.fromTrace) {
const traceEngineResult = await TraceEngineResult.request({trace}, context);
const traceEngineData = traceEngineResult.data;
const requests = TraceEngineComputationData.createNetworkRequests(trace, traceEngineData);
const requests =
Lantern.TraceEngineComputationData.createNetworkRequests(trace, traceEngineData);
const graph =
TraceEngineComputationData.createGraph(requests, trace, traceEngineData, URL);
Lantern.TraceEngineComputationData.createGraph(requests, trace, traceEngineData, URL);
return graph;
}

const lanternRequests = networkRecords.map(NetworkRequest.asLanternNetworkRequest);
return LanternPageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
return Lantern.PageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/computed/tbt-impact-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/types/lantern.js';
import * as Lantern from '../lib/lantern/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {MainThreadTasks} from './main-thread-tasks.js';
import {FirstContentfulPaint} from './metrics/first-contentful-paint.js';
import {Interactive} from './metrics/interactive.js';
import {TotalBlockingTime} from './metrics/total-blocking-time.js';
import {ProcessedTrace} from './processed-trace.js';
import {calculateTbtImpactForEvent} from '../lib/lantern/TBTUtils.js';

const {calculateTbtImpactForEvent} = Lantern.TBTUtils;

class TBTImpactTasks {
/**
Expand Down
2 changes: 1 addition & 1 deletion core/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as Lantern from '../lib/lantern/lantern.js';

const throttling = Lantern.constants.throttling;
const throttling = Lantern.Simulation.Constants.throttling;

/**
* @type {Required<LH.SharedFlagsSettings['screenEmulation']>}
Expand Down
4 changes: 2 additions & 2 deletions core/lib/asset-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {createGzip, gunzipSync} from 'zlib';

import log from 'lighthouse-logger';

import {Simulator} from './lantern/simulator/Simulator.js';
import * as Lantern from './lantern/lantern.js';
import lanternTraceSaver from './lantern-trace-saver.js';
import {MetricTraceEvents} from './traces/metric-trace-events.js';
import {NetworkAnalysis} from '../computed/network-analysis.js';
Expand Down Expand Up @@ -449,7 +449,7 @@ function saveDevtoolsLog(devtoolsLog, devtoolLogFilename, options = {}) {
async function saveLanternDebugTraces(pathWithBasename) {
if (!process.env.LANTERN_DEBUG) return;

for (const [label, nodeTimings] of Simulator.ALL_NODE_TIMINGS) {
for (const [label, nodeTimings] of Lantern.Simulation.Simulator.ALL_NODE_TIMINGS) {
if (lanternTraceSaver.simulationNamesToIgnore.includes(label)) continue;

const traceFilename = `${pathWithBasename}-${label}${traceSuffix}`;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/lantern-trace-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/** @typedef {import('./lantern/BaseNode.js').Node<LH.Artifacts.NetworkRequest>} Node */
/** @typedef {import('./lantern/simulator/Simulator.js').CompleteNodeTiming} CompleteNodeTiming */
/** @typedef {import('./lantern/simulation/Simulator.js').CompleteNodeTiming} CompleteNodeTiming */

/**
* @param {Map<Node, CompleteNodeTiming>} nodeTimings
Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/BaseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
* @template [T=any]
*/
class BaseNode {
static TYPES = /** @type {{NETWORK: 'network', CPU: 'cpu'}} */({
NETWORK: 'network',
CPU: 'cpu',
});

/**
* @param {string} id
*/
Expand Down Expand Up @@ -361,9 +366,4 @@ class BaseNode {
}
}

BaseNode.TYPES = /** @type {{NETWORK: 'network', CPU: 'cpu'}} */({
NETWORK: 'network',
CPU: 'cpu',
});

export {BaseNode};
Loading
Loading