Skip to content

Commit 42e04dd

Browse files
committed
computed context
1 parent 45defa8 commit 42e04dd

10 files changed

+31
-22
lines changed

lighthouse-core/audits/metrics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Metrics extends Audit {
4444
const trace = artifacts.traces[Audit.DEFAULT_PASS];
4545
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
4646
const summary = await ComputedTimingSummary
47-
.request({trace, devtoolsLog}, context);
47+
.request({trace, devtoolsLog, settings: artifacts.settings}, context);
4848
const metrics = summary.metrics;
4949
const debugInfo = summary.debugInfo;
5050

lighthouse-core/audits/performance-budget.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class ResourceBudget extends Audit {
120120
*/
121121
static async audit(artifacts, context) {
122122
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
123-
const summary = await ResourceSummary.request({devtoolsLog, URL: artifacts.URL}, context);
123+
const data = {devtoolsLog, URL: artifacts.URL, settings: artifacts.settings};
124+
const summary = await ResourceSummary.request(data, context);
124125
const mainResource = await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
125126
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResource.url);
126127

lighthouse-core/audits/resource-summary.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ResourceSummary extends Audit {
4545
static async audit(artifacts, context) {
4646
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
4747
const summary = await ComputedResourceSummary
48-
.request({devtoolsLog, URL: artifacts.URL}, context);
48+
.request({devtoolsLog, URL: artifacts.URL, settings: artifacts.settings}, context);
4949

5050
/** @type {LH.Audit.Details.Table['headings']} */
5151
const headings = [

lighthouse-core/audits/timing-budget.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ class TimingBudget extends Audit {
143143
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
144144
const trace = artifacts.traces[Audit.DEFAULT_PASS];
145145
const mainResource = await MainResource.request({URL: artifacts.URL, devtoolsLog}, context);
146-
const summary = (await TimingSummary.request({trace, devtoolsLog}, context)).metrics;
146+
const data = {trace, devtoolsLog, settings: artifacts.settings};
147+
const summary = (await TimingSummary.request(data, context)).metrics;
147148
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResource.url);
148149

149150
if (!budget) {

lighthouse-core/computed/computed-artifact.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
const ArbitraryEqualityMap = require('../lib/arbitrary-equality-map.js');
99
const log = require('lighthouse-logger');
1010

11+
1112
/**
1213
* Decorate computableArtifact with a caching `request()` method which will
1314
* automatically call `computableArtifact.compute_()` under the hood.
14-
* @template {{name: string, compute_(artifacts: unknown, context: LH.Audit.Context): Promise<unknown>}} C
15+
* @template {{name: string, compute_(artifacts: unknown, context: LH.Gatherer.ComputedContext): Promise<unknown>}} C
1516
* @param {C} computableArtifact
1617
*/
1718
function makeComputedArtifact(computableArtifact) {
@@ -21,7 +22,7 @@ function makeComputedArtifact(computableArtifact) {
2122
/**
2223
* Return an automatically cached result from the computed artifact.
2324
* @param {FirstParamType<C['compute_']>} artifacts
24-
* @param {LH.Audit.Context} context
25+
* @param {LH.Gatherer.ComputedContext} context
2526
* @return {ReturnType<C['compute_']>}
2627
*/
2728
const request = (artifacts, context) => {

lighthouse-core/computed/metrics/metric.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ComputedMetric {
2323

2424
/**
2525
* @param {LH.Artifacts.MetricComputationData} data
26-
* @param {LH.Audit.Context} context
26+
* @param {LH.Gatherer.ComputedContext} context
2727
* @return {Promise<LH.Artifacts.LanternMetric>}
2828
*/
2929
static computeSimulatedMetric(data, context) { // eslint-disable-line no-unused-vars
@@ -32,7 +32,7 @@ class ComputedMetric {
3232

3333
/**
3434
* @param {LH.Artifacts.MetricComputationData} data
35-
* @param {LH.Audit.Context} context
35+
* @param {LH.Gatherer.ComputedContext} context
3636
* @return {Promise<LH.Artifacts.Metric>}
3737
*/
3838
static computeObservedMetric(data, context) { // eslint-disable-line no-unused-vars
@@ -41,7 +41,7 @@ class ComputedMetric {
4141

4242
/**
4343
* @param {LH.Artifacts.MetricComputationDataInput} data
44-
* @param {LH.Audit.Context} context
44+
* @param {LH.Gatherer.ComputedContext} context
4545
* @return {Promise<LH.Artifacts.LanternMetric|LH.Artifacts.Metric>}
4646
*/
4747
static async compute_(data, context) {

lighthouse-core/computed/metrics/timing-summary.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ class TimingSummary {
2727
/**
2828
* @param {LH.Trace} trace
2929
* @param {LH.DevtoolsLog} devtoolsLog
30-
* @param {LH.Audit.Context} context
30+
* @param {LH.Config.Settings} settings
31+
* @param {LH.Gatherer.ComputedContext} context
3132
* @return {Promise<{metrics: LH.Artifacts.TimingSummary, debugInfo: Record<string,boolean>}>}
3233
*/
33-
static async summarize(trace, devtoolsLog, context) {
34-
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
34+
static async summarize(trace, devtoolsLog, settings, context) {
35+
const metricComputationData = {trace, devtoolsLog, settings};
3536
/**
3637
* @template TArtifacts
3738
* @template TReturn
38-
* @param {{request: (artifact: TArtifacts, context: LH.Audit.Context) => Promise<TReturn>}} Artifact
39+
* @param {{request: (artifact: TArtifacts, context: LH.Gatherer.ComputedContext) => Promise<TReturn>}} Artifact
3940
* @param {TArtifacts} artifact
4041
* @return {Promise<TReturn|undefined>}
4142
*/
@@ -141,12 +142,12 @@ class TimingSummary {
141142
return {metrics, debugInfo};
142143
}
143144
/**
144-
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog}} data
145-
* @param {LH.Audit.Context} context
145+
* @param {{trace: LH.Trace, devtoolsLog: LH.DevtoolsLog, settings: LH.Config.Settings}} data
146+
* @param {LH.Gatherer.ComputedContext} context
146147
* @return {Promise<{metrics: LH.Artifacts.TimingSummary, debugInfo: Record<string,boolean>}>}
147148
*/
148149
static async compute_(data, context) {
149-
return TimingSummary.summarize(data.trace, data.devtoolsLog, context);
150+
return TimingSummary.summarize(data.trace, data.devtoolsLog, data.settings, context);
150151
}
151152
}
152153

lighthouse-core/computed/resource-summary.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class ResourceSummary {
3737
/**
3838
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
3939
* @param {string} mainResourceURL
40-
* @param {LH.Audit.Context} context
40+
* @param {LH.Config.Settings} settings
4141
* @return {Record<LH.Budget.ResourceType, ResourceEntry>}
4242
*/
43-
static summarize(networkRecords, mainResourceURL, context) {
43+
static summarize(networkRecords, mainResourceURL, settings) {
4444
/** @type {Record<LH.Budget.ResourceType, ResourceEntry>} */
4545
const resourceSummary = {
4646
'stylesheet': {count: 0, resourceSize: 0, transferSize: 0},
@@ -53,7 +53,7 @@ class ResourceSummary {
5353
'total': {count: 0, resourceSize: 0, transferSize: 0},
5454
'third-party': {count: 0, resourceSize: 0, transferSize: 0},
5555
};
56-
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResourceURL);
56+
const budget = Budget.getMatchingBudget(settings.budgets, mainResourceURL);
5757
/** @type {ReadonlyArray<string>} */
5858
let firstPartyHosts = [];
5959
if (budget && budget.options && budget.options.firstPartyHostnames) {
@@ -102,16 +102,16 @@ class ResourceSummary {
102102
}
103103

104104
/**
105-
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog}} data
106-
* @param {LH.Audit.Context} context
105+
* @param {{URL: LH.Artifacts['URL'], devtoolsLog: LH.DevtoolsLog, settings: LH.Config.Settings}} data
106+
* @param {LH.Gatherer.ComputedContext} context
107107
* @return {Promise<Record<LH.Budget.ResourceType,ResourceEntry>>}
108108
*/
109109
static async compute_(data, context) {
110110
const [networkRecords, mainResource] = await Promise.all([
111111
NetworkRecords.request(data.devtoolsLog, context),
112112
MainResource.request(data, context),
113113
]);
114-
return ResourceSummary.summarize(networkRecords, mainResource.url, context);
114+
return ResourceSummary.summarize(networkRecords, mainResource.url, data.settings);
115115
}
116116
}
117117

types/artifacts.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import _LanternSimulator = require('../lighthouse-core/lib/dependency-graph/simu
99
import _NetworkRequest = require('../lighthouse-core/lib/network-request.js');
1010
import speedline = require('speedline-core');
1111
import TextSourceMap = require('../lighthouse-core/lib/cdt/generated/SourceMap.js');
12+
import ArbitraryEqualityMap = require('../lighthouse-core/lib/arbitrary-equality-map.js');
1213

1314
type _TaskNode = import('../lighthouse-core/lib/tracehouse/main-thread-tasks.js').TaskNode;
1415

types/gatherer.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ declare global {
6363
baseArtifacts: BaseArtifacts;
6464
}
6565

66+
export type ComputedContext = Immutable<{
67+
computedCache: Map<string, ArbitraryEqualityMap>;
68+
}>;
69+
6670
export type CompatibilityContext = PassContext | FRTransitionalContext;
6771

6872
export interface LoadData {

0 commit comments

Comments
 (0)