Skip to content

Commit

Permalink
core(computed-artifact): remove settings and options from context (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored May 3, 2021
1 parent dee182a commit 5bd16c2
Show file tree
Hide file tree
Showing 42 changed files with 81 additions and 71 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Metrics extends Audit {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const summary = await ComputedTimingSummary
.request({trace, devtoolsLog}, context);
.request({trace, devtoolsLog, settings: context.settings}, context);
const metrics = summary.metrics;
const debugInfo = summary.debugInfo;

Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/performance-budget.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class ResourceBudget extends Audit {
*/
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const summary = await ResourceSummary.request({devtoolsLog, URL: artifacts.URL}, context);
const data = {devtoolsLog, URL: artifacts.URL, budgets: context.settings.budgets};
const summary = await ResourceSummary.request(data, context);
const mainResource = await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResource.url);

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/resource-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ResourceSummary extends Audit {
static async audit(artifacts, context) {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const summary = await ComputedResourceSummary
.request({devtoolsLog, URL: artifacts.URL}, context);
.request({devtoolsLog, URL: artifacts.URL, budgets: context.settings.budgets}, context);

/** @type {LH.Audit.Details.Table['headings']} */
const headings = [
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/timing-budget.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class TimingBudget extends Audit {
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const mainResource = await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
const summary = (await TimingSummary.request({trace, devtoolsLog}, context)).metrics;
const data = {trace, devtoolsLog, settings: context.settings};
const summary = (await TimingSummary.request(data, context)).metrics;
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResource.url);

if (!budget) {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/computed/computed-artifact.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const log = require('lighthouse-logger');
/**
* Decorate computableArtifact with a caching `request()` method which will
* automatically call `computableArtifact.compute_()` under the hood.
* @template {{name: string, compute_(artifacts: unknown, context: LH.Audit.Context): Promise<unknown>}} C
* @template {{name: string, compute_(artifacts: unknown, context: LH.Artifacts.ComputedContext): Promise<unknown>}} C
* @param {C} computableArtifact
*/
function makeComputedArtifact(computableArtifact) {
Expand All @@ -21,7 +21,7 @@ function makeComputedArtifact(computableArtifact) {
/**
* Return an automatically cached result from the computed artifact.
* @param {FirstParamType<C['compute_']>} artifacts
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {ReturnType<C['compute_']>}
*/
const request = (artifacts, context) => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CriticalRequestChains {

/**
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog, trace: LH.Trace}} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.CriticalRequestNode>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/layout-shift-variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class LayoutShiftVariants {

/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<{avgSessionGap5s: number, maxSessionGap1s: number, maxSessionGap1sLimit5s: number, maxSliding1s: number, maxSliding300ms: number}>}
*/
static async compute_(trace, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/load-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const NetworkAnalysis = require('./network-analysis.js');
class LoadSimulator {
/**
* @param {{devtoolsLog: LH.DevtoolsLog, settings: Immutable<LH.Config.Settings>}} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<Simulator>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/main-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const NetworkRecords = require('./network-records.js');
class MainResource {
/**
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog}} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.NetworkRequest>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/main-thread-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TraceOfTab = require('./trace-of-tab.js');
class MainThreadTasks {
/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<Array<LH.Artifacts.TaskNode>>}
*/
static async compute_(trace, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const LayoutShiftVariants = require('../layout-shift-variants.js');
class CumulativeLayoutShiftAllFrames {
/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<{value: number}>}
*/
static async compute_(trace, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LayoutShiftVariants = require('../layout-shift-variants.js');
class CumulativeLayoutShift {
/**
* @param {LH.Trace} trace
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<{value: number, debugInfo: Record<string,boolean> | null}>}
*/
static async compute_(trace, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EstimatedInputLatency extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/first-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js
class FirstContentfulPaint extends ComputedMetric {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/first-cpu-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class FirstCPUIdle extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const LanternFirstMeaningfulPaint = require('./lantern-first-meaningful-paint.js
class FirstMeaningfulPaint extends ComputedMetric {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Interactive extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LanternEstimatedInputLatency extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/lantern-first-cpu-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class LanternFirstCPUIdle extends LanternInteractive {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LanternFirstMeaningfulPaint extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/lantern-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class LanternInteractive extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class LanternLargestContentfulPaint extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LanternMaxPotentialFID extends LanternMetricArtifact {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/computed/metrics/lantern-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LanternMetricArtifact {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @param {Omit<Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
Expand Down Expand Up @@ -148,7 +148,7 @@ class LanternMetricArtifact {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/lantern-speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LanternSpeedIndex extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class LanternTotalBlockingTime extends LanternMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static async compute_(data, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LanternLargestContentfulPaint = require('./lantern-largest-contentful-pain
class LargestContentfulPaint extends ComputedMetric {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TracingProcessor = require('../../lib/tracehouse/trace-processor.js');
class MaxPotentialFID extends MetricArtifact {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/computed/metrics/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) { // eslint-disable-line no-unused-vars
Expand All @@ -32,7 +32,7 @@ class ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.Metric>}
*/
static computeObservedMetric(data, context) { // eslint-disable-line no-unused-vars
Expand All @@ -41,7 +41,7 @@ class ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric|LH.Artifacts.Metric>}
*/
static async compute_(data, context) {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/computed/metrics/speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Speedline = require('../speedline.js');
class SpeedIndex extends ComputedMetric {
/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand All @@ -22,7 +22,7 @@ class SpeedIndex extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.Metric>}
*/
static async computeObservedMetric(data, context) {
Expand Down
15 changes: 8 additions & 7 deletions lighthouse-core/computed/metrics/timing-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ class TimingSummary {
/**
* @param {LH.Trace} trace
* @param {LH.DevtoolsLog} devtoolsLog
* @param {LH.Audit.Context} context
* @param {ImmutableObject<LH.Config.Settings>} settings
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<{metrics: LH.Artifacts.TimingSummary, debugInfo: Record<string,boolean>}>}
*/
static async summarize(trace, devtoolsLog, context) {
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
static async summarize(trace, devtoolsLog, settings, context) {
const metricComputationData = {trace, devtoolsLog, settings};
/**
* @template TArtifacts
* @template TReturn
* @param {{request: (artifact: TArtifacts, context: LH.Audit.Context) => Promise<TReturn>}} Artifact
* @param {{request: (artifact: TArtifacts, context: LH.Artifacts.ComputedContext) => Promise<TReturn>}} Artifact
* @param {TArtifacts} artifact
* @return {Promise<TReturn|undefined>}
*/
Expand Down Expand Up @@ -141,12 +142,12 @@ class TimingSummary {
return {metrics, debugInfo};
}
/**
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog}} data
* @param {LH.Audit.Context} context
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog, settings: ImmutableObject<LH.Config.Settings>}} data
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<{metrics: LH.Artifacts.TimingSummary, debugInfo: Record<string,boolean>}>}
*/
static async compute_(data, context) {
return TimingSummary.summarize(data.trace, data.devtoolsLog, context);
return TimingSummary.summarize(data.trace, data.devtoolsLog, data.settings, context);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/computed/metrics/total-blocking-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TotalBlockingTime extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
static computeSimulatedMetric(data, context) {
Expand All @@ -88,7 +88,7 @@ class TotalBlockingTime extends ComputedMetric {

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.Metric>}
*/
static async computeObservedMetric(data, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/module-duplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ModuleDuplication {

/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
*/
static async compute_(artifacts, context) {
const bundles = await JsBundles.request(artifacts, context);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/network-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NetworkAnalysis {

/**
* @param {LH.DevtoolsLog} devtoolsLog
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<LH.Artifacts.NetworkAnalysis>}
*/
static async compute_(devtoolsLog, context) {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class PageDependencyGraph {

/**
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog}} data
* @param {LH.Audit.Context} context
* @param {LH.Artifacts.ComputedContext} context
* @return {Promise<Node>}
*/
static async compute_(data, context) {
Expand Down
Loading

0 comments on commit 5bd16c2

Please sign in to comment.