Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update to typescript 4.1.2 #11690

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/gh-pages-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class GhPagesApp {
});
}

/**
* @return {Promise<void>}
*/
deploy() {
return new Promise((resolve, reject) => {
ghPages.publish(this.distDir, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/byte-efficiency/unminified-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
*/
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/charset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class Config {

/**
* @param {string} path
* @param {{}=} options
* @param {{}|undefined} options
* @param {Array<string>} coreAuditList
* @param {string=} configDir
* @return {LH.Config.GathererDefn}
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ class Driver {
throw new Error('_waitForFcp.cancel() called before it was defined');
};

/** @type {Promise<void>} */
const promise = new Promise((resolve, reject) => {
const maxWaitTimeout = setTimeout(() => {
reject(new LHError(LHError.errors.NO_FCP));
Expand Down Expand Up @@ -680,6 +681,7 @@ class Driver {
}
const networkStatusMonitor = this._networkStatusMonitor;

/** @type {Promise<void>} */
const promise = new Promise((resolve, reject) => {
const onIdle = () => {
// eslint-disable-next-line no-use-before-define
Expand Down Expand Up @@ -791,6 +793,7 @@ class Driver {
let cancel = () => {
throw new Error('_waitForCPUIdle.cancel() called before it was defined');
};
/** @type {Promise<void>} */
const promise = new Promise((resolve, reject) => {
checkForQuiet(this, resolve).catch(reject);
cancel = () => {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class Fetcher {
iframe.src = src;
iframe.onload = iframe.onerror = () => {
iframe.remove();
delete iframe.onload;
delete iframe.onerror;
iframe.onload = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

come to think of it, why do we do this at all? can onload or onerror ever refire after it's been fired before and removed from the DOM?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it helps me sleep at night

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I'm wondering if this holds a reference to itself, so GC would never delete the element ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iframe.onerror = null;
};
document.body.appendChild(iframe);
}
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/gather/gatherers/image-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

loading: element.loading,
resourceSize: 0, // this will get overwritten below
usesObjectFit: ['cover', 'contain', 'scale-down', 'none'].includes(
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-core/lib/dependency-graph/simulator/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ class Simulator {

/**
* @param {Node} node
* @return {NodeTimingIntermediate}
* @return {Required<NodeTimingIntermediate>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this can be improved, filed #11692 for myself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @patrickhulce!

*/
_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;
}

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-core/lib/lh-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,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);
}
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/lib/proto-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function processForProto(lhr) {

// Drop the i18n icuMessagePaths. Painful in proto, and low priority to expose currently.
if (reportJson.i18n && reportJson.i18n.icuMessagePaths) {
// @ts-expect-error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this? should we set it to undefined or do we need to update the type to allow it to be undefined to reflect reality?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

And now I realize the #10148 wouldn't work for PSI LHRs until we fix this :(

delete reportJson.i18n.icuMessagePaths;
}

Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/report/html/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes less sense to me than the one immediately above it, what's the reason?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes less sense to me than the one immediately above it, what's the reason?

it's because the conditional above only lets in audit.details that shouldn't be possible, so it's of type never and can't be assigned to. Definitely worth a @ts-expect-error comment for that, though.

audit.details.type = 'debugdata';
}

Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/scripts/generate-bundlephobia-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
14 changes: 10 additions & 4 deletions lighthouse-core/scripts/lantern/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand All @@ -135,18 +138,21 @@ 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') {
const evaluations = [];

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
);
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/scripts/lantern/print-correlations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8074,10 +8074,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"
Expand Down