-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(runner): make LH.Audit.Context immutable #10555
Conversation
@@ -51,7 +51,7 @@ class ResourceSummary { | |||
'third-party': {count: 0, size: 0}, | |||
}; | |||
const budget = Budget.getMatchingBudget(context.settings.budgets, mainResourceURL); | |||
let firstPartyHosts = /** @type {Array<string>} */ ([]); | |||
let firstPartyHosts = /** @type {Immutable<Array<string>>} */ ([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be able to be just ReadonlyArray<string>
after we upgrade to tsc 3.7+
@@ -670,31 +670,6 @@ describe('Runner', () => { | |||
}); | |||
}); | |||
|
|||
it('includes any LighthouseRunWarnings from errored audits in LHR', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the sole loss of functionality (being able to push top-level warnings before the audit completely errors out), but I don't think this has ever been behavior anyone cares about or needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call out the loss of this as a breaking change in PR description so we remember to include that too in final notes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call out the loss of this as a breaking change in PR description so we remember to include that too in final notes?
done
@@ -509,7 +509,7 @@ declare global { | |||
export interface MetricComputationDataInput { | |||
devtoolsLog: DevtoolsLog; | |||
trace: Trace; | |||
settings: Config.Settings; | |||
settings: Immutable<Config.Settings>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is complicated because this settings
is just as often not LH.Config.Settings
as it is, but that's something to sort out on a different day :)
types/externs.d.ts
Outdated
// Intermediate immutable interfaces. Prefer e.g. Immutable<Set<T>> over direct use. | ||
// TODO: switch to recursive type references when using tsc ≥ 3.7 | ||
// see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-557509399 | ||
interface ImmutableArray<T> extends ReadonlyArray<Immutable<T>> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we upgrade tsc, this can become
type ImmutableArray<T> = ReadonlyArray<Immutable<T>>;
, which means things like the built-in ReadonlyArray<string>
will be transparently switchable with Immutable<Array<string>>
, giving a lot better ergonomics and functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I trust audits any more than I did before, but OK :)
LGTM
@@ -25,6 +25,8 @@ function makeComputedArtifact(computableArtifact) { | |||
* @return {ReturnType<C['compute_']>} | |||
*/ | |||
const request = (artifacts, context) => { | |||
/** @type {Map<string, ArbitraryEqualityMap>} */ | |||
// @ts-ignore - break immutability solely for this caching-controller function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a Mutable<T>
type we could put Context['computedCache']
through? It'd be nice to not lose that type safety just for the mutability part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a
Mutable<T>
type we could putContext['computedCache']
through? It'd be nice to not lose that type safety just for the mutability part
Map
is a little special (as are Array
and Set
) because typescript has a special readonly type for it that removes all the mutating functions from instances, so Map
s are ReadonlyMap
s, but ReadonlyMap
s aren't Map
s.
Mutable<T>
could do an unsafe cast for that, but we could just as easily do that here too. There's little enough going on in this line of code that ignoring seemed fine, but maybe the cast would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big deal but even the unsafe cast of ReadonlyMap to Map would be a huge upgrade IMO so we can catch the compatibility of T :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we can catch the compatibility of T
very good point, sold :)
I'll wait for #10461 to be landable so I can use tsc 3.7 stuff
@@ -670,31 +670,6 @@ describe('Runner', () => { | |||
}); | |||
}); | |||
|
|||
it('includes any LighthouseRunWarnings from errored audits in LHR', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call out the loss of this as a breaking change in PR description so we remember to include that too in final notes?
Maybe it would have been more correct to say it gives them better guidance on how to act :) |
21e13b4
to
92b3602
Compare
@connorjclark what should I do about this travis failure?
|
my local changes from I'll gate on your approval, though @connorjclark |
0135117
to
9d096f5
Compare
breaking change (see below for details)
fixes #9897
tl;dr: making this change now allows us to
postMessage
able, handy for an off-main-thread/extension plugin model if we choose to go in that directionThe change is very small since we only have two lines of code currently modifying an audit context outside of
runner.js
:)The only real breaking change is that rather than audits pushing to the context to get a top-level LHR warning, they return the warning in their audit
Product
. It's very possible that existing extensions use this functionality. In core, there's only one audit doing so.Note that
readonly
is still type-checking/advisory level enforcement, so if an audit wants to mess with things it currently can, but that's always been the case and it's useful to leave things open without a reason to do otherwise.breaking changes:
context.LighthouseRunWarnings
to get a top-level warning in the LHR will instead need to return arunWarnings
property on theProduct
return value, set to an array with that string in it. (example change from core)context.LighthouseRunWarnings
even if they ended up throwing an error, but that is no longer possible since the run warnings are now part of the normal return value.