lighthouse 9.5.0-dev.20220629 → 9.5.0-dev.20220630

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/{eslint-local-rules.js → eslint-local-rules.cjs} +0 -0
  3. package/lighthouse-cli/run.js +1 -1
  4. package/lighthouse-core/audits/final-screenshot.js +2 -2
  5. package/lighthouse-core/audits/screenshot-thumbnails.js +6 -6
  6. package/lighthouse-core/audits/work-during-interaction.js +3 -3
  7. package/lighthouse-core/computed/metrics/cumulative-layout-shift.js +3 -3
  8. package/lighthouse-core/computed/metrics/first-meaningful-paint.js +2 -2
  9. package/lighthouse-core/computed/metrics/interactive.js +5 -5
  10. package/lighthouse-core/computed/metrics/lantern-first-meaningful-paint.js +3 -3
  11. package/lighthouse-core/computed/metrics/lantern-largest-contentful-paint.js +3 -3
  12. package/lighthouse-core/computed/metrics/largest-contentful-paint-all-frames.js +2 -2
  13. package/lighthouse-core/computed/metrics/largest-contentful-paint.js +2 -2
  14. package/lighthouse-core/computed/speedline.js +4 -4
  15. package/lighthouse-core/fraggle-rock/gather/session.js +3 -2
  16. package/lighthouse-core/gather/connections/connection.js +2 -2
  17. package/lighthouse-core/gather/driver/wait-for-condition.js +3 -3
  18. package/lighthouse-core/gather/driver.js +3 -2
  19. package/lighthouse-core/gather/gather-runner.js +1 -1
  20. package/lighthouse-core/lib/asset-saver.js +6 -6
  21. package/lighthouse-core/lib/lh-error.js +5 -5
  22. package/lighthouse-core/lib/lh-trace-processor.js +6 -6
  23. package/lighthouse-core/lib/navigation-error.js +9 -8
  24. package/lighthouse-core/lib/sentry.js +3 -3
  25. package/lighthouse-core/lib/url-shim.js +2 -2
  26. package/lighthouse-core/runner.js +6 -4
  27. package/package.json +1 -1
  28. package/shared/localization/format.js +1 -1
  29. package/tsconfig.json +1 -1
  30. package/types/global-lh.d.ts +2 -2
  31. package/flow-report/.eslintrc.cjs +0 -51
  32. package/lighthouse-cli/.eslintrc.cjs +0 -28
  33. package/report/.eslintrc.cjs +0 -37
  34. package/report/test/.eslintrc.cjs +0 -14
  35. package/shared/test/localization/.eslintrc.cjs +0 -14
package/CONTRIBUTING.md CHANGED
@@ -8,7 +8,7 @@ We tag issues that are good candidates for those new to the code with [`good fir
8
8
 
9
9
  ## Follow the coding style
10
10
 
11
- The `.eslintrc.js` file defines all. We use [JSDoc](http://usejsdoc.org/) with [TypeScript `checkJs`](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc). Annotations are encouraged for all contributions.
11
+ The `.eslintrc.cjs` file defines all. We use [JSDoc](http://usejsdoc.org/) with [TypeScript `checkJs`](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc). Annotations are encouraged for all contributions.
12
12
 
13
13
  ## Learn about the architecture
14
14
 
@@ -250,7 +250,7 @@ async function runLighthouse(url, flags, config) {
250
250
  if (runnerResult?.lhr.runtimeError) {
251
251
  const {runtimeError} = runnerResult.lhr;
252
252
  return printErrorAndExit({
253
- name: 'LHError',
253
+ name: 'LighthouseError',
254
254
  friendlyMessage: runtimeError.message,
255
255
  code: runtimeError.code,
256
256
  message: runtimeError.message,
@@ -6,7 +6,7 @@
6
6
  'use strict';
7
7
 
8
8
  const Audit = require('./audit.js');
9
- const LHError = require('../lib/lh-error.js');
9
+ const LighthouseError = require('../lib/lh-error.js');
10
10
  const ProcessedTrace = require('../computed/processed-trace.js');
11
11
  const Screenshots = require('../computed/screenshots.js');
12
12
 
@@ -41,7 +41,7 @@ class FinalScreenshot extends Audit {
41
41
  if (artifacts.GatherContext.gatherMode === 'timespan') return {notApplicable: true, score: 1};
42
42
 
43
43
  // If it was another mode, that's a fatal error.
44
- throw new LHError(LHError.errors.NO_SCREENSHOTS);
44
+ throw new LighthouseError(LighthouseError.errors.NO_SCREENSHOTS);
45
45
  }
46
46
 
47
47
  return {
@@ -6,7 +6,7 @@
6
6
  'use strict';
7
7
 
8
8
  const Audit = require('./audit.js');
9
- const LHError = require('../lib/lh-error.js');
9
+ const LighthouseError = require('../lib/lh-error.js');
10
10
  const jpeg = require('jpeg-js');
11
11
  const Speedline = require('../computed/speedline.js');
12
12
 
@@ -88,7 +88,7 @@ class ScreenshotThumbnails extends Audit {
88
88
  const timelineEnd = Math.max(maxFrameTime, minimumTimelineDuration);
89
89
 
90
90
  if (!analyzedFrames.length || !Number.isFinite(timelineEnd)) {
91
- throw new LHError(LHError.errors.INVALID_SPEEDLINE);
91
+ throw new LighthouseError(LighthouseError.errors.INVALID_SPEEDLINE);
92
92
  }
93
93
 
94
94
  for (let i = 1; i <= NUMBER_OF_THUMBNAILS; i++) {
@@ -144,10 +144,10 @@ class ScreenshotThumbnails extends Audit {
144
144
  return await this._audit(artifacts, context);
145
145
  } catch (err) {
146
146
  const noFramesErrors = new Set([
147
- LHError.errors.NO_SCREENSHOTS.code,
148
- LHError.errors.SPEEDINDEX_OF_ZERO.code,
149
- LHError.errors.NO_SPEEDLINE_FRAMES.code,
150
- LHError.errors.INVALID_SPEEDLINE.code,
147
+ LighthouseError.errors.NO_SCREENSHOTS.code,
148
+ LighthouseError.errors.SPEEDINDEX_OF_ZERO.code,
149
+ LighthouseError.errors.NO_SPEEDLINE_FRAMES.code,
150
+ LighthouseError.errors.INVALID_SPEEDLINE.code,
151
151
  ]);
152
152
 
153
153
  // If a timespan didn't happen to contain frames, that's fine. Just mark not applicable.
@@ -15,7 +15,7 @@ const {taskGroups} = require('../lib/tracehouse/task-groups.js');
15
15
  const TraceProcessor = require('../lib/tracehouse/trace-processor.js');
16
16
  const {getExecutionTimingsByURL} = require('../lib/tracehouse/task-summary.js');
17
17
  const inpThresholds = require('./metrics/experimental-interaction-to-next-paint.js').defaultOptions;
18
- const LHError = require('../lib/lh-error.js');
18
+ const LighthouseError = require('../lib/lh-error.js');
19
19
 
20
20
  /** @typedef {import('../computed/metrics/responsiveness.js').EventTimingEvent} EventTimingEvent */
21
21
  /** @typedef {import('../lib/tracehouse/main-thread-tasks.js').TaskNode} TaskNode */
@@ -237,8 +237,8 @@ class WorkDuringInteraction extends Audit {
237
237
  }
238
238
  // TODO: remove workaround once 103.0.5052.0 is sufficiently released.
239
239
  if (interactionEvent.name === 'FallbackTiming') {
240
- throw new LHError(
241
- LHError.errors.UNSUPPORTED_OLD_CHROME,
240
+ throw new LighthouseError(
241
+ LighthouseError.errors.UNSUPPORTED_OLD_CHROME,
242
242
  {featureName: 'detailed EventTiming trace events'}
243
243
  );
244
244
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  const makeComputedArtifact = require('../computed-artifact.js');
9
9
  const ProcessedTrace = require('../processed-trace.js');
10
- const LHError = require('../../lib/lh-error.js');
10
+ const LighthouseError = require('../../lib/lh-error.js');
11
11
 
12
12
  /** @typedef {{ts: number, isMainFrame: boolean, weightedScore: number}} LayoutShiftEvent */
13
13
 
@@ -40,8 +40,8 @@ class CumulativeLayoutShift {
40
40
  // For all-frames CLS calculation, we rely on `weighted_score_delta`, which
41
41
  // was added in Chrome 90: https://crbug.com/1173139
42
42
  if (event.args.data.weighted_score_delta === undefined) {
43
- throw new LHError(
44
- LHError.errors.UNSUPPORTED_OLD_CHROME,
43
+ throw new LighthouseError(
44
+ LighthouseError.errors.UNSUPPORTED_OLD_CHROME,
45
45
  {featureName: 'Cumulative Layout Shift'}
46
46
  );
47
47
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  const makeComputedArtifact = require('../computed-artifact.js');
9
9
  const NavigationMetric = require('./navigation-metric.js');
10
- const LHError = require('../../lib/lh-error.js');
10
+ const LighthouseError = require('../../lib/lh-error.js');
11
11
  const LanternFirstMeaningfulPaint = require('./lantern-first-meaningful-paint.js');
12
12
 
13
13
  class FirstMeaningfulPaint extends NavigationMetric {
@@ -28,7 +28,7 @@ class FirstMeaningfulPaint extends NavigationMetric {
28
28
  static async computeObservedMetric(data) {
29
29
  const {processedNavigation} = data;
30
30
  if (processedNavigation.timings.firstMeaningfulPaint === undefined) {
31
- throw new LHError(LHError.errors.NO_FMP);
31
+ throw new LighthouseError(LighthouseError.errors.NO_FMP);
32
32
  }
33
33
 
34
34
  return {
@@ -11,7 +11,7 @@ const LanternInteractive = require('./lantern-interactive.js');
11
11
 
12
12
  const NetworkMonitor = require('../../gather/driver/network-monitor.js');
13
13
  const TracingProcessor = require('../../lib/tracehouse/trace-processor.js');
14
- const LHError = require('../../lib/lh-error.js');
14
+ const LighthouseError = require('../../lib/lh-error.js');
15
15
 
16
16
  const REQUIRED_QUIET_WINDOW = 5000;
17
17
  const ALLOWED_CONCURRENT_REQUESTS = 2;
@@ -133,10 +133,10 @@ class Interactive extends NavigationMetric {
133
133
  }
134
134
  }
135
135
 
136
- throw new LHError(
136
+ throw new LighthouseError(
137
137
  cpuCandidate
138
- ? LHError.errors.NO_TTI_NETWORK_IDLE_PERIOD
139
- : LHError.errors.NO_TTI_CPU_IDLE_PERIOD
138
+ ? LighthouseError.errors.NO_TTI_NETWORK_IDLE_PERIOD
139
+ : LighthouseError.errors.NO_TTI_CPU_IDLE_PERIOD
140
140
  );
141
141
  }
142
142
 
@@ -158,7 +158,7 @@ class Interactive extends NavigationMetric {
158
158
  const {processedTrace, processedNavigation, networkRecords} = data;
159
159
 
160
160
  if (!processedNavigation.timestamps.domContentLoaded) {
161
- throw new LHError(LHError.errors.NO_DCL);
161
+ throw new LighthouseError(LighthouseError.errors.NO_DCL);
162
162
  }
163
163
 
164
164
  const longTasks = TracingProcessor.getMainThreadTopLevelEvents(processedTrace)
@@ -7,7 +7,7 @@
7
7
 
8
8
  const makeComputedArtifact = require('../computed-artifact.js');
9
9
  const LanternMetric = require('./lantern-metric.js');
10
- const LHError = require('../../lib/lh-error.js');
10
+ const LighthouseError = require('../../lib/lh-error.js');
11
11
  const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js');
12
12
 
13
13
  /** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */
@@ -32,7 +32,7 @@ class LanternFirstMeaningfulPaint extends LanternMetric {
32
32
  static getOptimisticGraph(dependencyGraph, processedNavigation) {
33
33
  const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
34
34
  if (!fmp) {
35
- throw new LHError(LHError.errors.NO_FMP);
35
+ throw new LighthouseError(LighthouseError.errors.NO_FMP);
36
36
  }
37
37
 
38
38
  return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
@@ -52,7 +52,7 @@ class LanternFirstMeaningfulPaint extends LanternMetric {
52
52
  static getPessimisticGraph(dependencyGraph, processedNavigation) {
53
53
  const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
54
54
  if (!fmp) {
55
- throw new LHError(LHError.errors.NO_FMP);
55
+ throw new LighthouseError(LighthouseError.errors.NO_FMP);
56
56
  }
57
57
 
58
58
  return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
@@ -7,7 +7,7 @@
7
7
 
8
8
  const makeComputedArtifact = require('../computed-artifact.js');
9
9
  const LanternMetric = require('./lantern-metric.js');
10
- const LHError = require('../../lib/lh-error.js');
10
+ const LighthouseError = require('../../lib/lh-error.js');
11
11
  const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js');
12
12
 
13
13
  /** @typedef {import('../../lib/dependency-graph/base-node.js').Node} Node */
@@ -47,7 +47,7 @@ class LanternLargestContentfulPaint extends LanternMetric {
47
47
  static getOptimisticGraph(dependencyGraph, processedNavigation) {
48
48
  const lcp = processedNavigation.timestamps.largestContentfulPaint;
49
49
  if (!lcp) {
50
- throw new LHError(LHError.errors.NO_LCP);
50
+ throw new LighthouseError(LighthouseError.errors.NO_LCP);
51
51
  }
52
52
 
53
53
  return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
@@ -65,7 +65,7 @@ class LanternLargestContentfulPaint extends LanternMetric {
65
65
  static getPessimisticGraph(dependencyGraph, processedNavigation) {
66
66
  const lcp = processedNavigation.timestamps.largestContentfulPaint;
67
67
  if (!lcp) {
68
- throw new LHError(LHError.errors.NO_LCP);
68
+ throw new LighthouseError(LighthouseError.errors.NO_LCP);
69
69
  }
70
70
 
71
71
  return LanternFirstContentfulPaint.getFirstPaintBasedGraph(
@@ -11,7 +11,7 @@
11
11
 
12
12
  const makeComputedArtifact = require('../computed-artifact.js');
13
13
  const NavigationMetric = require('./navigation-metric.js');
14
- const LHError = require('../../lib/lh-error.js');
14
+ const LighthouseError = require('../../lib/lh-error.js');
15
15
 
16
16
  class LargestContentfulPaintAllFrames extends NavigationMetric {
17
17
  /**
@@ -29,7 +29,7 @@ class LargestContentfulPaintAllFrames extends NavigationMetric {
29
29
  static async computeObservedMetric(data) {
30
30
  const {processedNavigation} = data;
31
31
  if (processedNavigation.timings.largestContentfulPaintAllFrames === undefined) {
32
- throw new LHError(LHError.errors.NO_LCP_ALL_FRAMES);
32
+ throw new LighthouseError(LighthouseError.errors.NO_LCP_ALL_FRAMES);
33
33
  }
34
34
 
35
35
  return {
@@ -15,7 +15,7 @@
15
15
 
16
16
  const makeComputedArtifact = require('../computed-artifact.js');
17
17
  const NavigationMetric = require('./navigation-metric.js');
18
- const LHError = require('../../lib/lh-error.js');
18
+ const LighthouseError = require('../../lib/lh-error.js');
19
19
  const LanternLargestContentfulPaint = require('./lantern-largest-contentful-paint.js');
20
20
 
21
21
  class LargestContentfulPaint extends NavigationMetric {
@@ -36,7 +36,7 @@ class LargestContentfulPaint extends NavigationMetric {
36
36
  static async computeObservedMetric(data) {
37
37
  const {processedNavigation} = data;
38
38
  if (processedNavigation.timings.largestContentfulPaint === undefined) {
39
- throw new LHError(LHError.errors.NO_LCP);
39
+ throw new LighthouseError(LighthouseError.errors.NO_LCP);
40
40
  }
41
41
 
42
42
  return {
@@ -7,7 +7,7 @@
7
7
 
8
8
  const makeComputedArtifact = require('./computed-artifact.js');
9
9
  const speedline = require('speedline-core');
10
- const LHError = require('../lib/lh-error.js');
10
+ const LighthouseError = require('../lib/lh-error.js');
11
11
  const ProcessedTrace = require('./processed-trace.js');
12
12
 
13
13
  class Speedline {
@@ -33,17 +33,17 @@ class Speedline {
33
33
  });
34
34
  }).catch(err => {
35
35
  if (/No screenshots found in trace/.test(err.message)) {
36
- throw new LHError(LHError.errors.NO_SCREENSHOTS);
36
+ throw new LighthouseError(LighthouseError.errors.NO_SCREENSHOTS);
37
37
  }
38
38
 
39
39
  throw err;
40
40
  }).then(speedline => {
41
41
  if (speedline.frames.length === 0) {
42
- throw new LHError(LHError.errors.NO_SPEEDLINE_FRAMES);
42
+ throw new LighthouseError(LighthouseError.errors.NO_SPEEDLINE_FRAMES);
43
43
  }
44
44
 
45
45
  if (speedline.speedIndex === 0) {
46
- throw new LHError(LHError.errors.SPEEDINDEX_OF_ZERO);
46
+ throw new LighthouseError(LighthouseError.errors.SPEEDINDEX_OF_ZERO);
47
47
  }
48
48
 
49
49
  return speedline;
@@ -6,7 +6,7 @@
6
6
  'use strict';
7
7
 
8
8
  const EventEmitter = require('events').EventEmitter;
9
- const LHError = require('../../lib/lh-error.js');
9
+ const LighthouseError = require('../../lib/lh-error.js');
10
10
 
11
11
  // Controls how long to wait for a response after sending a DevTools protocol command.
12
12
  const DEFAULT_PROTOCOL_TIMEOUT = 30000;
@@ -87,7 +87,8 @@ class ProtocolSession extends CrdpEventEmitter {
87
87
  const timeoutPromise = new Promise((resolve, reject) => {
88
88
  if (timeoutMs === Infinity) return;
89
89
 
90
- timeout = setTimeout(reject, timeoutMs, new LHError(LHError.errors.PROTOCOL_TIMEOUT, {
90
+ // eslint-disable-next-line max-len
91
+ timeout = setTimeout(reject, timeoutMs, new LighthouseError(LighthouseError.errors.PROTOCOL_TIMEOUT, {
91
92
  protocolMethod: method,
92
93
  }));
93
94
  });
@@ -7,7 +7,7 @@
7
7
 
8
8
  const EventEmitter = require('events').EventEmitter;
9
9
  const log = require('lighthouse-logger');
10
- const LHError = require('../../lib/lh-error.js');
10
+ const LighthouseError = require('../../lib/lh-error.js');
11
11
 
12
12
  // TODO(bckenny): CommandCallback properties should be tied by command type after
13
13
  // https://github.com/Microsoft/TypeScript/pull/22348. See driver.js TODO.
@@ -138,7 +138,7 @@ class Connection {
138
138
  callback.resolve(Promise.resolve().then(_ => {
139
139
  if (object.error) {
140
140
  log.formatProtocol('method <= browser ERR', {method: callback.method}, 'error');
141
- throw LHError.fromProtocolMessage(callback.method, object.error);
141
+ throw LighthouseError.fromProtocolMessage(callback.method, object.error);
142
142
  }
143
143
 
144
144
  log.formatProtocol('method <= browser OK',
@@ -8,7 +8,7 @@
8
8
  /* global window */
9
9
 
10
10
  const log = require('lighthouse-logger');
11
- const LHError = require('../../lib/lh-error.js');
11
+ const LighthouseError = require('../../lib/lh-error.js');
12
12
  const ExecutionContext = require('./execution-context.js');
13
13
 
14
14
  /** @typedef {import('./network-monitor.js')} NetworkMonitor */
@@ -75,7 +75,7 @@ function waitForFcp(session, pauseAfterFcpMs, maxWaitForFcpMs) {
75
75
  /** @type {Promise<void>} */
76
76
  const promise = new Promise((resolve, reject) => {
77
77
  const maxWaitTimeout = setTimeout(() => {
78
- reject(new LHError(LHError.errors.NO_FCP));
78
+ reject(new LighthouseError(LighthouseError.errors.NO_FCP));
79
79
  }, maxWaitForFcpMs);
80
80
  /** @type {NodeJS.Timeout|undefined} */
81
81
  let loadTimeout;
@@ -476,7 +476,7 @@ async function waitForFullyLoaded(session, networkMonitor, options) {
476
476
  log.warn('waitFor', 'Page appears to be hung, killing JavaScript...');
477
477
  await session.sendCommand('Emulation.setScriptExecutionDisabled', {value: true});
478
478
  await session.sendCommand('Runtime.terminateExecution');
479
- throw new LHError(LHError.errors.PAGE_HUNG);
479
+ throw new LighthouseError(LighthouseError.errors.PAGE_HUNG);
480
480
  }
481
481
 
482
482
  return {timedOut: true};
@@ -7,7 +7,7 @@
7
7
 
8
8
  const Fetcher = require('./fetcher.js');
9
9
  const ExecutionContext = require('./driver/execution-context.js');
10
- const LHError = require('../lib/lh-error.js');
10
+ const LighthouseError = require('../lib/lh-error.js');
11
11
  const {fetchResponseBodyFromCache} = require('../gather/driver/network.js');
12
12
  const EventEmitter = require('events').EventEmitter;
13
13
 
@@ -343,7 +343,8 @@ class Driver {
343
343
  let asyncTimeout;
344
344
  const timeoutPromise = new Promise((resolve, reject) => {
345
345
  if (timeout === Infinity) return;
346
- asyncTimeout = setTimeout(reject, timeout, new LHError(LHError.errors.PROTOCOL_TIMEOUT, {
346
+ // eslint-disable-next-line max-len
347
+ asyncTimeout = setTimeout(reject, timeout, new LighthouseError(LighthouseError.errors.PROTOCOL_TIMEOUT, {
347
348
  protocolMethod: method,
348
349
  }));
349
350
  });
@@ -90,7 +90,7 @@ class GatherRunner {
90
90
  passContext.LighthouseRunWarnings.push(...warnings);
91
91
  }
92
92
  } catch (err) {
93
- // If it's one of our loading-based LHErrors, we'll treat it as a page load error.
93
+ // If it's one of our loading-based LighthouseErrors, we'll treat it as a page load error.
94
94
  if (err.code === 'NO_FCP' || err.code === 'PAGE_HUNG') {
95
95
  return {navigationError: err};
96
96
  }
@@ -15,7 +15,7 @@ const lanternTraceSaver = require('./lantern-trace-saver.js');
15
15
  const Metrics = require('./traces/pwmetrics-events.js');
16
16
  const NetworkAnalysisComputed = require('../computed/network-analysis.js');
17
17
  const LoadSimulatorComputed = require('../computed/load-simulator.js');
18
- const LHError = require('../lib/lh-error.js');
18
+ const LighthouseError = require('../lib/lh-error.js');
19
19
  // TODO(esmodules): Rollup does not support `promisfy` or `stream.pipeline`. Bundled files
20
20
  // don't need anything in this file except for `stringifyReplacer`, so a check for
21
21
  // truthiness before using is enough.
@@ -48,10 +48,10 @@ function loadArtifacts(basePath) {
48
48
  throw new Error('No saved artifacts found at ' + basePath);
49
49
  }
50
50
 
51
- // load artifacts.json using a reviver to deserialize any LHErrors in artifacts.
51
+ // load artifacts.json using a reviver to deserialize any LighthouseErrors in artifacts.
52
52
  const artifactsStr = fs.readFileSync(path.join(basePath, artifactsFilename), 'utf8');
53
53
  /** @type {LH.Artifacts} */
54
- const artifacts = JSON.parse(artifactsStr, LHError.parseReviver);
54
+ const artifacts = JSON.parse(artifactsStr, LighthouseError.parseReviver);
55
55
 
56
56
  const filenames = fs.readdirSync(basePath);
57
57
 
@@ -87,9 +87,9 @@ function loadArtifacts(basePath) {
87
87
  * @param {any} value
88
88
  */
89
89
  function stringifyReplacer(key, value) {
90
- // Currently only handle LHError and other Error types.
90
+ // Currently only handle LighthouseError and other Error types.
91
91
  if (value instanceof Error) {
92
- return LHError.stringifyReplacer(value);
92
+ return LighthouseError.stringifyReplacer(value);
93
93
  }
94
94
 
95
95
  return value;
@@ -128,7 +128,7 @@ async function saveArtifacts(artifacts, basePath) {
128
128
  await saveDevtoolsLog(devtoolsLog, `${basePath}/${passName}${devtoolsLogSuffix}`);
129
129
  }
130
130
 
131
- // save everything else, using a replacer to serialize LHErrors in the artifacts.
131
+ // save everything else, using a replacer to serialize LighthouseErrors in the artifacts.
132
132
  const restArtifactsString = JSON.stringify(restArtifacts, stringifyReplacer, 2) + '\n';
133
133
  fs.writeFileSync(`${basePath}/${artifactsFilename}`, restArtifactsString, 'utf8');
134
134
  log.log('Artifacts saved to disk in folder:', basePath);
@@ -114,7 +114,7 @@ class LighthouseError extends Error {
114
114
  */
115
115
  constructor(errorDefinition, properties) {
116
116
  super(errorDefinition.code);
117
- this.name = 'LHError';
117
+ this.name = 'LighthouseError';
118
118
  this.code = errorDefinition.code;
119
119
  // Add additional properties to be ICU replacements in the error string.
120
120
  // `code` is always added as `errorCode` so callers don't need to specify the code multiple times.
@@ -148,7 +148,7 @@ class LighthouseError extends Error {
148
148
  }
149
149
 
150
150
  /**
151
- * A JSON.stringify replacer to serialize LHErrors and (as a fallback) Errors.
151
+ * A JSON.stringify replacer to serialize LighthouseErrors and (as a fallback) Errors.
152
152
  * Returns a simplified version of the error object that can be reconstituted
153
153
  * as a copy of the original error at parse time.
154
154
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter
@@ -169,7 +169,7 @@ class LighthouseError extends Error {
169
169
  };
170
170
  }
171
171
 
172
- // Unexpected errors won't be LHErrors, but we want them serialized as well.
172
+ // Unexpected errors won't be LighthouseErrors, but we want them serialized as well.
173
173
  if (err instanceof Error) {
174
174
  const {message, stack} = err;
175
175
  // @ts-expect-error - code can be helpful for e.g. node errors, so preserve it if it's present.
@@ -182,12 +182,12 @@ class LighthouseError extends Error {
182
182
  };
183
183
  }
184
184
 
185
- throw new Error('Invalid value for LHError stringification');
185
+ throw new Error('Invalid value for LighthouseError stringification');
186
186
  }
187
187
 
188
188
  /**
189
189
  * A JSON.parse reviver. If any value passed in is a serialized Error or
190
- * LHError, the error is recreated as the original object. Otherwise, the
190
+ * LighthouseError, the error is recreated as the original object. Otherwise, the
191
191
  * value is passed through unchanged.
192
192
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter
193
193
  * @param {string} key
@@ -5,17 +5,17 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const LHError = require('../lib/lh-error.js');
8
+ const LighthouseError = require('../lib/lh-error.js');
9
9
  const TraceProcessor = require('../lib/tracehouse/trace-processor.js');
10
10
 
11
- // TraceProcessor throws generic errors, but we'd like our special localized and code-specific LHError
11
+ // TraceProcessor throws generic errors, but we'd like our special localized and code-specific LighthouseError
12
12
  // objects to be thrown instead.
13
13
  class LHTraceProcessor extends TraceProcessor {
14
14
  /**
15
15
  * @return {Error}
16
16
  */
17
17
  static createNoNavstartError() {
18
- return new LHError(LHError.errors.NO_NAVSTART);
18
+ return new LighthouseError(LighthouseError.errors.NO_NAVSTART);
19
19
  }
20
20
 
21
21
  /**
@@ -25,21 +25,21 @@ class LHTraceProcessor extends TraceProcessor {
25
25
  * @return {Error}
26
26
  */
27
27
  static createNoResourceSendRequestError() {
28
- return new LHError(LHError.errors.NO_RESOURCE_REQUEST);
28
+ return new LighthouseError(LighthouseError.errors.NO_RESOURCE_REQUEST);
29
29
  }
30
30
 
31
31
  /**
32
32
  * @return {Error}
33
33
  */
34
34
  static createNoTracingStartedError() {
35
- return new LHError(LHError.errors.NO_TRACING_STARTED);
35
+ return new LighthouseError(LighthouseError.errors.NO_TRACING_STARTED);
36
36
  }
37
37
 
38
38
  /**
39
39
  * @return {Error}
40
40
  */
41
41
  static createNoFirstContentfulPaintError() {
42
- return new LHError(LHError.errors.NO_FCP);
42
+ return new LighthouseError(LighthouseError.errors.NO_FCP);
43
43
  }
44
44
  }
45
45
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const LHError = require('./lh-error.js');
8
+ const LighthouseError = require('./lh-error.js');
9
9
  const NetworkAnalyzer = require('./dependency-graph/simulator/network-analyzer.js');
10
10
  const NetworkRequest = require('./network-request.js');
11
11
  const i18n = require('./i18n/i18n.js');
@@ -32,7 +32,7 @@ const XHTML_MIME_TYPE = 'application/xhtml+xml';
32
32
  */
33
33
  function getNetworkError(mainRecord) {
34
34
  if (!mainRecord) {
35
- return new LHError(LHError.errors.NO_DOCUMENT_REQUEST);
35
+ return new LighthouseError(LighthouseError.errors.NO_DOCUMENT_REQUEST);
36
36
  } else if (mainRecord.failed) {
37
37
  const netErr = mainRecord.localizedFailDescription;
38
38
  // Match all resolution and DNS failures
@@ -42,12 +42,13 @@ function getNetworkError(mainRecord) {
42
42
  netErr === 'net::ERR_NAME_RESOLUTION_FAILED' ||
43
43
  netErr.startsWith('net::ERR_DNS_')
44
44
  ) {
45
- return new LHError(LHError.errors.DNS_FAILURE);
45
+ return new LighthouseError(LighthouseError.errors.DNS_FAILURE);
46
46
  } else {
47
- return new LHError(LHError.errors.FAILED_DOCUMENT_REQUEST, {errorDetails: netErr});
47
+ return new LighthouseError(
48
+ LighthouseError.errors.FAILED_DOCUMENT_REQUEST, {errorDetails: netErr});
48
49
  }
49
50
  } else if (mainRecord.hasErrorStatusCode()) {
50
- return new LHError(LHError.errors.ERRORED_DOCUMENT_REQUEST, {
51
+ return new LighthouseError(LighthouseError.errors.ERRORED_DOCUMENT_REQUEST, {
51
52
  statusCode: `${mainRecord.statusCode}`,
52
53
  });
53
54
  }
@@ -76,13 +77,13 @@ function getInterstitialError(mainRecord, networkRecords) {
76
77
 
77
78
  // If a request failed with the `net::ERR_CERT_*` collection of errors, then it's a security issue.
78
79
  if (mainRecord.localizedFailDescription.startsWith('net::ERR_CERT')) {
79
- return new LHError(LHError.errors.INSECURE_DOCUMENT_REQUEST, {
80
+ return new LighthouseError(LighthouseError.errors.INSECURE_DOCUMENT_REQUEST, {
80
81
  securityMessages: mainRecord.localizedFailDescription,
81
82
  });
82
83
  }
83
84
 
84
85
  // If we made it this far, it's a generic Chrome interstitial error.
85
- return new LHError(LHError.errors.CHROME_INTERSTITIAL_ERROR);
86
+ return new LighthouseError(LighthouseError.errors.CHROME_INTERSTITIAL_ERROR);
86
87
  }
87
88
 
88
89
  /**
@@ -98,7 +99,7 @@ function getNonHtmlError(finalRecord) {
98
99
  // mimeType is determined by the browser, we assume Chrome is determining mimeType correctly,
99
100
  // independently of 'Content-Type' response headers, and always sending mimeType if well-formed.
100
101
  if (finalRecord.mimeType !== HTML_MIME_TYPE && finalRecord.mimeType !== XHTML_MIME_TYPE) {
101
- return new LHError(LHError.errors.NOT_HTML, {
102
+ return new LighthouseError(LighthouseError.errors.NOT_HTML, {
102
103
  mimeType: finalRecord.mimeType,
103
104
  });
104
105
  }
@@ -108,14 +108,14 @@ function init(opts) {
108
108
  const sampledErrorMatch = SAMPLED_ERRORS.find(sample => sample.pattern.test(err.message));
109
109
  if (sampledErrorMatch && sampledErrorMatch.rate <= Math.random()) return;
110
110
 
111
- // @ts-expect-error - properties added to protocol method LHErrors.
111
+ // @ts-expect-error - properties added to protocol method LighthouseErrors.
112
112
  if (err.protocolMethod) {
113
113
  // Protocol errors all share same stack trace, so add more to fingerprint
114
- // @ts-expect-error - properties added to protocol method LHErrors.
114
+ // @ts-expect-error - properties added to protocol method LighthouseErrors.
115
115
  opts.fingerprint = ['{{ default }}', err.protocolMethod, err.protocolError];
116
116
 
117
117
  opts.tags = opts.tags || {};
118
- // @ts-expect-error - properties added to protocol method LHErrors.
118
+ // @ts-expect-error - properties added to protocol method LighthouseErrors.
119
119
  opts.tags.protocolMethod = err.protocolMethod;
120
120
  }
121
121
 
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  const {Util} = require('../util-commonjs.js');
13
- const LHError = require('../lib/lh-error.js');
13
+ const LighthouseError = require('../lib/lh-error.js');
14
14
 
15
15
  /** @typedef {import('./network-request.js')} NetworkRequest */
16
16
 
@@ -260,7 +260,7 @@ class URLShim extends URL {
260
260
  // Use canonicalized URL (with trailing slashes and such)
261
261
  return new URL(url).href;
262
262
  } else {
263
- throw new LHError(LHError.errors.INVALID_URL);
263
+ throw new LighthouseError(LighthouseError.errors.INVALID_URL);
264
264
  }
265
265
  }
266
266
  }
@@ -18,7 +18,7 @@ const fs = require('fs');
18
18
  const path = require('path');
19
19
  const Sentry = require('./lib/sentry.js');
20
20
  const generateReport = require('../report/generator/report-generator.js').generateReport;
21
- const LHError = require('./lib/lh-error.js');
21
+ const LighthouseError = require('./lib/lh-error.js');
22
22
  const {version: lighthouseVersion} = require('../package.json');
23
23
 
24
24
  /** @typedef {import('./gather/connections/connection.js')} Connection */
@@ -357,7 +357,8 @@ class Runner {
357
357
  if (noArtifact || noRequiredTrace || noRequiredDevtoolsLog) {
358
358
  log.warn('Runner',
359
359
  `${artifactName} gatherer, required by audit ${audit.meta.id}, did not run.`);
360
- throw new LHError(LHError.errors.MISSING_REQUIRED_ARTIFACT, {artifactName});
360
+ throw new LighthouseError(
361
+ LighthouseError.errors.MISSING_REQUIRED_ARTIFACT, {artifactName});
361
362
  }
362
363
 
363
364
  // If artifact was an error, output error result on behalf of audit.
@@ -375,7 +376,7 @@ class Runner {
375
376
  ` encountered an error: ${artifactError.message}`);
376
377
 
377
378
  // Create a friendlier display error and mark it as expected to avoid duplicates in Sentry
378
- const error = new LHError(LHError.errors.ERRORED_REQUIRED_ARTIFACT,
379
+ const error = new LighthouseError(LighthouseError.errors.ERRORED_REQUIRED_ARTIFACT,
379
380
  {artifactName, errorMessage: artifactError.message});
380
381
  // @ts-expect-error Non-standard property added to Error
381
382
  error.expected = true;
@@ -435,7 +436,8 @@ class Runner {
435
436
  ];
436
437
 
437
438
  for (const possibleErrorArtifact of possibleErrorArtifacts) {
438
- if (possibleErrorArtifact instanceof LHError && possibleErrorArtifact.lhrRuntimeError) {
439
+ // eslint-disable-next-line max-len
440
+ if (possibleErrorArtifact instanceof LighthouseError && possibleErrorArtifact.lhrRuntimeError) {
439
441
  const errorMessage = possibleErrorArtifact.friendlyMessage || possibleErrorArtifact.message;
440
442
 
441
443
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lighthouse",
3
- "version": "9.5.0-dev.20220629",
3
+ "version": "9.5.0-dev.20220630",
4
4
  "description": "Automated auditing, performance metrics, and best practices for the web.",
5
5
  "main": "./lighthouse-core/index.js",
6
6
  "bin": {
@@ -147,7 +147,7 @@ function _preformatValues(messageFormatter, values = {}, lhlMessage) {
147
147
  for (const valueId of Object.keys(values)) {
148
148
  if (valueId in formattedValues) continue;
149
149
 
150
- // errorCode is a special case always allowed to help LHError ease-of-use.
150
+ // errorCode is a special case always allowed to help LighthouseError ease-of-use.
151
151
  if (valueId === 'errorCode') {
152
152
  formattedValues.errorCode = values.errorCode;
153
153
  continue;
package/tsconfig.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "clients/**/*.js",
19
19
  "build/**/*.js",
20
20
  "./types/**/*.d.ts",
21
- "eslint-local-rules.js",
21
+ "eslint-local-rules.cjs",
22
22
  "third-party/axe/valid-langs.js",
23
23
 
24
24
  // TODO(esmodules): JSON files included via resolveJsonModule. Removable on the switch to ES Modules.
@@ -14,7 +14,7 @@ import _CrdpMappings from 'devtools-protocol/types/protocol-mapping';
14
14
  import * as Externs from './externs';
15
15
  import Gatherer_ from './gatherer';
16
16
  import * as I18n from './lhr/i18n';
17
- import LHError = require('../lighthouse-core/lib/lh-error.js');
17
+ import LighthouseError_ = require('../lighthouse-core/lib/lh-error.js');
18
18
  import LHResult from './lhr/lhr';
19
19
  import FlowResult_ from './lhr/flow';
20
20
  import Protocol_ from './protocol';
@@ -59,7 +59,7 @@ declare global {
59
59
  export import DevToolsJsonTarget = Externs.DevToolsJsonTarget;
60
60
 
61
61
  export import Gatherer = Gatherer_;
62
- export import LighthouseError = LHError;
62
+ export import LighthouseError = LighthouseError_;
63
63
  export import Result = LHResult;
64
64
  export import FlowResult = FlowResult_;
65
65
 
@@ -1,51 +0,0 @@
1
- /**
2
- * @license Copyright 2021 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
-
7
- module.exports = {
8
- extends: '../.eslintrc.js',
9
- env: {
10
- node: true,
11
- browser: true,
12
- },
13
- plugins: [
14
- '@typescript-eslint',
15
- ],
16
- rules: {
17
- // TODO(esmodules): move to root eslint when all code is ESM
18
- // or when this is resolved: https://github.com/import-js/eslint-plugin-import/issues/2214
19
- 'import/order': [2, {
20
- 'groups': [
21
- 'builtin',
22
- 'external',
23
- ['sibling', 'parent'],
24
- 'index',
25
- 'object',
26
- 'type',
27
- ],
28
- 'newlines-between': 'always',
29
- }],
30
- 'import/group-exports': 2,
31
- 'import/exports-last': 2,
32
- '@typescript-eslint/type-annotation-spacing': 2,
33
- },
34
- overrides: [
35
- // TS already handles this issue.
36
- // https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
37
- {
38
- files: ['**/*.ts', '**/*.tsx', '**/*.js'],
39
- rules: {
40
- 'no-undef': 'off',
41
- },
42
- },
43
- ],
44
- parserOptions: {
45
- ecmaVersion: 2019,
46
- ecmaFeatures: {
47
- jsx: true,
48
- },
49
- sourceType: 'module',
50
- },
51
- };
@@ -1,28 +0,0 @@
1
- /**
2
- * @license Copyright 2021 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
-
7
- module.exports = {
8
- rules: {
9
- // TODO(esmodules): move to root eslint when all code is ESM
10
- // or when this is resolved: https://github.com/import-js/eslint-plugin-import/issues/2214
11
- 'import/order': [2, {
12
- 'groups': [
13
- 'builtin',
14
- 'external',
15
- ['sibling', 'parent'],
16
- 'index',
17
- 'object',
18
- 'type',
19
- ],
20
- 'newlines-between': 'always',
21
- }],
22
- 'import/group-exports': 2,
23
- 'import/exports-last': 2,
24
- },
25
- parserOptions: {
26
- sourceType: 'module',
27
- },
28
- };
@@ -1,37 +0,0 @@
1
- /**
2
- * @license Copyright 2021 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
-
7
- /**
8
- * eslint does not support ESM rc files, so this must be a .cjs file.
9
- * @see https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats
10
- * @see https://github.com/eslint/eslint/issues/13481
11
- */
12
-
13
- module.exports = {
14
- env: {
15
- browser: true,
16
- },
17
- rules: {
18
- // TODO(esmodules): move to root eslint when all code is ESM
19
- // or when this is resolved: https://github.com/import-js/eslint-plugin-import/issues/2214
20
- 'import/order': [2, {
21
- 'groups': [
22
- 'builtin',
23
- 'external',
24
- ['sibling', 'parent'],
25
- 'index',
26
- 'object',
27
- 'type',
28
- ],
29
- 'newlines-between': 'always',
30
- }],
31
- 'import/group-exports': 2,
32
- 'import/exports-last': 2,
33
- },
34
- parserOptions: {
35
- sourceType: 'module',
36
- },
37
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * @license Copyright 2022 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
-
7
- module.exports = {
8
- env: {
9
- mocha: true,
10
- },
11
- globals: {
12
- expect: true,
13
- },
14
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * @license Copyright 2022 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
-
7
- module.exports = {
8
- env: {
9
- mocha: true,
10
- },
11
- globals: {
12
- expect: true,
13
- },
14
- };