From 38c534c732595279407b0b70ff8a1f267ec44646 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 23 Nov 2020 21:45:40 -0600 Subject: [PATCH] deps: update to typescript 4.1.2 (#11690) --- build/gh-pages-app.js | 3 +++ .../byte-efficiency/byte-efficiency-audit.js | 2 +- .../audits/byte-efficiency/unminified-css.js | 2 +- lighthouse-core/audits/dobetterweb/charset.js | 2 +- lighthouse-core/config/config.js | 2 +- lighthouse-core/gather/fetcher.js | 4 ++-- lighthouse-core/gather/gatherers/image-elements.js | 1 - .../lib/dependency-graph/simulator/simulator.js | 6 ++++-- lighthouse-core/lib/i18n/swap-locale.js | 2 ++ lighthouse-core/lib/lh-error.js | 5 +++-- lighthouse-core/report/html/renderer/util.js | 1 + .../scripts/generate-bundlephobia-database.js | 3 +-- lighthouse-core/scripts/lantern/constants.js | 14 ++++++++++---- .../scripts/lantern/print-correlations.js | 4 ++-- package.json | 2 +- types/lhr.d.ts | 2 +- yarn.lock | 8 ++++---- 17 files changed, 38 insertions(+), 25 deletions(-) diff --git a/build/gh-pages-app.js b/build/gh-pages-app.js index 4b963e8c567a..86860eb73c46 100644 --- a/build/gh-pages-app.js +++ b/build/gh-pages-app.js @@ -98,6 +98,9 @@ class GhPagesApp { }); } + /** + * @return {Promise} + */ deploy() { return new Promise((resolve, reject) => { ghPages.publish(this.distDir, { diff --git a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js index 7a7f9d9273dc..1e6b5e4c4dbd 100644 --- a/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js +++ b/lighthouse-core/audits/byte-efficiency/byte-efficiency-audit.js @@ -62,7 +62,7 @@ class UnusedBytes extends Audit { * Estimates the number of bytes this network record would have consumed on the network based on the * uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable. * - * @param {LH.Artifacts.NetworkRequest=} networkRecord + * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord * @param {number} totalBytes Uncompressed size of the resource * @param {LH.Crdp.Network.ResourceType=} resourceType * @return {number} diff --git a/lighthouse-core/audits/byte-efficiency/unminified-css.js b/lighthouse-core/audits/byte-efficiency/unminified-css.js index e9a6aa19943c..86e422d30424 100644 --- a/lighthouse-core/audits/byte-efficiency/unminified-css.js +++ b/lighthouse-core/audits/byte-efficiency/unminified-css.js @@ -52,7 +52,7 @@ class UnminifiedCSS extends ByteEfficiencyAudit { /** * @param {LH.Artifacts.CSSStyleSheetInfo} stylesheet - * @param {LH.Artifacts.NetworkRequest=} networkRecord + * @param {LH.Artifacts.NetworkRequest|undefined} networkRecord * @param {string} pageUrl * @return {{url: string, totalBytes: number, wastedBytes: number, wastedPercent: number}} */ diff --git a/lighthouse-core/audits/dobetterweb/charset.js b/lighthouse-core/audits/dobetterweb/charset.js index d28adcd993b0..110d60eac109 100644 --- a/lighthouse-core/audits/dobetterweb/charset.js +++ b/lighthouse-core/audits/dobetterweb/charset.js @@ -8,7 +8,7 @@ * @fileoverview Audits a page to ensure charset it configured properly. * It must be defined within the first 1024 bytes of the HTML document, defined in the HTTP header, or the document source must start with a BOM. * - * @see: https://github.com/GoogleChrome/lighthouse/issues/10023 + * @see https://github.com/GoogleChrome/lighthouse/issues/10023 */ 'use strict'; diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index f144cd2873ec..285099e0a75f 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -741,7 +741,7 @@ class Config { /** * @param {string} path - * @param {{}=} options + * @param {{}|undefined} options * @param {Array} coreAuditList * @param {string=} configDir * @return {LH.Config.GathererDefn} diff --git a/lighthouse-core/gather/fetcher.js b/lighthouse-core/gather/fetcher.js index cb6126e68460..7b1b695e3baa 100644 --- a/lighthouse-core/gather/fetcher.js +++ b/lighthouse-core/gather/fetcher.js @@ -156,8 +156,8 @@ class Fetcher { iframe.src = src; iframe.onload = iframe.onerror = () => { iframe.remove(); - delete iframe.onload; - delete iframe.onerror; + iframe.onload = null; + iframe.onerror = null; }; document.body.appendChild(iframe); } diff --git a/lighthouse-core/gather/gatherers/image-elements.js b/lighthouse-core/gather/gatherers/image-elements.js index a6f7ca0f5a4f..7e46ce6e032b 100644 --- a/lighthouse-core/gather/gatherers/image-elements.js +++ b/lighthouse-core/gather/gatherers/image-elements.js @@ -76,7 +76,6 @@ function getHTMLImages(allElements) { cssComputedPosition: getPosition(element, computedStyle), isCss: false, isPicture, - // @ts-expect-error: loading attribute not yet added to HTMLImageElement definition. loading: element.loading, resourceSize: 0, // this will get overwritten below usesObjectFit: ['cover', 'contain', 'scale-down', 'none'].includes( diff --git a/lighthouse-core/lib/dependency-graph/simulator/simulator.js b/lighthouse-core/lib/dependency-graph/simulator/simulator.js index b5d9557d1b40..4d3998ac46c6 100644 --- a/lighthouse-core/lib/dependency-graph/simulator/simulator.js +++ b/lighthouse-core/lib/dependency-graph/simulator/simulator.js @@ -143,11 +143,12 @@ class Simulator { /** * @param {Node} node - * @return {NodeTimingIntermediate} + * @return {Required} */ _getTimingData(node) { const timingData = this._nodeTimings.get(node); if (!timingData) throw new Error(`Unable to get timing data for node ${node.id}`); + // @ts-expect-error - Allow consumers to assume all values are defined. return timingData; } @@ -405,7 +406,8 @@ class Simulator { _computeFinalNodeTimings() { /** @type {Array<[Node, LH.Gatherer.Simulation.NodeTiming]>} */ const nodeTimingEntries = []; - for (const [node, timing] of this._nodeTimings) { + for (const node of this._nodeTimings.keys()) { + const timing = this._getTimingData(node); nodeTimingEntries.push([node, { startTime: timing.startTime, endTime: timing.endTime, diff --git a/lighthouse-core/lib/i18n/swap-locale.js b/lighthouse-core/lib/i18n/swap-locale.js index 5506c87f0904..13eb3a9eb19f 100644 --- a/lighthouse-core/lib/i18n/swap-locale.js +++ b/lighthouse-core/lib/i18n/swap-locale.js @@ -54,6 +54,8 @@ function swapLocale(lhr, requestedLocale) { const {icuMessagePaths} = lhr.i18n; const missingIcuMessageIds = []; + if (!icuMessagePaths) throw new Error('missing icuMessagePaths'); + for (const [i18nId, icuMessagePath] of Object.entries(icuMessagePaths)) { for (const instance of icuMessagePath) { // The path that _formatPathAsString() generated. diff --git a/lighthouse-core/lib/lh-error.js b/lighthouse-core/lib/lh-error.js index 1d4dc61a0661..4463e0afc4e0 100644 --- a/lighthouse-core/lib/lh-error.js +++ b/lighthouse-core/lib/lh-error.js @@ -132,9 +132,10 @@ class LighthouseError extends Error { */ static fromProtocolMessage(method, protocolError) { // extract all errors with a regex pattern to match against. - const protocolErrors = Object.values(LighthouseError.errors).filter(e => e.pattern); // if we find one, use the friendly LighthouseError definition - const matchedErrorDefinition = protocolErrors.find(e => e.pattern.test(protocolError.message)); + const matchedErrorDefinition = Object.values(LighthouseError.errors) + .filter(e => e.pattern) + .find(e => e.pattern && e.pattern.test(protocolError.message)); if (matchedErrorDefinition) { return new LighthouseError(matchedErrorDefinition); } diff --git a/lighthouse-core/report/html/renderer/util.js b/lighthouse-core/report/html/renderer/util.js index 632f73e618b6..9a80d3fbf80b 100644 --- a/lighthouse-core/report/html/renderer/util.js +++ b/lighthouse-core/report/html/renderer/util.js @@ -81,6 +81,7 @@ class Util { // into 'debugdata' (LHR ≥5.0). // @ts-expect-error tsc rightly flags that these values shouldn't occur. if (audit.details.type === undefined || audit.details.type === 'diagnostic') { + // @ts-expect-error details is of type never. audit.details.type = 'debugdata'; } diff --git a/lighthouse-core/scripts/generate-bundlephobia-database.js b/lighthouse-core/scripts/generate-bundlephobia-database.js index 5572deb94f79..3275788bbf72 100644 --- a/lighthouse-core/scripts/generate-bundlephobia-database.js +++ b/lighthouse-core/scripts/generate-bundlephobia-database.js @@ -19,8 +19,7 @@ const fs = require('fs'); const path = require('path'); -const getPackageVersionList = require('bundle-phobia-cli').fetchPackageStats.getPackageVersionList; -const fetchPackageStats = require('bundle-phobia-cli').fetchPackageStats.fetchPackageStats; +const {getPackageVersionList, fetchPackageStats} = require('bundle-phobia-cli').fetchPackageStats; const databasePath = path.join(__dirname, '../lib/large-javascript-libraries/bundlephobia-database.json'); diff --git a/lighthouse-core/scripts/lantern/constants.js b/lighthouse-core/scripts/lantern/constants.js index 646c4d2f36aa..6b200b748812 100644 --- a/lighthouse-core/scripts/lantern/constants.js +++ b/lighthouse-core/scripts/lantern/constants.js @@ -33,7 +33,7 @@ const path = require('path'); /** * @typedef EstimateEvaluationSummary - * @property {LanternEvaluation[]} evaluations + * @property {LanternEvaluation[]} [evaluations] * @property {number} p50 * @property {number} p90 * @property {number} p95 @@ -113,7 +113,10 @@ module.exports = { * @return {(LanternEvaluation & LanternSiteDefinition)|null} */ evaluateSite(site, expectedMetrics, actualMetrics, metric, lanternMetric) { - const expected = Math.round(expectedMetrics[metric]); + const expectedRaw = expectedMetrics[metric]; + if (expectedRaw === undefined) return null; + + const expected = Math.round(expectedRaw); if (expected === 0) return null; const actual = Math.round(actualMetrics[lanternMetric]); @@ -135,7 +138,7 @@ module.exports = { * @param {LanternSiteDefinition[]} entries * @param {keyof TargetMetrics} metric * @param {keyof LanternMetrics} lanternMetric - * @param {'lantern'|'baseline'} [lanternOrBaseline] + * @param {'lantern'|'baseline'} lanternOrBaseline * @return {EstimateEvaluationSummary} */ evaluateAccuracy(entries, metric, lanternMetric, lanternOrBaseline = 'lantern') { @@ -143,10 +146,13 @@ module.exports = { const percentErrors = []; for (const entry of entries) { + const actualMetrics = entry[lanternOrBaseline]; + if (!actualMetrics) throw new Error(`No metrics for ${metric} ${lanternMetric} ${lanternOrBaseline}`); + const evaluation = this.evaluateSite( entry, entry.wpt3g, - entry[lanternOrBaseline], + actualMetrics, metric, lanternMetric ); diff --git a/lighthouse-core/scripts/lantern/print-correlations.js b/lighthouse-core/scripts/lantern/print-correlations.js index 727c99ca2fea..4cf2f0b89c30 100755 --- a/lighthouse-core/scripts/lantern/print-correlations.js +++ b/lighthouse-core/scripts/lantern/print-correlations.js @@ -117,8 +117,8 @@ function evaluateAndPrintAccuracy(metric, lanternMetric) { )}`.padEnd(30), ]; - allEvaluations.push(...actualAccuracy.evaluations); - baselineEvaluations.push(...baselineAccuracy.evaluations); + if (actualAccuracy.evaluations) allEvaluations.push(...actualAccuracy.evaluations); + if (baselineAccuracy.evaluations) baselineEvaluations.push(...baselineAccuracy.evaluations); if (lanternMetric.includes('roughEstimate')) { console.log(...strings); diff --git a/package.json b/package.json index 292fad97abb4..e894f7fdbedb 100644 --- a/package.json +++ b/package.json @@ -152,7 +152,7 @@ "pretty-json-stringify": "^0.0.2", "puppeteer": "^1.19.0", "terser": "^4.2.0", - "typescript": "3.9.7", + "typescript": "4.1.2", "webtreemap-cdt": "^3.0.1" }, "dependencies": { diff --git a/types/lhr.d.ts b/types/lhr.d.ts index 0b48492a28ee..e01548a0a83f 100644 --- a/types/lhr.d.ts +++ b/types/lhr.d.ts @@ -53,7 +53,7 @@ declare global { /** Execution timings for the Lighthouse run */ timing: Result.Timing; /** The record of all formatted string locations in the LHR and their corresponding source values. */ - i18n: {rendererFormattedStrings: I18NRendererStrings, icuMessagePaths: IcuMessagePaths}; + i18n: {rendererFormattedStrings: I18NRendererStrings, icuMessagePaths?: IcuMessagePaths}; /** An array containing the result of all stack packs. */ stackPacks?: Result.StackPack[]; } diff --git a/yarn.lock b/yarn.lock index 9cca2d6edd72..c42fadc7df08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8061,10 +8061,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@3.9.7: - version "3.9.7" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" - integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== +typescript@4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9" + integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ== uglify-js@^3.1.4: version "3.4.9"