Skip to content

Commit 538d4ae

Browse files
authored
core(config): use fr config to construct the legacy config (#13965)
1 parent 1b1c1a4 commit 538d4ae

File tree

12 files changed

+438
-442
lines changed

12 files changed

+438
-442
lines changed

lighthouse-core/config/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
'use strict';
77

8-
import defaultConfig from './default-config.js';
8+
import legacyDefaultConfig from './legacy-default-config.js';
99
import * as constants from './constants.js';
1010
import format from '../../shared/localization/format.js';
1111
import * as validation from './../fraggle-rock/config/validation.js';
@@ -24,7 +24,7 @@ import {
2424
} from './config-helpers.js';
2525
import {getModuleDirectory} from '../../esm-utils.js';
2626

27-
const defaultConfigPath = './default-config.js';
27+
const defaultConfigPath = './legacy-default-config.js';
2828

2929
/** @typedef {typeof import('../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */
3030
/** @typedef {InstanceType<GathererConstructor>} Gatherer */
@@ -168,7 +168,7 @@ class Config {
168168
let configPath = flags?.configPath;
169169

170170
if (!configJSON) {
171-
configJSON = defaultConfig;
171+
configJSON = legacyDefaultConfig;
172172
configPath = path.resolve(getModuleDirectory(import.meta), defaultConfigPath);
173173
}
174174

@@ -184,7 +184,7 @@ class Config {
184184
if (configJSON.extends !== 'lighthouse:default') {
185185
throw new Error('`lighthouse:default` is the only valid extension method.');
186186
}
187-
configJSON = Config.extendConfigJSON(deepCloneConfigJson(defaultConfig), configJSON);
187+
configJSON = Config.extendConfigJSON(deepCloneConfigJson(legacyDefaultConfig), configJSON);
188188
}
189189

190190
// The directory of the config path, if one was provided.

lighthouse-core/config/default-config.js

Lines changed: 157 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -123,56 +123,160 @@ const UIStrings = {
123123

124124
const str_ = i18n.createMessageInstanceIdFn(import.meta.url, UIStrings);
125125

126+
// Ensure all artifact IDs match the typedefs.
127+
/** @type {Record<keyof LH.FRArtifacts, string>} */
128+
const artifacts = {
129+
DevtoolsLog: '',
130+
Trace: '',
131+
Accessibility: '',
132+
AnchorElements: '',
133+
CacheContents: '',
134+
ConsoleMessages: '',
135+
CSSUsage: '',
136+
Doctype: '',
137+
DOMStats: '',
138+
EmbeddedContent: '',
139+
FontSize: '',
140+
Inputs: '',
141+
FullPageScreenshot: '',
142+
GlobalListeners: '',
143+
IFrameElements: '',
144+
ImageElements: '',
145+
InstallabilityErrors: '',
146+
InspectorIssues: '',
147+
JsUsage: '',
148+
LinkElements: '',
149+
MainDocumentContent: '',
150+
MetaElements: '',
151+
NetworkUserAgent: '',
152+
OptimizedImages: '',
153+
PasswordInputsWithPreventedPaste: '',
154+
ResponseCompression: '',
155+
RobotsTxt: '',
156+
ServiceWorker: '',
157+
ScriptElements: '',
158+
Scripts: '',
159+
SourceMaps: '',
160+
Stacks: '',
161+
TagsBlockingFirstPaint: '',
162+
TapTargets: '',
163+
TraceElements: '',
164+
ViewportDimensions: '',
165+
WebAppManifest: '',
166+
devtoolsLogs: '',
167+
traces: '',
168+
};
169+
170+
for (const key of Object.keys(artifacts)) {
171+
artifacts[/** @type {keyof typeof artifacts} */ (key)] = key;
172+
}
173+
126174
/** @type {LH.Config.Json} */
127175
const defaultConfig = {
128176
settings: constants.defaultSettings,
129-
passes: [{
130-
passName: 'defaultPass',
131-
recordTrace: true,
132-
useThrottling: true,
133-
pauseAfterFcpMs: 1000,
134-
pauseAfterLoadMs: 1000,
135-
networkQuietThresholdMs: 1000,
136-
cpuQuietThresholdMs: 1000,
137-
gatherers: [
138-
'css-usage',
139-
'js-usage',
140-
'viewport-dimensions',
141-
'console-messages',
142-
'anchor-elements',
143-
'image-elements',
144-
'link-elements',
145-
'meta-elements',
146-
'script-elements',
147-
'scripts',
148-
'iframe-elements',
149-
'inputs',
150-
'main-document-content',
151-
'global-listeners',
152-
'dobetterweb/doctype',
153-
'dobetterweb/domstats',
154-
'dobetterweb/optimized-images',
155-
'dobetterweb/password-inputs-with-prevented-paste',
156-
'dobetterweb/response-compression',
157-
'dobetterweb/tags-blocking-first-paint',
158-
'seo/font-size',
159-
'seo/embedded-content',
160-
'seo/robots-txt',
161-
'seo/tap-targets',
162-
'accessibility',
163-
'trace-elements',
164-
'inspector-issues',
165-
'source-maps',
166-
'full-page-screenshot',
167-
],
168-
},
169-
{
170-
passName: 'offlinePass',
171-
loadFailureMode: 'ignore',
172-
gatherers: [
173-
'service-worker',
174-
],
175-
}],
177+
artifacts: [
178+
// Artifacts which can be depended on come first.
179+
{id: artifacts.DevtoolsLog, gatherer: 'devtools-log'},
180+
{id: artifacts.Trace, gatherer: 'trace'},
181+
182+
{id: artifacts.Accessibility, gatherer: 'accessibility'},
183+
{id: artifacts.AnchorElements, gatherer: 'anchor-elements'},
184+
{id: artifacts.CacheContents, gatherer: 'cache-contents'},
185+
{id: artifacts.ConsoleMessages, gatherer: 'console-messages'},
186+
{id: artifacts.CSSUsage, gatherer: 'css-usage'},
187+
{id: artifacts.Doctype, gatherer: 'dobetterweb/doctype'},
188+
{id: artifacts.DOMStats, gatherer: 'dobetterweb/domstats'},
189+
{id: artifacts.EmbeddedContent, gatherer: 'seo/embedded-content'},
190+
{id: artifacts.FontSize, gatherer: 'seo/font-size'},
191+
{id: artifacts.Inputs, gatherer: 'inputs'},
192+
{id: artifacts.GlobalListeners, gatherer: 'global-listeners'},
193+
{id: artifacts.IFrameElements, gatherer: 'iframe-elements'},
194+
{id: artifacts.ImageElements, gatherer: 'image-elements'},
195+
{id: artifacts.InstallabilityErrors, gatherer: 'installability-errors'},
196+
{id: artifacts.InspectorIssues, gatherer: 'inspector-issues'},
197+
{id: artifacts.JsUsage, gatherer: 'js-usage'},
198+
{id: artifacts.LinkElements, gatherer: 'link-elements'},
199+
{id: artifacts.MainDocumentContent, gatherer: 'main-document-content'},
200+
{id: artifacts.MetaElements, gatherer: 'meta-elements'},
201+
{id: artifacts.NetworkUserAgent, gatherer: 'network-user-agent'},
202+
{id: artifacts.OptimizedImages, gatherer: 'dobetterweb/optimized-images'},
203+
{id: artifacts.PasswordInputsWithPreventedPaste, gatherer: 'dobetterweb/password-inputs-with-prevented-paste'},
204+
{id: artifacts.ResponseCompression, gatherer: 'dobetterweb/response-compression'},
205+
{id: artifacts.RobotsTxt, gatherer: 'seo/robots-txt'},
206+
{id: artifacts.ServiceWorker, gatherer: 'service-worker'},
207+
{id: artifacts.ScriptElements, gatherer: 'script-elements'},
208+
{id: artifacts.Scripts, gatherer: 'scripts'},
209+
{id: artifacts.SourceMaps, gatherer: 'source-maps'},
210+
{id: artifacts.Stacks, gatherer: 'stacks'},
211+
{id: artifacts.TagsBlockingFirstPaint, gatherer: 'dobetterweb/tags-blocking-first-paint'},
212+
{id: artifacts.TapTargets, gatherer: 'seo/tap-targets'},
213+
{id: artifacts.TraceElements, gatherer: 'trace-elements'},
214+
{id: artifacts.ViewportDimensions, gatherer: 'viewport-dimensions'},
215+
{id: artifacts.WebAppManifest, gatherer: 'web-app-manifest'},
216+
217+
// Artifact copies are renamed for compatibility with legacy artifacts.
218+
{id: artifacts.devtoolsLogs, gatherer: 'devtools-log-compat'},
219+
{id: artifacts.traces, gatherer: 'trace-compat'},
220+
221+
// FullPageScreenshot comes at the very end so all other node analysis is captured.
222+
{id: artifacts.FullPageScreenshot, gatherer: 'full-page-screenshot'},
223+
],
224+
navigations: [
225+
{
226+
id: 'default',
227+
pauseAfterFcpMs: 1000,
228+
pauseAfterLoadMs: 1000,
229+
networkQuietThresholdMs: 1000,
230+
cpuQuietThresholdMs: 1000,
231+
artifacts: [
232+
// Artifacts which can be depended on come first.
233+
artifacts.DevtoolsLog,
234+
artifacts.Trace,
235+
236+
artifacts.Accessibility,
237+
artifacts.AnchorElements,
238+
artifacts.CacheContents,
239+
artifacts.ConsoleMessages,
240+
artifacts.CSSUsage,
241+
artifacts.Doctype,
242+
artifacts.DOMStats,
243+
artifacts.EmbeddedContent,
244+
artifacts.FontSize,
245+
artifacts.Inputs,
246+
artifacts.GlobalListeners,
247+
artifacts.IFrameElements,
248+
artifacts.ImageElements,
249+
artifacts.InstallabilityErrors,
250+
artifacts.InspectorIssues,
251+
artifacts.JsUsage,
252+
artifacts.LinkElements,
253+
artifacts.MainDocumentContent,
254+
artifacts.MetaElements,
255+
artifacts.NetworkUserAgent,
256+
artifacts.OptimizedImages,
257+
artifacts.PasswordInputsWithPreventedPaste,
258+
artifacts.ResponseCompression,
259+
artifacts.RobotsTxt,
260+
artifacts.ServiceWorker,
261+
artifacts.ScriptElements,
262+
artifacts.Scripts,
263+
artifacts.SourceMaps,
264+
artifacts.Stacks,
265+
artifacts.TagsBlockingFirstPaint,
266+
artifacts.TapTargets,
267+
artifacts.TraceElements,
268+
artifacts.ViewportDimensions,
269+
artifacts.WebAppManifest,
270+
271+
// Compat artifacts come last.
272+
artifacts.devtoolsLogs,
273+
artifacts.traces,
274+
275+
// FullPageScreenshot comes at the very end so all other node analysis is captured.
276+
artifacts.FullPageScreenshot,
277+
],
278+
},
279+
],
176280
audits: [
177281
'is-on-https',
178282
'service-worker',
@@ -186,6 +290,7 @@ const defaultConfig = {
186290
'metrics/total-blocking-time',
187291
'metrics/max-potential-fid',
188292
'metrics/cumulative-layout-shift',
293+
'metrics/experimental-interaction-to-next-paint',
189294
'errors-in-console',
190295
'server-response-time',
191296
'metrics/interactive',
@@ -302,6 +407,7 @@ const defaultConfig = {
302407
'byte-efficiency/efficient-animated-content',
303408
'byte-efficiency/duplicated-javascript',
304409
'byte-efficiency/legacy-javascript',
410+
'byte-efficiency/uses-responsive-images-snapshot',
305411
'dobetterweb/doctype',
306412
'dobetterweb/charset',
307413
'dobetterweb/dom-size',
@@ -326,8 +432,8 @@ const defaultConfig = {
326432
'seo/plugins',
327433
'seo/canonical',
328434
'seo/manual/structured-data',
435+
'work-during-interaction',
329436
],
330-
331437
groups: {
332438
'metrics': {
333439
title: str_(UIStrings.metricGroupTitle),
@@ -420,6 +526,7 @@ const defaultConfig = {
420526
{id: 'total-blocking-time', weight: 30, group: 'metrics', acronym: 'TBT', relevantAudits: metricsToAudits.tbtRelevantAudits},
421527
{id: 'largest-contentful-paint', weight: 25, group: 'metrics', acronym: 'LCP', relevantAudits: metricsToAudits.lcpRelevantAudits},
422528
{id: 'cumulative-layout-shift', weight: 15, group: 'metrics', acronym: 'CLS', relevantAudits: metricsToAudits.clsRelevantAudits},
529+
{id: 'experimental-interaction-to-next-paint', weight: 0, group: 'metrics', acronym: 'INP', relevantAudits: metricsToAudits.inpRelevantAudits},
423530

424531
// These are our "invisible" metrics. Not displayed, but still in the LHR.
425532
{id: 'max-potential-fid', weight: 0, group: 'hidden'},
@@ -466,6 +573,8 @@ const defaultConfig = {
466573
{id: 'unsized-images', weight: 0},
467574
{id: 'viewport', weight: 0},
468575
{id: 'no-unload-listeners', weight: 0},
576+
{id: 'uses-responsive-images-snapshot', weight: 0},
577+
{id: 'work-during-interaction', weight: 0},
469578

470579
// Budget audits.
471580
{id: 'performance-budget', weight: 0, group: 'budgets'},
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @license Copyright 2018 The Lighthouse Authors. All Rights Reserved.
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5+
*/
6+
'use strict';
7+
8+
/**
9+
* @fileoverview Construct the legacy default config from the standard default config.
10+
*/
11+
12+
import defaultConfig from './default-config.js';
13+
14+
/** @type {LH.Config.Json} */
15+
const legacyDefaultConfig = JSON.parse(JSON.stringify(defaultConfig));
16+
if (!legacyDefaultConfig.categories) {
17+
throw new Error('Default config should always have categories');
18+
}
19+
20+
// These properties are ignored in Legacy navigations.
21+
delete legacyDefaultConfig.artifacts;
22+
delete legacyDefaultConfig.navigations;
23+
24+
// These audits don't work in Legacy navigation mode so we remove them.
25+
const unsupportedAuditIds = [
26+
'experimental-interaction-to-next-paint',
27+
'uses-responsive-images-snapshot',
28+
'work-during-interaction',
29+
];
30+
31+
legacyDefaultConfig.audits = legacyDefaultConfig.audits?.filter(audit =>
32+
!unsupportedAuditIds.find(auditId => audit.toString().endsWith(auditId)));
33+
34+
legacyDefaultConfig.categories['performance'].auditRefs =
35+
legacyDefaultConfig.categories['performance'].auditRefs.filter(auditRef =>
36+
!unsupportedAuditIds.includes(auditRef.id));
37+
38+
legacyDefaultConfig.passes = [{
39+
passName: 'defaultPass',
40+
recordTrace: true,
41+
useThrottling: true,
42+
pauseAfterFcpMs: 1000,
43+
pauseAfterLoadMs: 1000,
44+
networkQuietThresholdMs: 1000,
45+
cpuQuietThresholdMs: 1000,
46+
gatherers: [
47+
'css-usage',
48+
'js-usage',
49+
'viewport-dimensions',
50+
'console-messages',
51+
'anchor-elements',
52+
'image-elements',
53+
'link-elements',
54+
'meta-elements',
55+
'script-elements',
56+
'scripts',
57+
'iframe-elements',
58+
'inputs',
59+
'main-document-content',
60+
'global-listeners',
61+
'dobetterweb/doctype',
62+
'dobetterweb/domstats',
63+
'dobetterweb/optimized-images',
64+
'dobetterweb/password-inputs-with-prevented-paste',
65+
'dobetterweb/response-compression',
66+
'dobetterweb/tags-blocking-first-paint',
67+
'seo/font-size',
68+
'seo/embedded-content',
69+
'seo/robots-txt',
70+
'seo/tap-targets',
71+
'accessibility',
72+
'trace-elements',
73+
'inspector-issues',
74+
'source-maps',
75+
'full-page-screenshot',
76+
],
77+
},
78+
{
79+
passName: 'offlinePass',
80+
loadFailureMode: 'ignore',
81+
gatherers: [
82+
'service-worker',
83+
],
84+
}];
85+
86+
export default legacyDefaultConfig;

lighthouse-core/fraggle-rock/config/config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import path from 'path';
99
import log from 'lighthouse-logger';
1010
import {Runner} from '../../runner.js';
11-
import defaultConfig from './default-config.js';
11+
import defaultConfig from '../../config/default-config.js';
1212
import {defaultNavigationConfig, nonSimulatedPassConfigOverrides} from '../../config/constants.js'; // eslint-disable-line max-len
1313

1414
import {
@@ -35,7 +35,10 @@ import {
3535
import {getModuleDirectory} from '../../../esm-utils.js';
3636
import * as format from '../../../shared/localization/format.js';
3737

38-
const defaultConfigPath = path.join(getModuleDirectory(import.meta), './default-config.js');
38+
const defaultConfigPath = path.join(
39+
getModuleDirectory(import.meta),
40+
'../../config/default-config.js'
41+
);
3942

4043
/** @typedef {LH.Config.FRContext & {gatherMode: LH.Gatherer.GatherMode}} ConfigContext */
4144

0 commit comments

Comments
 (0)