lighthouse 9.5.0-dev.20220815 → 9.5.0-dev.20220816

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 (101) hide show
  1. package/cli/commands/list-locales.js +1 -1
  2. package/core/config/config-helpers.js +0 -15
  3. package/core/config/config.js +1 -1
  4. package/core/config/constants.js +1 -0
  5. package/core/config/default-config.js +0 -2
  6. package/core/fraggle-rock/api.js +1 -1
  7. package/core/fraggle-rock/config/config.js +12 -13
  8. package/core/fraggle-rock/gather/navigation-runner.js +17 -26
  9. package/core/fraggle-rock/gather/snapshot-runner.js +4 -5
  10. package/core/fraggle-rock/gather/timespan-runner.js +4 -5
  11. package/core/fraggle-rock/replay/stringify-extension.js +105 -0
  12. package/core/fraggle-rock/user-flow.js +10 -12
  13. package/core/gather/driver/execution-context.js +19 -2
  14. package/core/gather/gather-runner.js +1 -1
  15. package/core/index.js +2 -5
  16. package/core/lib/asset-saver.js +2 -2
  17. package/core/lib/page-functions.js +15 -3
  18. package/core/lib/traces/{pwmetrics-events.js → metric-trace-events.js} +3 -4
  19. package/core/runner.js +2 -2
  20. package/dist/report/bundle.esm.js +1 -14
  21. package/dist/report/flow.js +28 -27
  22. package/dist/report/standalone.js +4 -4
  23. package/flow-report/test/flow-report-pptr-test.ts +1 -1
  24. package/package.json +2 -1
  25. package/report/generator/file-namer.js +5 -1
  26. package/report/generator/flow-report-assets.js +10 -6
  27. package/report/generator/report-assets.js +8 -5
  28. package/report/generator/report-generator.js +7 -7
  29. package/report/generator/tsconfig.json +1 -0
  30. package/report/test/generator/file-namer-test.js +2 -2
  31. package/report/test/generator/report-generator-test.js +8 -9
  32. package/report/test/renderer/report-renderer-axe-test.js +2 -2
  33. package/report/test/renderer/report-ui-features-test.js +1 -1
  34. package/shared/localization/format.js +11 -13
  35. package/shared/localization/i18n-module.js +7 -2
  36. package/shared/localization/locales/ar-XB.json +0 -21
  37. package/shared/localization/locales/ar.json +0 -21
  38. package/shared/localization/locales/bg.json +0 -21
  39. package/shared/localization/locales/ca.json +0 -21
  40. package/shared/localization/locales/cs.json +0 -21
  41. package/shared/localization/locales/da.json +0 -21
  42. package/shared/localization/locales/de.json +0 -21
  43. package/shared/localization/locales/el.json +0 -21
  44. package/shared/localization/locales/en-GB.json +0 -21
  45. package/shared/localization/locales/en-US.json +0 -21
  46. package/shared/localization/locales/en-XA.json +0 -21
  47. package/shared/localization/locales/en-XL.json +0 -21
  48. package/shared/localization/locales/es-419.json +0 -21
  49. package/shared/localization/locales/es.json +0 -21
  50. package/shared/localization/locales/fi.json +0 -21
  51. package/shared/localization/locales/fil.json +0 -21
  52. package/shared/localization/locales/fr.json +0 -21
  53. package/shared/localization/locales/he.json +0 -21
  54. package/shared/localization/locales/hi.json +0 -21
  55. package/shared/localization/locales/hr.json +0 -21
  56. package/shared/localization/locales/hu.json +0 -21
  57. package/shared/localization/locales/id.json +0 -21
  58. package/shared/localization/locales/it.json +0 -21
  59. package/shared/localization/locales/ja.json +0 -21
  60. package/shared/localization/locales/ko.json +0 -21
  61. package/shared/localization/locales/lt.json +0 -21
  62. package/shared/localization/locales/lv.json +0 -21
  63. package/shared/localization/locales/nl.json +0 -21
  64. package/shared/localization/locales/no.json +0 -21
  65. package/shared/localization/locales/pl.json +0 -21
  66. package/shared/localization/locales/pt-PT.json +0 -21
  67. package/shared/localization/locales/pt.json +0 -21
  68. package/shared/localization/locales/ro.json +0 -21
  69. package/shared/localization/locales/ru.json +0 -21
  70. package/shared/localization/locales/sk.json +0 -21
  71. package/shared/localization/locales/sl.json +0 -21
  72. package/shared/localization/locales/sr-Latn.json +0 -21
  73. package/shared/localization/locales/sr.json +0 -21
  74. package/shared/localization/locales/sv.json +0 -21
  75. package/shared/localization/locales/ta.json +0 -21
  76. package/shared/localization/locales/te.json +0 -21
  77. package/shared/localization/locales/th.json +0 -21
  78. package/shared/localization/locales/tr.json +0 -21
  79. package/shared/localization/locales/uk.json +0 -21
  80. package/shared/localization/locales/vi.json +0 -21
  81. package/shared/localization/locales/zh-HK.json +0 -21
  82. package/shared/localization/locales/zh-TW.json +0 -21
  83. package/shared/localization/locales/zh.json +0 -21
  84. package/shared/localization/locales.js +53 -50
  85. package/shared/localization/swap-flow-locale.js +6 -2
  86. package/shared/localization/swap-locale.js +4 -4
  87. package/shared/test/localization/format-test.js +17 -20
  88. package/shared/test/localization/locales-test.js +2 -2
  89. package/shared/test/localization/swap-locale-test.js +3 -2
  90. package/shared/tsconfig.json +1 -0
  91. package/shared/type-verifiers.js +1 -1
  92. package/tsconfig.json +1 -5
  93. package/types/config.d.ts +0 -13
  94. package/types/externs.d.ts +1 -1
  95. package/types/lhr/settings.d.ts +2 -0
  96. package/types/user-flow.d.ts +1 -1
  97. package/core/audits/dobetterweb/no-vulnerable-libraries.js +0 -229
  98. package/report/generator/package.json +0 -4
  99. package/report/test/generator/package.json +0 -4
  100. package/shared/package.json +0 -4
  101. package/third-party/snyk/snapshot.json +0 -182
@@ -22,61 +22,64 @@
22
22
 
23
23
  // TODO(paulirish): Centralize locale inheritance (combining this & i18n.lookupLocale()), adopt cldr parentLocale rules.
24
24
 
25
+ import fs from 'fs';
26
+ import {getModuleDirectory} from '../../esm-utils.js';
27
+
25
28
  /** @typedef {import('../../types/lhr/settings').Locale} Locale */
26
29
  /** @typedef {Record<string, {message: string}>} LhlMessages */
27
30
 
28
- const fs = require('fs');
31
+ const moduleDir = getModuleDirectory(import.meta);
29
32
 
30
33
  /** @type {Record<string, LhlMessages>} */
31
34
  const files = {
32
- 'ar': JSON.parse(fs.readFileSync(`${__dirname}/locales/ar.json`, 'utf8')),
33
- 'ar-XB': JSON.parse(fs.readFileSync(`${__dirname}/locales/ar-XB.json`, 'utf8')),
34
- 'bg': JSON.parse(fs.readFileSync(`${__dirname}/locales/bg.json`, 'utf8')),
35
- 'ca': JSON.parse(fs.readFileSync(`${__dirname}/locales/ca.json`, 'utf8')),
36
- 'cs': JSON.parse(fs.readFileSync(`${__dirname}/locales/cs.json`, 'utf8')),
37
- 'da': JSON.parse(fs.readFileSync(`${__dirname}/locales/da.json`, 'utf8')),
38
- 'de': JSON.parse(fs.readFileSync(`${__dirname}/locales/de.json`, 'utf8')),
39
- 'el': JSON.parse(fs.readFileSync(`${__dirname}/locales/el.json`, 'utf8')),
40
- 'en-GB': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-GB.json`, 'utf8')),
41
- 'en-US': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-US.json`, 'utf8')),
42
- 'en-XA': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-XA.json`, 'utf8')),
43
- 'en-XL': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-XL.json`, 'utf8')),
44
- 'es': JSON.parse(fs.readFileSync(`${__dirname}/locales/es.json`, 'utf8')),
45
- 'es-419': JSON.parse(fs.readFileSync(`${__dirname}/locales/es-419.json`, 'utf8')),
46
- 'fi': JSON.parse(fs.readFileSync(`${__dirname}/locales/fi.json`, 'utf8')),
47
- 'fil': JSON.parse(fs.readFileSync(`${__dirname}/locales/fil.json`, 'utf8')),
48
- 'fr': JSON.parse(fs.readFileSync(`${__dirname}/locales/fr.json`, 'utf8')),
49
- 'he': JSON.parse(fs.readFileSync(`${__dirname}/locales/he.json`, 'utf8')),
50
- 'hi': JSON.parse(fs.readFileSync(`${__dirname}/locales/hi.json`, 'utf8')),
51
- 'hr': JSON.parse(fs.readFileSync(`${__dirname}/locales/hr.json`, 'utf8')),
52
- 'hu': JSON.parse(fs.readFileSync(`${__dirname}/locales/hu.json`, 'utf8')),
53
- 'id': JSON.parse(fs.readFileSync(`${__dirname}/locales/id.json`, 'utf8')),
54
- 'it': JSON.parse(fs.readFileSync(`${__dirname}/locales/it.json`, 'utf8')),
55
- 'ja': JSON.parse(fs.readFileSync(`${__dirname}/locales/ja.json`, 'utf8')),
56
- 'ko': JSON.parse(fs.readFileSync(`${__dirname}/locales/ko.json`, 'utf8')),
57
- 'lt': JSON.parse(fs.readFileSync(`${__dirname}/locales/lt.json`, 'utf8')),
58
- 'lv': JSON.parse(fs.readFileSync(`${__dirname}/locales/lv.json`, 'utf8')),
59
- 'nl': JSON.parse(fs.readFileSync(`${__dirname}/locales/nl.json`, 'utf8')),
60
- 'no': JSON.parse(fs.readFileSync(`${__dirname}/locales/no.json`, 'utf8')),
61
- 'pl': JSON.parse(fs.readFileSync(`${__dirname}/locales/pl.json`, 'utf8')),
62
- 'pt': JSON.parse(fs.readFileSync(`${__dirname}/locales/pt.json`, 'utf8')),
63
- 'pt-PT': JSON.parse(fs.readFileSync(`${__dirname}/locales/pt-PT.json`, 'utf8')),
64
- 'ro': JSON.parse(fs.readFileSync(`${__dirname}/locales/ro.json`, 'utf8')),
65
- 'ru': JSON.parse(fs.readFileSync(`${__dirname}/locales/ru.json`, 'utf8')),
66
- 'sk': JSON.parse(fs.readFileSync(`${__dirname}/locales/sk.json`, 'utf8')),
67
- 'sl': JSON.parse(fs.readFileSync(`${__dirname}/locales/sl.json`, 'utf8')),
68
- 'sr': JSON.parse(fs.readFileSync(`${__dirname}/locales/sr.json`, 'utf8')),
69
- 'sr-Latn': JSON.parse(fs.readFileSync(`${__dirname}/locales/sr-Latn.json`, 'utf8')),
70
- 'sv': JSON.parse(fs.readFileSync(`${__dirname}/locales/sv.json`, 'utf8')),
71
- 'ta': JSON.parse(fs.readFileSync(`${__dirname}/locales/ta.json`, 'utf8')),
72
- 'te': JSON.parse(fs.readFileSync(`${__dirname}/locales/te.json`, 'utf8')),
73
- 'th': JSON.parse(fs.readFileSync(`${__dirname}/locales/th.json`, 'utf8')),
74
- 'tr': JSON.parse(fs.readFileSync(`${__dirname}/locales/tr.json`, 'utf8')),
75
- 'uk': JSON.parse(fs.readFileSync(`${__dirname}/locales/uk.json`, 'utf8')),
76
- 'vi': JSON.parse(fs.readFileSync(`${__dirname}/locales/vi.json`, 'utf8')),
77
- 'zh': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh.json`, 'utf8')),
78
- 'zh-HK': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh-HK.json`, 'utf8')),
79
- 'zh-TW': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh-TW.json`, 'utf8')),
35
+ 'ar': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ar.json`, 'utf8')),
36
+ 'ar-XB': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ar-XB.json`, 'utf8')),
37
+ 'bg': JSON.parse(fs.readFileSync(`${moduleDir}/locales/bg.json`, 'utf8')),
38
+ 'ca': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ca.json`, 'utf8')),
39
+ 'cs': JSON.parse(fs.readFileSync(`${moduleDir}/locales/cs.json`, 'utf8')),
40
+ 'da': JSON.parse(fs.readFileSync(`${moduleDir}/locales/da.json`, 'utf8')),
41
+ 'de': JSON.parse(fs.readFileSync(`${moduleDir}/locales/de.json`, 'utf8')),
42
+ 'el': JSON.parse(fs.readFileSync(`${moduleDir}/locales/el.json`, 'utf8')),
43
+ 'en-GB': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-GB.json`, 'utf8')),
44
+ 'en-US': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-US.json`, 'utf8')),
45
+ 'en-XA': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-XA.json`, 'utf8')),
46
+ 'en-XL': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-XL.json`, 'utf8')),
47
+ 'es': JSON.parse(fs.readFileSync(`${moduleDir}/locales/es.json`, 'utf8')),
48
+ 'es-419': JSON.parse(fs.readFileSync(`${moduleDir}/locales/es-419.json`, 'utf8')),
49
+ 'fi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fi.json`, 'utf8')),
50
+ 'fil': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fil.json`, 'utf8')),
51
+ 'fr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fr.json`, 'utf8')),
52
+ 'he': JSON.parse(fs.readFileSync(`${moduleDir}/locales/he.json`, 'utf8')),
53
+ 'hi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hi.json`, 'utf8')),
54
+ 'hr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hr.json`, 'utf8')),
55
+ 'hu': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hu.json`, 'utf8')),
56
+ 'id': JSON.parse(fs.readFileSync(`${moduleDir}/locales/id.json`, 'utf8')),
57
+ 'it': JSON.parse(fs.readFileSync(`${moduleDir}/locales/it.json`, 'utf8')),
58
+ 'ja': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ja.json`, 'utf8')),
59
+ 'ko': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ko.json`, 'utf8')),
60
+ 'lt': JSON.parse(fs.readFileSync(`${moduleDir}/locales/lt.json`, 'utf8')),
61
+ 'lv': JSON.parse(fs.readFileSync(`${moduleDir}/locales/lv.json`, 'utf8')),
62
+ 'nl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/nl.json`, 'utf8')),
63
+ 'no': JSON.parse(fs.readFileSync(`${moduleDir}/locales/no.json`, 'utf8')),
64
+ 'pl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pl.json`, 'utf8')),
65
+ 'pt': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pt.json`, 'utf8')),
66
+ 'pt-PT': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pt-PT.json`, 'utf8')),
67
+ 'ro': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ro.json`, 'utf8')),
68
+ 'ru': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ru.json`, 'utf8')),
69
+ 'sk': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sk.json`, 'utf8')),
70
+ 'sl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sl.json`, 'utf8')),
71
+ 'sr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sr.json`, 'utf8')),
72
+ 'sr-Latn': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sr-Latn.json`, 'utf8')),
73
+ 'sv': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sv.json`, 'utf8')),
74
+ 'ta': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ta.json`, 'utf8')),
75
+ 'te': JSON.parse(fs.readFileSync(`${moduleDir}/locales/te.json`, 'utf8')),
76
+ 'th': JSON.parse(fs.readFileSync(`${moduleDir}/locales/th.json`, 'utf8')),
77
+ 'tr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/tr.json`, 'utf8')),
78
+ 'uk': JSON.parse(fs.readFileSync(`${moduleDir}/locales/uk.json`, 'utf8')),
79
+ 'vi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/vi.json`, 'utf8')),
80
+ 'zh': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh.json`, 'utf8')),
81
+ 'zh-HK': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh-HK.json`, 'utf8')),
82
+ 'zh-TW': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh-TW.json`, 'utf8')),
80
83
  };
81
84
 
82
85
  // The keys within this const must exactly match the LH.Locale type in externs.d.ts
@@ -172,4 +175,4 @@ const locales = {
172
175
  'zh-TW': files['zh-TW'], // aka zh-Hant, zh-Hant-TW, Traditional Chinese
173
176
  };
174
177
 
175
- module.exports = locales;
178
+ export {locales};
@@ -5,16 +5,20 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const swapLocale = require('./swap-locale.js');
8
+ import {swapLocale} from './swap-locale.js';
9
9
 
10
10
  /**
11
11
  * @param {LH.FlowResult} flowResult
12
12
  * @param {LH.Locale} locale
13
13
  */
14
- module.exports = function swapFlowLocale(flowResult, locale) {
14
+ function swapFlowLocale(flowResult, locale) {
15
15
  const localizedFlowResult = JSON.parse(JSON.stringify(flowResult));
16
16
  localizedFlowResult.steps = flowResult.steps.map(step => {
17
17
  return {...step, lhr: swapLocale(step.lhr, locale).lhr};
18
18
  });
19
19
  return localizedFlowResult;
20
+ }
21
+
22
+ export {
23
+ swapFlowLocale,
20
24
  };
@@ -5,10 +5,10 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const _set = require('lodash/set.js');
9
- const _get = require('lodash/get.js');
8
+ import _set from 'lodash/set.js';
9
+ import _get from 'lodash/get.js';
10
10
 
11
- const format = require('./format.js');
11
+ import * as format from './format.js';
12
12
 
13
13
  /**
14
14
  * @fileoverview Use the lhr.i18n.icuMessagePaths object to change locales.
@@ -110,4 +110,4 @@ function swapLocale(lhr, requestedLocale) {
110
110
  };
111
111
  }
112
112
 
113
- module.exports = swapLocale;
113
+ export {swapLocale};
@@ -5,18 +5,16 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const path = require('path');
8
+ import path from 'path';
9
9
 
10
- const format = require('../../localization/format.js');
11
- const locales = require('../../localization/locales.js');
10
+ import * as i18n from '../../../core/lib/i18n/i18n.js';
11
+ import * as constants from '../../../core/config/constants.js';
12
+ import * as format from '../../localization/format.js';
13
+ import {locales} from '../../localization/locales.js';
14
+ import {getModuleDirectory, getModulePath} from '../../../esm-utils.js';
12
15
 
13
- // TODO(esmodules): remove when shared/ is esm
14
- let i18n;
15
- let constants;
16
- before(async () => {
17
- i18n = await import('../../../core/lib/i18n/i18n.js');
18
- constants = await import('../../../core/config/constants.js');
19
- });
16
+ const moduleDir = getModuleDirectory(import.meta);
17
+ const modulePath = getModulePath(import.meta);
20
18
 
21
19
  describe('format', () => {
22
20
  describe('DEFAULT_LOCALE', () => {
@@ -83,7 +81,7 @@ describe('format', () => {
83
81
 
84
82
  describe('#replaceIcuMessages', () => {
85
83
  it('replaces the references in the LHR', () => {
86
- const fakeFile = path.join(__dirname, 'fake-file-number-2.js');
84
+ const fakeFile = path.join(moduleDir, 'fake-file-number-2.js');
87
85
  const UIStrings = {aString: 'different {x}!'};
88
86
  const formatter = i18n.createIcuMessageFn(fakeFile, UIStrings);
89
87
 
@@ -115,14 +113,14 @@ describe('format', () => {
115
113
  describe('#getFormatted', () => {
116
114
  it('returns the formatted string', () => {
117
115
  const UIStrings = {testMessage: 'happy test'};
118
- const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
116
+ const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
119
117
  const formattedStr = format.getFormatted(str_(UIStrings.testMessage), 'en');
120
118
  expect(formattedStr).toEqual('happy test');
121
119
  });
122
120
 
123
121
  it('returns the formatted string with replacements', () => {
124
122
  const UIStrings = {testMessage: 'replacement test ({errorCode})'};
125
- const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
123
+ const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
126
124
  const formattedStr = format.getFormatted(str_(UIStrings.testMessage,
127
125
  {errorCode: 'BOO'}), 'en');
128
126
  expect(formattedStr).toEqual('replacement test (BOO)');
@@ -131,7 +129,7 @@ describe('format', () => {
131
129
  it('throws an error for invalid locales', () => {
132
130
  // Populate a string to try to localize to a bad locale.
133
131
  const UIStrings = {testMessage: 'testy test'};
134
- const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
132
+ const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
135
133
 
136
134
  expect(_ => format.getFormatted(str_(UIStrings.testMessage), 'still-not-a-locale'))
137
135
  .toThrow(`Unsupported locale 'still-not-a-locale'`);
@@ -141,7 +139,7 @@ describe('format', () => {
141
139
  const UIStrings = {
142
140
  testMessage: 'needs {count, number, bytes}KB test {str} in {timeInMs, number, seconds}s',
143
141
  };
144
- const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
142
+ const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
145
143
 
146
144
  const replacements = {
147
145
  count: 2555,
@@ -172,8 +170,7 @@ describe('format', () => {
172
170
 
173
171
  describe('#registerLocaleData', () => {
174
172
  // Store original locale data so we can restore at the end
175
- const moduleLocales = require('../../localization/locales.js');
176
- const clonedLocales = JSON.parse(JSON.stringify(moduleLocales));
173
+ const clonedLocales = JSON.parse(JSON.stringify(locales));
177
174
 
178
175
  it('installs new locale strings', () => {
179
176
  const localeData = {
@@ -184,7 +181,7 @@ describe('format', () => {
184
181
  format.registerLocaleData('en-XZ', localeData);
185
182
 
186
183
  const UIStrings = {testString: 'en-US string!'};
187
- const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
184
+ const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
188
185
  const formattedStr = format.getFormatted(str_(UIStrings.testString), 'en-XZ');
189
186
  expect(formattedStr).toEqual('en-XZ cuerda!');
190
187
  });
@@ -217,7 +214,7 @@ describe('format', () => {
217
214
  expect(newFailureTitle).toEqual('Does not use HTTPS');
218
215
 
219
216
  // Restore overwritten strings to avoid messing with other tests
220
- moduleLocales['es-419'] = clonedLocales['es-419'];
217
+ locales['es-419'] = clonedLocales['es-419'];
221
218
  const title = format.getFormatted(str_(UIStrings.title), 'es-419');
222
219
  expect(title).toEqual('Usa HTTPS');
223
220
  });
@@ -324,7 +321,7 @@ describe('format', () => {
324
321
 
325
322
  let str_;
326
323
  before(() => {
327
- str_ = i18n.createIcuMessageFn(__filename, UIStrings);
324
+ str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
328
325
  });
329
326
 
330
327
  it('formats a basic message', () => {
@@ -5,8 +5,8 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const locales = require('../../localization/locales.js');
9
- const assert = require('assert').strict;
8
+ import {locales} from '../../localization/locales.js';
9
+ import {strict as assert} from 'assert';
10
10
 
11
11
  describe('locales', () => {
12
12
  it('has only canonical (or expected-deprecated) language tags', () => {
@@ -5,9 +5,10 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const swapLocale = require('../../localization/swap-locale.js');
8
+ import {swapLocale} from '../../localization/swap-locale.js';
9
+ import {readJson} from '../../../core/test/test-utils.js';
9
10
 
10
- const lhr = require('../../../core/test/results/sample_v2.json');
11
+ const lhr = readJson('core/test/results/sample_v2.json');
11
12
 
12
13
  describe('swap-locale', () => {
13
14
  it('does not mutate the original lhr', () => {
@@ -13,6 +13,7 @@
13
13
  "include": [
14
14
  "**/*.js",
15
15
  "types/**/*.d.ts",
16
+ "../esm-utils.js",
16
17
  ],
17
18
  "exclude": [
18
19
  "test/**/*.js",
@@ -29,7 +29,7 @@ function isObjectOrArrayOfUnknownValues(val) {
29
29
  return typeof val === 'object' && val !== null;
30
30
  }
31
31
 
32
- module.exports = {
32
+ export {
33
33
  isObjectOfUnknownValues,
34
34
  isObjectOrArrayOfUnknownValues,
35
35
  };
package/tsconfig.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "extends": "./tsconfig-base.json",
3
3
  "compilerOptions": {
4
- // TODO(esmodules): included to support require('file.json'). Remove on the switch to ES Modules.
5
4
  "resolveJsonModule": true,
6
5
  },
7
6
  "references": [
@@ -24,13 +23,10 @@
24
23
  "eslint-local-rules.cjs",
25
24
  "third-party/axe/valid-langs.js",
26
25
 
27
- // TODO(esmodules): JSON files included via resolveJsonModule. Removable on the switch to ES Modules.
28
- "package.json",
29
26
  "core/test/results/sample_v2.json",
30
27
  "core/lib/sd-validation/assets/*.json",
31
28
  "core/test/fixtures/unresolved-perflog.json",
32
29
  "core/test/fixtures/traces/lcp-m78.devtools.log.json",
33
- "third-party/snyk/snapshot.json",
34
30
  "core/audits/byte-efficiency/polyfill-graph-data.json",
35
31
  "shared/localization/locales/en-US.json",
36
32
  ],
@@ -102,7 +98,7 @@
102
98
  "core/test/lib/tracehouse/main-thread-tasks-test.js",
103
99
  "core/test/lib/tracehouse/task-summary-test.js",
104
100
  "core/test/lib/tracehouse/trace-processor-test.js",
105
- "core/test/lib/traces/pwmetrics-events-test.js",
101
+ "core/test/lib/traces/metrics-trace-events-test.js",
106
102
  "core/test/lib/url-shim-test.js",
107
103
  "core/test/network-records-to-devtools-log-test.js",
108
104
  "core/test/runner-test.js",
package/types/config.d.ts CHANGED
@@ -57,19 +57,6 @@ declare module Config {
57
57
  groups: Record<string, Group> | null;
58
58
  }
59
59
 
60
- /**
61
- * Additional information about the context in which a Fraggle Rock config should be interpreted.
62
- * This information is typically set by the CLI or other channel integrations.
63
- */
64
- interface FRContext {
65
- configPath?: string;
66
- settingsOverrides?: SharedFlagsSettings & Pick<LH.Flags, 'plugins'>;
67
- skipAboutBlank?: boolean;
68
- logLevel?: string;
69
- hostname?: string;
70
- port?: number;
71
- }
72
-
73
60
  interface SharedPassNavigationJson {
74
61
  /**
75
62
  * Controls the behavior when the navigation fails to complete (due to server error, no FCP, etc).
@@ -30,7 +30,7 @@ declare global {
30
30
 
31
31
  /** Used by FullPageScreenshot gatherer. */
32
32
  __lighthouseNodesDontTouchOrAllVarianceGoesAway: Map<Element, string>;
33
- __lighthouseExecutionContextId?: number;
33
+ __lighthouseExecutionContextUniqueIdentifier?: number;
34
34
 
35
35
  /** Injected into the page when the `--debug` flag is used. */
36
36
  continueLighthouseRun(): void;
@@ -71,6 +71,8 @@ export type ScreenEmulationSettings = {
71
71
  disableStorageReset?: boolean;
72
72
  /** Flag indicating that Lighthouse should pause after page load to wait for the user's permission to continue the audit. */
73
73
  debugNavigation?: boolean;
74
+ /** If set to true, will skip the initial navigation to about:blank. This option is ignored when using the legacy navigation runner. */
75
+ skipAboutBlank?: boolean;
74
76
 
75
77
  /** How Lighthouse should interpret this run in regards to scoring performance metrics and skipping mobile-only tests in desktop. Must be set even if throttling/emulation is being applied outside of Lighthouse. */
76
78
  formFactor?: 'mobile'|'desktop';
@@ -10,7 +10,7 @@ declare module UserFlow {
10
10
  artifacts: LH.Artifacts;
11
11
  name: string;
12
12
  config?: LH.Config.Json;
13
- configContext?: LH.Config.FRContext;
13
+ flags?: LH.Flags;
14
14
  }
15
15
  }
16
16
 
@@ -1,229 +0,0 @@
1
- /**
2
- * @license Copyright 2017 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
- * @fileoverview Audits a page to make sure there are no JS libraries with
9
- * known vulnerabilities being used. Checks against a vulnerability db
10
- * provided by Snyk.io and checked in locally as third-party/snyk/snapshot.json
11
- */
12
-
13
- 'use strict';
14
-
15
- import fs from 'fs';
16
- import {Audit} from '../audit.js';
17
- import {Sentry} from '../../lib/sentry.js';
18
- import semver from 'semver';
19
- import * as i18n from '../../lib/i18n/i18n.js';
20
- import {LH_ROOT} from '../../../root.js';
21
-
22
- const snykDatabase = JSON.parse(
23
- fs.readFileSync(`${LH_ROOT}/third-party/snyk/snapshot.json`, 'utf-8'));
24
-
25
- const UIStrings = {
26
- /** Title of a Lighthouse audit that provides detail on Javascript libraries the page uses. This descriptive title is shown to users when all Javascript libraries are free of known security vulnerabilities. */
27
- title: 'Avoids front-end JavaScript libraries' +
28
- ' with known security vulnerabilities',
29
- /** Title of a Lighthouse audit that provides detail on Javascript libraries the page uses. This descriptive title is shown to users when some detected Javascript libraries have known security vulnerabilities. */
30
- failureTitle: 'Includes front-end JavaScript libraries' +
31
- ' with known security vulnerabilities',
32
- /** Description of a Lighthouse audit that tells the user why they should be concerned about the third party Javascript libraries that they use. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
33
- description: 'Some third-party scripts may contain known security vulnerabilities ' +
34
- 'that are easily identified and exploited by attackers. ' +
35
- '[Learn more about vulnerable libraries](https://web.dev/no-vulnerable-libraries/).',
36
- /** [ICU Syntax] Label for the audit identifying the number of vulnerable Javascript libraries found. */
37
- displayValue: `{itemCount, plural,
38
- =1 {1 vulnerability detected}
39
- other {# vulnerabilities detected}
40
- }`,
41
- /** Label for a column in a data table; entries will be the version numbers of the Javascript libraries found. */
42
- columnVersion: 'Library Version',
43
- /** Label for a column in a data table; entries will be the counts of JavaScript-library vulnerabilities found. */
44
- columnVuln: 'Vulnerability Count',
45
- /** Label for a column in a data table; entries will be the severity of the vulnerabilities found within a Javascript library. */
46
- columnSeverity: 'Highest Severity',
47
- };
48
-
49
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
50
-
51
- const SEMVER_REGEX = /^(\d+\.\d+\.\d+)[^-0-9]+/;
52
-
53
- /** @type {Record<string, LH.IcuMessage>} */
54
- const severityStringsMap = {
55
- 'low': str_(i18n.UIStrings.itemSeverityLow),
56
- 'medium': str_(i18n.UIStrings.itemSeverityMedium),
57
- 'high': str_(i18n.UIStrings.itemSeverityHigh),
58
- };
59
-
60
- /** @typedef {{npm: Object<string, Array<{id: string, severity: string, semver: {vulnerable: Array<string>}}>>}} SnykDB */
61
- /** @typedef {{severity: LH.IcuMessage, numericSeverity: number, library: string, url: string}} Vulnerability */
62
-
63
- class NoVulnerableLibrariesAudit extends Audit {
64
- /**
65
- * @return {LH.Audit.Meta}
66
- */
67
- static get meta() {
68
- return {
69
- id: 'no-vulnerable-libraries',
70
- title: str_(UIStrings.title),
71
- failureTitle: str_(UIStrings.failureTitle),
72
- description: str_(UIStrings.description),
73
- requiredArtifacts: ['Stacks'],
74
- };
75
- }
76
-
77
- /**
78
- * @return {SnykDB}
79
- */
80
- static get snykDB() {
81
- return snykDatabase;
82
- }
83
-
84
- /**
85
- * @return {Object<string, number>}
86
- */
87
- static get severityMap() {
88
- return {
89
- high: 3,
90
- medium: 2,
91
- low: 1,
92
- };
93
- }
94
-
95
- /**
96
- * Attempts to normalize the version.
97
- * @param {string|undefined} version
98
- * @return {string|undefined}
99
- */
100
- static normalizeVersion(version) {
101
- if (!version) return version;
102
- if (semver.valid(version)) return version;
103
-
104
- // converts 1.5 -> 1.5.0
105
- if (/^\d+\.\d+$/.test(version)) return `${version}.0`;
106
- // converts 1.0.0a-bunch-of-crap -> 1.0.0
107
- const versionMatch = version.match(SEMVER_REGEX);
108
- if (versionMatch) return versionMatch[1];
109
- // leave everything else untouched
110
- return version;
111
- }
112
-
113
- /**
114
- * @param {string} normalizedVersion
115
- * @param {LH.Artifacts.DetectedStack} lib
116
- * @param {SnykDB} snykDB
117
- * @return {Array<Vulnerability>}
118
- */
119
- static getVulnerabilities(normalizedVersion, lib, snykDB) {
120
- if (!lib.npm || !snykDB.npm[lib.npm]) {
121
- return [];
122
- }
123
-
124
- // Verify the version is well-formed first
125
- try {
126
- semver.satisfies(normalizedVersion, '*');
127
- } catch (err) {
128
- err.pkgName = lib.npm;
129
- // Report the failure and skip this library if the version was ill-specified
130
- Sentry.captureException(err, {level: 'warning'});
131
- return [];
132
- }
133
-
134
- // Match the vulnerability candidates from snyk against the version we see in the page
135
- const vulnCandidatesForLib = snykDB.npm[lib.npm];
136
- const matchingVulns = vulnCandidatesForLib.filter(vulnCandidate => {
137
- // Each snyk vulnerability comes with an array of semver ranges
138
- // The page is vulnerable if any of the ranges match.
139
- const hasMatchingVersion = vulnCandidate.semver.vulnerable.some(vulnSemverRange =>
140
- semver.satisfies(normalizedVersion, vulnSemverRange)
141
- );
142
- return hasMatchingVersion;
143
- });
144
-
145
- const vulns = matchingVulns.map(vuln => {
146
- return {
147
- severity: severityStringsMap[vuln.severity],
148
- numericSeverity: this.severityMap[vuln.severity],
149
- library: `${lib.name}@${normalizedVersion}`,
150
- url: 'https://snyk.io/vuln/' + vuln.id,
151
- };
152
- });
153
-
154
- return vulns;
155
- }
156
-
157
- /**
158
- * @param {Array<Vulnerability>} vulnerabilities
159
- * @return {LH.IcuMessage}
160
- */
161
- static highestSeverity(vulnerabilities) {
162
- const sortedVulns = vulnerabilities
163
- .sort((a, b) => b.numericSeverity - a.numericSeverity);
164
- return sortedVulns[0].severity;
165
- }
166
-
167
- /**
168
- * @param {LH.Artifacts} artifacts
169
- * @return {LH.Audit.Product}
170
- */
171
- static audit(artifacts) {
172
- const foundLibraries = artifacts.Stacks.filter(stack => stack.detector === 'js');
173
- const snykDB = NoVulnerableLibrariesAudit.snykDB;
174
-
175
- if (!foundLibraries.length) {
176
- return {
177
- score: 1,
178
- };
179
- }
180
-
181
- let totalVulns = 0;
182
- /** @type {Array<{highestSeverity: LH.IcuMessage, vulnCount: number, detectedLib: LH.Audit.Details.LinkValue}>} */
183
- const vulnerabilityResults = [];
184
-
185
- for (const lib of foundLibraries) {
186
- const version = this.normalizeVersion(lib.version) || '';
187
- const vulns = this.getVulnerabilities(version, lib, snykDB);
188
- const vulnCount = vulns.length;
189
- totalVulns += vulnCount;
190
-
191
- let highestSeverity;
192
- if (vulns.length > 0) {
193
- highestSeverity = this.highestSeverity(vulns);
194
-
195
- vulnerabilityResults.push({
196
- highestSeverity,
197
- vulnCount,
198
- detectedLib: {
199
- text: lib.name + '@' + version,
200
- url: `https://snyk.io/vuln/npm:${lib.npm}?lh=${version}&utm_source=lighthouse&utm_medium=ref&utm_campaign=audit`,
201
- type: 'link',
202
- },
203
- });
204
- }
205
- }
206
-
207
- let displayValue;
208
- if (totalVulns > 0) {
209
- displayValue = str_(UIStrings.displayValue, {itemCount: totalVulns});
210
- }
211
-
212
- /** @type {LH.Audit.Details.Table['headings']} */
213
- const headings = [
214
- {key: 'detectedLib', itemType: 'link', text: str_(UIStrings.columnVersion)},
215
- {key: 'vulnCount', itemType: 'text', text: str_(UIStrings.columnVuln)},
216
- {key: 'highestSeverity', itemType: 'text', text: str_(UIStrings.columnSeverity)},
217
- ];
218
- const details = Audit.makeTableDetails(headings, vulnerabilityResults, {});
219
-
220
- return {
221
- score: Number(totalVulns === 0),
222
- displayValue,
223
- details,
224
- };
225
- }
226
- }
227
-
228
- export default NoVulnerableLibrariesAudit;
229
- export {UIStrings};
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "//": "Preserve commonjs in this directory. Temporary file until converted to type: module"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "//": "Preserve commonjs in this directory. Temporary file until converted to type: module"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "//": "Preserve commonjs in this directory. Temporary file until converted to type: module"
4
- }