lighthouse 8.5.1 → 8.6.0-dev.20211013

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 (172) hide show
  1. package/changelog.md +5490 -0
  2. package/flow-report/.eslintrc.cjs +49 -0
  3. package/flow-report/assets/styles.css +272 -9
  4. package/flow-report/jest.config.js +1 -1
  5. package/flow-report/package.json +4 -0
  6. package/flow-report/src/app.tsx +31 -9
  7. package/flow-report/src/common.tsx +86 -7
  8. package/flow-report/src/header.tsx +88 -0
  9. package/flow-report/src/help-dialog.tsx +120 -0
  10. package/flow-report/src/i18n/i18n.tsx +44 -0
  11. package/flow-report/src/i18n/localized-strings.js +11 -0
  12. package/flow-report/src/i18n/ui-strings.js +86 -0
  13. package/flow-report/src/icons.tsx +20 -3
  14. package/flow-report/src/sidebar/sidebar.tsx +11 -16
  15. package/flow-report/src/summary/category.tsx +42 -24
  16. package/flow-report/src/summary/summary.tsx +32 -29
  17. package/flow-report/src/topbar.tsx +54 -4
  18. package/flow-report/src/util.ts +26 -1
  19. package/flow-report/src/wrappers/report-renderer.tsx +1 -1
  20. package/flow-report/src/wrappers/report.tsx +6 -21
  21. package/flow-report/test/app-test.tsx +17 -13
  22. package/flow-report/test/common-test.tsx +89 -0
  23. package/flow-report/test/header-test.tsx +55 -0
  24. package/flow-report/test/sample-flow.ts +17 -0
  25. package/flow-report/test/setup/env-setup.ts +1 -0
  26. package/flow-report/test/sidebar/flow-test.tsx +6 -12
  27. package/flow-report/test/sidebar/sidebar-test.tsx +7 -13
  28. package/flow-report/test/summary/category-test.tsx +79 -34
  29. package/flow-report/test/summary/summary-test.tsx +11 -17
  30. package/flow-report/test/topbar-test.tsx +68 -0
  31. package/flow-report/test/util-test.tsx +1 -12
  32. package/flow-report/tsconfig.json +1 -0
  33. package/flow-report/types/flow-report.d.ts +2 -1
  34. package/jest.config.js +1 -15
  35. package/lighthouse-cli/bin.js +5 -0
  36. package/lighthouse-cli/cli-flags.js +10 -3
  37. package/lighthouse-cli/commands/commands.js +1 -0
  38. package/lighthouse-cli/commands/list-locales.js +16 -0
  39. package/lighthouse-cli/run.js +2 -2
  40. package/lighthouse-cli/test/smokehouse/frontends/smokehouse-bin.js +0 -0
  41. package/lighthouse-cli/test/smokehouse/report-assert.js +20 -4
  42. package/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +2 -1
  43. package/lighthouse-core/audits/byte-efficiency/unused-javascript.js +1 -1
  44. package/lighthouse-core/audits/seo/crawlable-anchors.js +10 -12
  45. package/lighthouse-core/computed/js-bundles.js +1 -2
  46. package/lighthouse-core/computed/unused-javascript-summary.js +3 -3
  47. package/lighthouse-core/config/config.js +2 -2
  48. package/lighthouse-core/config/default-config.js +5 -0
  49. package/lighthouse-core/fraggle-rock/api.js +10 -0
  50. package/lighthouse-core/fraggle-rock/config/filters.js +22 -3
  51. package/lighthouse-core/fraggle-rock/gather/driver.js +4 -0
  52. package/lighthouse-core/fraggle-rock/gather/navigation-runner.js +2 -2
  53. package/lighthouse-core/fraggle-rock/user-flow.js +35 -6
  54. package/lighthouse-core/gather/driver/navigation.js +5 -0
  55. package/lighthouse-core/gather/driver/prepare.js +14 -0
  56. package/lighthouse-core/gather/driver/storage.js +5 -0
  57. package/lighthouse-core/gather/gather-runner.js +2 -2
  58. package/lighthouse-core/gather/gatherers/dobetterweb/response-compression.js +5 -1
  59. package/lighthouse-core/gather/gatherers/full-page-screenshot.js +30 -24
  60. package/lighthouse-core/lib/cdt/Platform.js +55 -0
  61. package/lighthouse-core/lib/cdt/SDK.js +3 -123
  62. package/lighthouse-core/lib/cdt/generated/SourceMap.js +148 -312
  63. package/lighthouse-core/lib/csp-evaluator.js +2 -1
  64. package/lighthouse-core/lib/i18n/README.md +6 -6
  65. package/lighthouse-core/lib/i18n/i18n.js +9 -342
  66. package/lighthouse-core/lib/page-functions.js +4 -4
  67. package/lighthouse-core/lib/stack-packs.js +1 -13
  68. package/lighthouse-core/runner.js +6 -6
  69. package/lighthouse-core/scripts/manual-chrome-launcher.js +4 -1
  70. package/lighthouse-core/scripts/package.json +4 -0
  71. package/lighthouse-core/util-commonjs.js +20 -4
  72. package/package.json +19 -16
  73. package/readme.md +1 -1
  74. package/report/assets/standalone-template.html +0 -1
  75. package/report/assets/styles.css +16 -41
  76. package/report/assets/templates.html +42 -4
  77. package/report/clients/psi.js +1 -0
  78. package/report/clients/standalone.js +1 -2
  79. package/report/generator/file-namer.js +17 -8
  80. package/report/generator/report-generator.js +0 -1
  81. package/report/renderer/category-renderer.js +4 -16
  82. package/report/renderer/components.js +107 -71
  83. package/report/renderer/dom.js +19 -0
  84. package/report/renderer/logger.js +35 -2
  85. package/report/renderer/performance-category-renderer.js +23 -21
  86. package/report/renderer/pwa-category-renderer.js +1 -2
  87. package/report/renderer/report-renderer.js +21 -0
  88. package/report/renderer/report-ui-features.js +7 -19
  89. package/report/renderer/swap-locale-feature.js +82 -0
  90. package/report/renderer/util.js +20 -4
  91. package/report/test/clients/psi-test.js +0 -4
  92. package/report/test/generator/file-namer-test.js +2 -2
  93. package/report/test/renderer/category-renderer-test.js +1 -1
  94. package/report/test/renderer/performance-category-renderer-test.js +12 -0
  95. package/report/test/renderer/report-renderer-axe-test.js +86 -0
  96. package/report/test/renderer/report-renderer-test.js +0 -55
  97. package/report/test/renderer/util-test.js +68 -8
  98. package/report/test-assets/faux-psi-template.html +0 -1
  99. package/report/tsconfig.json +2 -1
  100. package/report/types/html-renderer.d.ts +2 -1
  101. package/root.js +18 -0
  102. package/shared/localization/format.js +422 -0
  103. package/{lighthouse-core/lib/cdt/Common.js → shared/localization/i18n-module.js} +3 -8
  104. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ar-XB.json +139 -4
  105. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ar.json +141 -6
  106. package/{lighthouse-core/lib/i18n → shared/localization}/locales/bg.json +139 -4
  107. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ca.json +140 -5
  108. package/{lighthouse-core/lib/i18n → shared/localization}/locales/cs.json +139 -4
  109. package/{lighthouse-core/lib/i18n → shared/localization}/locales/da.json +139 -4
  110. package/{lighthouse-core/lib/i18n → shared/localization}/locales/de.json +139 -4
  111. package/{lighthouse-core/lib/i18n → shared/localization}/locales/el.json +141 -6
  112. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-GB.json +139 -4
  113. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-US.json +111 -0
  114. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-XA.json +139 -4
  115. package/{lighthouse-core/lib/i18n → shared/localization}/locales/en-XL.json +111 -0
  116. package/{lighthouse-core/lib/i18n → shared/localization}/locales/es-419.json +139 -4
  117. package/{lighthouse-core/lib/i18n → shared/localization}/locales/es.json +139 -4
  118. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fi.json +139 -4
  119. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fil.json +139 -4
  120. package/{lighthouse-core/lib/i18n → shared/localization}/locales/fr.json +139 -4
  121. package/{lighthouse-core/lib/i18n → shared/localization}/locales/he.json +139 -4
  122. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hi.json +142 -7
  123. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hr.json +139 -4
  124. package/{lighthouse-core/lib/i18n → shared/localization}/locales/hu.json +139 -4
  125. package/{lighthouse-core/lib/i18n → shared/localization}/locales/id.json +139 -4
  126. package/{lighthouse-core/lib/i18n → shared/localization}/locales/it.json +139 -4
  127. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ja.json +139 -4
  128. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ko.json +139 -4
  129. package/{lighthouse-core/lib/i18n → shared/localization}/locales/lt.json +139 -4
  130. package/{lighthouse-core/lib/i18n → shared/localization}/locales/lv.json +139 -4
  131. package/{lighthouse-core/lib/i18n → shared/localization}/locales/nl.json +139 -4
  132. package/{lighthouse-core/lib/i18n → shared/localization}/locales/no.json +139 -4
  133. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pl.json +139 -4
  134. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pt-PT.json +139 -4
  135. package/{lighthouse-core/lib/i18n → shared/localization}/locales/pt.json +139 -4
  136. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ro.json +139 -4
  137. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ru.json +139 -4
  138. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sk.json +139 -4
  139. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sl.json +139 -4
  140. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sr-Latn.json +139 -4
  141. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sr.json +139 -4
  142. package/{lighthouse-core/lib/i18n → shared/localization}/locales/sv.json +139 -4
  143. package/{lighthouse-core/lib/i18n → shared/localization}/locales/ta.json +146 -11
  144. package/{lighthouse-core/lib/i18n → shared/localization}/locales/te.json +179 -44
  145. package/{lighthouse-core/lib/i18n → shared/localization}/locales/th.json +139 -4
  146. package/{lighthouse-core/lib/i18n → shared/localization}/locales/tr.json +139 -4
  147. package/{lighthouse-core/lib/i18n → shared/localization}/locales/uk.json +139 -4
  148. package/{lighthouse-core/lib/i18n → shared/localization}/locales/vi.json +139 -4
  149. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh-HK.json +139 -4
  150. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh-TW.json +139 -4
  151. package/{lighthouse-core/lib/i18n → shared/localization}/locales/zh.json +139 -4
  152. package/{lighthouse-core/lib/i18n → shared/localization}/locales.js +2 -1
  153. package/shared/localization/swap-flow-locale.js +20 -0
  154. package/{lighthouse-core/lib/i18n → shared/localization}/swap-locale.js +9 -7
  155. package/shared/test/localization/format-test.js +377 -0
  156. package/shared/test/localization/locales-test.js +47 -0
  157. package/shared/test/localization/swap-locale-test.js +140 -0
  158. package/shared/tsconfig.json +22 -0
  159. package/{lighthouse-core/lib → shared}/type-verifiers.js +0 -0
  160. package/shared/types/shared.d.ts +24 -0
  161. package/third-party/chromium-synchronization/inspector-issueAdded-types-test.js +5 -3
  162. package/third-party/chromium-synchronization/installability-errors-test.js +2 -1
  163. package/tsconfig-all.json +1 -0
  164. package/tsconfig-base.json +1 -1
  165. package/tsconfig.json +2 -3
  166. package/types/config.d.ts +1 -0
  167. package/types/es-main.d.ts +18 -0
  168. package/types/externs.d.ts +2 -0
  169. package/types/lhr/flow.d.ts +7 -0
  170. package/types/lhr/i18n.d.ts +0 -3
  171. package/dist/report/flow.js +0 -149
  172. package/dist/report/standalone.js +0 -228
@@ -1,7 +1,7 @@
1
1
  # Terminology
2
2
 
3
3
  * **CTC format**: The [Chrome extension & Chrome app i18n format](https://developer.chrome.com/extensions/i18n-messages) with some minor changes. JSON with their specified model for declaring placeholders, examples, etc. Used as an interchange data format.
4
- * **LHL syntax** (Lighthouse Localizable syntax): The ICU-friendly string syntax that is used to author `UIStrings` and is seen in the locale files in `i18n/locales/*.json`. Lighthouse has a custom syntax these strings combines many ICU message features along with some markdown.
4
+ * **LHL syntax** (Lighthouse Localizable syntax): The ICU-friendly string syntax that is used to author `UIStrings` and is seen in the locale files in `shared/localization/locales/*.json`. Lighthouse has a custom syntax these strings combines many ICU message features along with some markdown.
5
5
  * **ICU**: ICU (International Components for Unicode) is a localization project and standard defined by the Unicode consortium. In general, we refer to "ICU" as the [ICU message formatting](http://userguide.icu-project.org/formatparse/messages) syntax.
6
6
 
7
7
  # The Lighthouse i18n pipeline
@@ -12,11 +12,11 @@ The collection and translation pipeline:
12
12
  ```
13
13
  Source files: Locale files:
14
14
  +---------------------------+ +----------------------------------------------
15
- | ++ | lighthouse-core/lib/i18n/locales/en-US.json |
16
- | const UIStrings = { ... };|-+ +---> | lighthouse-core/lib/i18n/locales/en-XL.json |
15
+ | ++ | shared/localization/locales/en-US.json |
16
+ | const UIStrings = { ... };|-+ +---> | shared/localization/locales/en-XL.json |
17
17
  | |-| | +----------------------------------------------+
18
18
  +-----------------------------| | | ||
19
- +----------------------------| | | lighthouse-core/lib/i18n/locales/*.json |-<+
19
+ +----------------------------| | | shared/localization/locales/*.json |-<+
20
20
  +---------------------------+ | | || |
21
21
  | | +----------------------------------------------| |
22
22
  $ yarn | | +---------------------------------------------+ |
@@ -218,7 +218,7 @@ CTC is a name that is distinct and identifies this as the Chrome translation for
218
218
  1. String called in `.js` file, converted to `LH.IcuMessage` object.
219
219
 
220
220
  1. Message object is replaced with the localized string via
221
- `i18n.replaceIcuMessages` and `i18n.getFormatted`.
221
+ `format.replaceIcuMessages` and `format.getFormatted`.
222
222
 
223
223
  #### Example:
224
224
 
@@ -251,7 +251,7 @@ CTC is a name that is distinct and identifies this as the Chrome translation for
251
251
  }
252
252
  ```
253
253
 
254
- 3. Lookup in `i18n.replaceIcuMessages` and `i18n.getFormatted` will attempt to find the message in this order:
254
+ 3. Lookup in `format.replaceIcuMessages` and `format.getFormatted` will attempt to find the message in this order:
255
255
 
256
256
  1. `locales/{locale}.json` The best result. `icuMessage.i18nId` is found in the target locale and the resulting string should appear correct.
257
257
 
@@ -5,23 +5,17 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- /** @typedef {import('../../lib/i18n/locales').LhlMessages} LhlMessages */
8
+ /** @typedef {import('../../../shared/localization/locales').LhlMessages} LhlMessages */
9
9
 
10
10
  const path = require('path');
11
- const MessageFormat = require('intl-messageformat').default;
12
11
  const lookupClosestLocale = require('lookup-closest-locale');
13
- const LOCALES = require('./locales.js');
14
- const {isObjectOfUnknownValues, isObjectOrArrayOfUnknownValues} = require('../type-verifiers.js');
12
+ const {getAvailableLocales} = require('../../../shared/localization/format.js');
15
13
  const log = require('lighthouse-logger');
16
14
  const {LH_ROOT} = require('../../../root.js');
15
+ const {isIcuMessage, _formatMessage} = require('../../../shared/localization/format.js');
17
16
 
18
17
  const DEFAULT_LOCALE = 'en';
19
18
 
20
- /** @typedef {import('intl-messageformat-parser').Element} MessageElement */
21
- /** @typedef {import('intl-messageformat-parser').ArgumentElement} ArgumentElement */
22
-
23
- const MESSAGE_I18N_ID_REGEX = / | [^\s]+$/;
24
-
25
19
  const UIStrings = {
26
20
  /** Used to show the duration in milliseconds that something lasted. The `{timeInMs}` placeholder will be replaced with the time duration, shown in milliseconds (e.g. 63 ms) */
27
21
  ms: '{timeInMs, number, milliseconds}\xa0ms',
@@ -117,27 +111,6 @@ const UIStrings = {
117
111
  itemSeverityHigh: 'High',
118
112
  };
119
113
 
120
- const formats = {
121
- number: {
122
- bytes: {
123
- maximumFractionDigits: 0,
124
- },
125
- milliseconds: {
126
- maximumFractionDigits: 0,
127
- },
128
- seconds: {
129
- // Force the seconds to the tenths place for limited output and ease of scanning
130
- minimumFractionDigits: 1,
131
- maximumFractionDigits: 1,
132
- },
133
- extendedPercent: {
134
- // Force allow up to two digits after decimal place in percentages. (Intl.NumberFormat options)
135
- maximumFractionDigits: 2,
136
- style: 'percent',
137
- },
138
- },
139
- };
140
-
141
114
  /**
142
115
  * Look up the best available locale for the requested language through these fall backs:
143
116
  * - exact match
@@ -160,7 +133,12 @@ function lookupLocale(locales) {
160
133
  // Filter by what's available in this runtime.
161
134
  const availableLocales = Intl.NumberFormat.supportedLocalesOf(canonicalLocales);
162
135
 
163
- const closestLocale = lookupClosestLocale(availableLocales, LOCALES);
136
+ // Get available locales and transform into object to match `lookupClosestLocale`'s API.
137
+ const localesWithMessages = getAvailableLocales();
138
+ const localesWithmessagesObj = /** @type {Record<LH.Locale, LhlMessages>} */ (
139
+ Object.fromEntries(localesWithMessages.map(l => [l, {}])));
140
+
141
+ const closestLocale = lookupClosestLocale(availableLocales, localesWithmessagesObj);
164
142
 
165
143
  if (!closestLocale) {
166
144
  // Log extra info if we're pretty sure this version of Node was built with `--with-intl=small-icu`.
@@ -174,191 +152,6 @@ function lookupLocale(locales) {
174
152
  return closestLocale || DEFAULT_LOCALE;
175
153
  }
176
154
 
177
- /**
178
- * Function to retrieve all 'argumentElement's from an ICU message. An argumentElement
179
- * is an ICU element with an argument in it, like '{varName}' or '{varName, number, bytes}'. This
180
- * differs from 'messageElement's which are just arbitrary text in a message.
181
- *
182
- * Notes:
183
- * This function will recursively inspect plural elements for nested argumentElements.
184
- *
185
- * We need to find all the elements from the plural format sections, but
186
- * they need to be deduplicated. I.e. "=1{hello {icu}} =other{hello {icu}}"
187
- * the variable "icu" would appear twice if it wasn't de duplicated. And they cannot
188
- * be stored in a set because they are not equal since their locations are different,
189
- * thus they are stored via a Map keyed on the "id" which is the ICU varName.
190
- *
191
- * @param {Array<MessageElement>} icuElements
192
- * @param {Map<string, ArgumentElement>} [seenElementsById]
193
- * @return {Map<string, ArgumentElement>}
194
- */
195
- function collectAllCustomElementsFromICU(icuElements, seenElementsById = new Map()) {
196
- for (const el of icuElements) {
197
- // We are only interested in elements that need ICU formatting (argumentElements)
198
- if (el.type !== 'argumentElement') continue;
199
-
200
- seenElementsById.set(el.id, el);
201
-
202
- // Plurals need to be inspected recursively
203
- if (!el.format || el.format.type !== 'pluralFormat') continue;
204
- // Look at all options of the plural (=1{} =other{}...)
205
- for (const option of el.format.options) {
206
- // Run collections on each option's elements
207
- collectAllCustomElementsFromICU(option.value.elements, seenElementsById);
208
- }
209
- }
210
-
211
- return seenElementsById;
212
- }
213
-
214
- /**
215
- * Returns a copy of the `values` object, with the values formatted based on how
216
- * they will be used in their icuMessage, e.g. KB or milliseconds. The original
217
- * object is unchanged.
218
- * @param {MessageFormat} messageFormatter
219
- * @param {Readonly<Record<string, string | number>>} values
220
- * @param {string} lhlMessage Used for clear error logging.
221
- * @return {Record<string, string | number>}
222
- */
223
- function _preformatValues(messageFormatter, values, lhlMessage) {
224
- const elementMap = collectAllCustomElementsFromICU(messageFormatter.getAst().elements);
225
- const argumentElements = [...elementMap.values()];
226
-
227
- /** @type {Record<string, string | number>} */
228
- const formattedValues = {};
229
-
230
- for (const {id, format} of argumentElements) {
231
- // Throw an error if a message's value isn't provided
232
- if (id && (id in values) === false) {
233
- throw new Error(`ICU Message "${lhlMessage}" contains a value reference ("${id}") ` +
234
- `that wasn't provided`);
235
- }
236
-
237
- const value = values[id];
238
-
239
- // Direct `{id}` replacement and non-numeric values need no formatting.
240
- if (!format || format.type !== 'numberFormat') {
241
- formattedValues[id] = value;
242
- continue;
243
- }
244
-
245
- if (typeof value !== 'number') {
246
- throw new Error(`ICU Message "${lhlMessage}" contains a numeric reference ("${id}") ` +
247
- 'but provided value was not a number');
248
- }
249
-
250
- // Format values for known styles.
251
- if (format.style === 'milliseconds') {
252
- // Round all milliseconds to the nearest 10.
253
- formattedValues[id] = Math.round(value / 10) * 10;
254
- } else if (format.style === 'seconds' && id === 'timeInMs') {
255
- // Convert all seconds to the correct unit (currently only for `timeInMs`).
256
- formattedValues[id] = Math.round(value / 100) / 10;
257
- } else if (format.style === 'bytes') {
258
- // Replace all the bytes with KB.
259
- formattedValues[id] = value / 1024;
260
- } else {
261
- // For all other number styles, the value isn't changed.
262
- formattedValues[id] = value;
263
- }
264
- }
265
-
266
- // Throw an error if a value is provided but has no placeholder in the message.
267
- for (const valueId of Object.keys(values)) {
268
- if (valueId in formattedValues) continue;
269
-
270
- // errorCode is a special case always allowed to help LHError ease-of-use.
271
- if (valueId === 'errorCode') {
272
- formattedValues.errorCode = values.errorCode;
273
- continue;
274
- }
275
-
276
- throw new Error(`Provided value "${valueId}" does not match any placeholder in ` +
277
- `ICU message "${lhlMessage}"`);
278
- }
279
-
280
- return formattedValues;
281
- }
282
-
283
- /**
284
- * Format string `message` by localizing `values` and inserting them.
285
- * @param {string} message
286
- * @param {Record<string, string | number>} values
287
- * @param {LH.Locale} locale
288
- * @return {string}
289
- */
290
- function _formatMessage(message, values = {}, locale) {
291
- // When using accented english, force the use of a different locale for number formatting.
292
- const localeForMessageFormat = (locale === 'en-XA' || locale === 'en-XL') ? 'de-DE' : locale;
293
-
294
- const formatter = new MessageFormat(message, localeForMessageFormat, formats);
295
-
296
- // Preformat values for the message format like KB and milliseconds.
297
- const valuesForMessageFormat = _preformatValues(formatter, values, message);
298
-
299
- return formatter.format(valuesForMessageFormat);
300
- }
301
-
302
- /**
303
- * Retrieves the localized version of `icuMessage` and formats with any given
304
- * value replacements.
305
- * @param {LH.IcuMessage} icuMessage
306
- * @param {LH.Locale} locale
307
- * @return {string}
308
- */
309
- function _localizeIcuMessage(icuMessage, locale) {
310
- const localeMessages = LOCALES[locale];
311
- if (!localeMessages) throw new Error(`Unsupported locale '${locale}'`);
312
- const localeMessage = localeMessages[icuMessage.i18nId];
313
-
314
- // Fall back to the default (usually the original english message) if we couldn't find a
315
- // message in the specified locale. This could be because of string drift between
316
- // Lighthouse versions or because new strings haven't been updated yet. Better to have
317
- // an english message than no message at all; in some cases it won't even matter.
318
- if (!localeMessage) {
319
- return icuMessage.formattedDefault;
320
- }
321
-
322
- return _formatMessage(localeMessage.message, icuMessage.values, locale);
323
- }
324
-
325
- /** @param {string[]} pathInLHR */
326
- function _formatPathAsString(pathInLHR) {
327
- let pathAsString = '';
328
- for (const property of pathInLHR) {
329
- if (/^[a-z]+$/i.test(property)) {
330
- if (pathAsString.length) pathAsString += '.';
331
- pathAsString += property;
332
- } else {
333
- if (/]|"|'|\s/.test(property)) throw new Error(`Cannot handle "${property}" in i18n`);
334
- pathAsString += `[${property}]`;
335
- }
336
- }
337
-
338
- return pathAsString;
339
- }
340
-
341
- /**
342
- * @param {LH.Locale} locale
343
- * @return {Record<string, string>}
344
- */
345
- function getRendererFormattedStrings(locale) {
346
- const localeMessages = LOCALES[locale];
347
- if (!localeMessages) throw new Error(`Unsupported locale '${locale}'`);
348
-
349
- const icuMessageIds = Object.keys(localeMessages).filter(f => f.startsWith('report/'));
350
- /** @type {Record<string, string>} */
351
- const strings = {};
352
- for (const icuMessageId of icuMessageIds) {
353
- const [filename, key] = icuMessageId.split(' | ');
354
- if (!filename.endsWith('util.js')) throw new Error(`Unexpected message: ${icuMessageId}`);
355
-
356
- strings[key] = localeMessages[icuMessageId].message;
357
- }
358
-
359
- return strings;
360
- }
361
-
362
155
  /**
363
156
  * Returns a function that generates `LH.IcuMessage` objects to localize the
364
157
  * messages in `fileStrings` and the shared `i18n.UIStrings`.
@@ -396,125 +189,6 @@ function createIcuMessageFn(filename, fileStrings) {
396
189
  return getIcuMessageFn;
397
190
  }
398
191
 
399
- /**
400
- * Returns whether `icuMessageOrNot`` is an `LH.IcuMessage` instance.
401
- * @param {unknown} icuMessageOrNot
402
- * @return {icuMessageOrNot is LH.IcuMessage}
403
- */
404
- function isIcuMessage(icuMessageOrNot) {
405
- if (!isObjectOfUnknownValues(icuMessageOrNot)) {
406
- return false;
407
- }
408
-
409
- const {i18nId, values, formattedDefault} = icuMessageOrNot;
410
- if (typeof i18nId !== 'string') {
411
- return false;
412
- }
413
-
414
- // formattedDefault is required.
415
- if (typeof formattedDefault !== 'string') {
416
- return false;
417
- }
418
-
419
- // Values is optional.
420
- if (values !== undefined) {
421
- if (!isObjectOfUnknownValues(values)) {
422
- return false;
423
- }
424
- for (const value of Object.values(values)) {
425
- if (typeof value !== 'string' && typeof value !== 'number') {
426
- return false;
427
- }
428
- }
429
- }
430
-
431
- // Finally return true if i18nId seems correct.
432
- return MESSAGE_I18N_ID_REGEX.test(i18nId);
433
- }
434
-
435
- /**
436
- * Get the localized and formatted form of `icuMessageOrRawString` if it's an
437
- * LH.IcuMessage, or get it back directly if it's already a string.
438
- * Warning: this function throws if `icuMessageOrRawString` is not the expected
439
- * type (use function from `createIcuMessageFn` to create a valid LH.IcuMessage)
440
- * or `locale` isn't supported (use `lookupLocale` to find a valid locale).
441
- * @param {LH.IcuMessage | string} icuMessageOrRawString
442
- * @param {LH.Locale} locale
443
- * @return {string}
444
- */
445
- function getFormatted(icuMessageOrRawString, locale) {
446
- if (isIcuMessage(icuMessageOrRawString)) {
447
- return _localizeIcuMessage(icuMessageOrRawString, locale);
448
- }
449
-
450
- if (typeof icuMessageOrRawString === 'string') {
451
- return icuMessageOrRawString;
452
- }
453
-
454
- // Should be impossible from types, but do a strict check in case malformed JSON makes it this far.
455
- throw new Error('Attempted to format invalid icuMessage type');
456
- }
457
-
458
- /**
459
- * Recursively walk the input object, looking for property values that are
460
- * `LH.IcuMessage`s and replace them with their localized values. Primarily
461
- * used with the full LHR or a Config as input.
462
- * Returns a map of locations that were replaced to the `IcuMessage` that was at
463
- * that location.
464
- * @param {unknown} inputObject
465
- * @param {LH.Locale} locale
466
- * @return {LH.Result.IcuMessagePaths}
467
- */
468
- function replaceIcuMessages(inputObject, locale) {
469
- /**
470
- * @param {unknown} subObject
471
- * @param {LH.Result.IcuMessagePaths} icuMessagePaths
472
- * @param {string[]} pathInLHR
473
- */
474
- function replaceInObject(subObject, icuMessagePaths, pathInLHR = []) {
475
- if (!isObjectOrArrayOfUnknownValues(subObject)) return;
476
-
477
- for (const [property, possibleIcuMessage] of Object.entries(subObject)) {
478
- const currentPathInLHR = pathInLHR.concat([property]);
479
-
480
- // Replace any IcuMessages with a localized string.
481
- if (isIcuMessage(possibleIcuMessage)) {
482
- const formattedString = _localizeIcuMessage(possibleIcuMessage, locale);
483
- const messageInstancesInLHR = icuMessagePaths[possibleIcuMessage.i18nId] || [];
484
- const currentPathAsString = _formatPathAsString(currentPathInLHR);
485
-
486
- messageInstancesInLHR.push(
487
- possibleIcuMessage.values ?
488
- {values: possibleIcuMessage.values, path: currentPathAsString} :
489
- currentPathAsString
490
- );
491
-
492
- // @ts-ignore - tsc doesn't like that `property` can be either string key or array index.
493
- subObject[property] = formattedString;
494
- icuMessagePaths[possibleIcuMessage.i18nId] = messageInstancesInLHR;
495
- } else {
496
- replaceInObject(possibleIcuMessage, icuMessagePaths, currentPathInLHR);
497
- }
498
- }
499
- }
500
-
501
- /** @type {LH.Result.IcuMessagePaths} */
502
- const icuMessagePaths = {};
503
- replaceInObject(inputObject, icuMessagePaths);
504
- return icuMessagePaths;
505
- }
506
-
507
- /**
508
- * Populate the i18n string lookup dict with locale data
509
- * Used when the host environment selects the locale and serves lighthouse the intended locale file
510
- * @see https://docs.google.com/document/d/1jnt3BqKB-4q3AE94UWFA0Gqspx8Sd_jivlB7gQMlmfk/edit
511
- * @param {LH.Locale} locale
512
- * @param {LhlMessages} lhlMessages
513
- */
514
- function registerLocaleData(locale, lhlMessages) {
515
- LOCALES[locale] = lhlMessages;
516
- }
517
-
518
192
  /**
519
193
  * Returns true if the given value is a string or an LH.IcuMessage.
520
194
  * @param {unknown} value
@@ -525,16 +199,9 @@ function isStringOrIcuMessage(value) {
525
199
  }
526
200
 
527
201
  module.exports = {
528
- _formatPathAsString,
529
202
  UIStrings,
530
203
  lookupLocale,
531
- getRendererFormattedStrings,
532
204
  createIcuMessageFn,
533
- getFormatted,
534
- replaceIcuMessages,
535
- isIcuMessage,
536
- collectAllCustomElementsFromICU,
537
- registerLocaleData,
538
205
  isStringOrIcuMessage,
539
206
  // TODO: exported for backwards compatibility. Consider removing on future breaking change.
540
207
  createMessageInstanceIdFn: createIcuMessageFn,
@@ -530,8 +530,8 @@ module.exports = {
530
530
  getElementsInDocument,
531
531
  getElementsInDocumentString: getElementsInDocument.toString(),
532
532
  getOuterHTMLSnippetString: getOuterHTMLSnippet.toString(),
533
- getOuterHTMLSnippet: getOuterHTMLSnippet,
534
- computeBenchmarkIndex: computeBenchmarkIndex,
533
+ getOuterHTMLSnippet,
534
+ computeBenchmarkIndex,
535
535
  computeBenchmarkIndexString: computeBenchmarkIndex.toString(),
536
536
  getMaxTextureSize,
537
537
  getNodeDetailsString,
@@ -539,8 +539,8 @@ module.exports = {
539
539
  getNodePathString: getNodePath.toString(),
540
540
  getNodeSelectorString: getNodeSelector.toString(),
541
541
  getNodePath,
542
- getNodeSelector: getNodeSelector,
543
- getNodeLabel: getNodeLabel,
542
+ getNodeSelector,
543
+ getNodeLabel,
544
544
  getNodeLabelString: getNodeLabel.toString(),
545
545
  isPositionFixedString: isPositionFixed.toString(),
546
546
  wrapRequestIdleCallback,
@@ -9,18 +9,6 @@ const log = require('lighthouse-logger');
9
9
  const stackPacks = require('lighthouse-stack-packs');
10
10
  const i18n = require('./i18n/i18n.js');
11
11
 
12
- /**
13
- * Resolve a module on web and node
14
- * @param {string} module
15
- */
16
- function resolve(module) {
17
- if (!require.resolve) {
18
- return `node_modules/${module}`;
19
- }
20
-
21
- return require.resolve(module);
22
- }
23
-
24
12
  /**
25
13
  * Pairs consisting of a stack pack's ID and the set of stacks needed to be
26
14
  * detected in a page to display that pack's advice.
@@ -87,7 +75,7 @@ function getStackPacks(pageStacks) {
87
75
 
88
76
  // Create i18n handler to get translated strings.
89
77
  const str_ = i18n.createMessageInstanceIdFn(
90
- resolve(`lighthouse-stack-packs/packs/${matchedPack.id}`),
78
+ `node_modules/lighthouse-stack-packs/packs/${matchedPack.id}.js`,
91
79
  matchedPack.UIStrings
92
80
  );
93
81
 
@@ -11,7 +11,7 @@ const GatherRunner = require('./gather/gather-runner.js');
11
11
  const ReportScoring = require('./scoring.js');
12
12
  const Audit = require('./audits/audit.js');
13
13
  const log = require('lighthouse-logger');
14
- const i18n = require('./lib/i18n/i18n.js');
14
+ const format = require('../shared/localization/format.js');
15
15
  const stackPacks = require('./lib/stack-packs.js');
16
16
  const assetSaver = require('./lib/asset-saver.js');
17
17
  const fs = require('fs');
@@ -152,14 +152,14 @@ class Runner {
152
152
  categoryGroups: runOpts.config.groups || undefined,
153
153
  timing: this._getTiming(artifacts),
154
154
  i18n: {
155
- rendererFormattedStrings: i18n.getRendererFormattedStrings(settings.locale),
155
+ rendererFormattedStrings: format.getRendererFormattedStrings(settings.locale),
156
156
  icuMessagePaths: {},
157
157
  },
158
158
  stackPacks: stackPacks.getStackPacks(artifacts.Stacks),
159
159
  };
160
160
 
161
161
  // Replace ICU message references with localized strings; save replaced paths in lhr.
162
- i18nLhr.i18n.icuMessagePaths = i18n.replaceIcuMessages(i18nLhr, settings.locale);
162
+ i18nLhr.i18n.icuMessagePaths = format.replaceIcuMessages(i18nLhr, settings.locale);
163
163
 
164
164
  // LHR has now been localized.
165
165
  const lhr = /** @type {LH.Result} */ (i18nLhr);
@@ -177,7 +177,7 @@ class Runner {
177
177
  } catch (err) {
178
178
  // i18n LighthouseError strings.
179
179
  if (err.friendlyMessage) {
180
- err.friendlyMessage = i18n.getFormatted(err.friendlyMessage, settings.locale);
180
+ err.friendlyMessage = format.getFormatted(err.friendlyMessage, settings.locale);
181
181
  }
182
182
  await Sentry.captureException(err, {level: 'fatal'});
183
183
  throw err;
@@ -211,7 +211,7 @@ class Runner {
211
211
  duration: parseFloat(entry.duration.toFixed(2)),
212
212
  entryType: entry.entryType,
213
213
  };
214
- });
214
+ }).sort((a, b) => a.startTime - b.startTime);
215
215
  const runnerEntry = timingEntries.find(e => e.name === 'lh:runner:run');
216
216
  return {entries: timingEntries, total: runnerEntry && runnerEntry.duration || 0};
217
217
  }
@@ -301,7 +301,7 @@ class Runner {
301
301
  static async _runAudit(auditDefn, artifacts, sharedAuditContext, runWarnings) {
302
302
  const audit = auditDefn.implementation;
303
303
  const status = {
304
- msg: `Auditing: ${i18n.getFormatted(audit.meta.title, 'en-US')}`,
304
+ msg: `Auditing: ${format.getFormatted(audit.meta.title, 'en-US')}`,
305
305
  id: `lh:audit:${audit.meta.id}`,
306
306
  };
307
307
  log.time(status);
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  'use strict';
4
+
4
5
  /**
5
6
  * @fileoverview Script to launch a clean Chrome instance on-demand.
6
7
  *
8
+ * node lighthouse-core/scripts/manual-chrome-launcher.js
9
+ *
7
10
  * Assuming Lighthouse is installed globally or `npm link`ed, use via:
8
11
  * chrome-debug
9
12
  * Optionally enable extensions or pass a port, additional chrome flags, and/or a URL
@@ -13,7 +16,7 @@
13
16
  * chrome-debug --enable-extensions
14
17
  */
15
18
 
16
- const {Launcher, launch} = require('chrome-launcher');
19
+ import {Launcher, launch} from 'chrome-launcher';
17
20
 
18
21
  const args = process.argv.slice(2);
19
22
  const chromeFlags = [];
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "//": "Any directory that uses `import ... from` or `export ...` must be type module. Temporary file until root package.json is type: module"
4
+ }
@@ -521,15 +521,31 @@ class Util {
521
521
  * @param {LH.ReportResult.Category} category
522
522
  */
523
523
  static calculateCategoryFraction(category) {
524
- const numAudits = category.auditRefs.length;
525
-
524
+ let numPassableAudits = 0;
526
525
  let numPassed = 0;
526
+ let numInformative = 0;
527
527
  let totalWeight = 0;
528
528
  for (const auditRef of category.auditRefs) {
529
+ const auditPassed = Util.showAsPassed(auditRef.result);
530
+ const notDisplayed = !auditRef.group && category.id === 'performance';
531
+
532
+ // Don't count the audit if it's manual, N/A, or isn't displayed.
533
+ if (notDisplayed ||
534
+ auditRef.result.scoreDisplayMode === 'manual' ||
535
+ auditRef.result.scoreDisplayMode === 'notApplicable') {
536
+ continue;
537
+ } else if (auditRef.result.scoreDisplayMode === 'informative') {
538
+ if (!auditPassed) {
539
+ ++numInformative;
540
+ }
541
+ continue;
542
+ }
543
+
544
+ ++numPassableAudits;
529
545
  totalWeight += auditRef.weight;
530
- if (Util.showAsPassed(auditRef.result)) numPassed++;
546
+ if (auditPassed) numPassed++;
531
547
  }
532
- return {numPassed, numAudits, totalWeight};
548
+ return {numPassed, numPassableAudits, numInformative, totalWeight};
533
549
  }
534
550
  }
535
551