Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Mar 19, 2025

The type interface between audits/gatherers and computed artifacts is unsound: both audits and gatherers use the full LH.Artifacts type, even though both are actually limited by the runner. At some point I wanted to fix this, but for some unwritten reason the change was not merged.

Recently in #16396 I struggled to add SourceMaps to a computed artifact used by many audits over multiple layers of our modules. Errors looked like "can't call find on undefined", and was many files removed from the audit file that was missing a declaration for "SourceMaps". What helped me make the change was tweaking how computed artifacts work:

  1. In makeComputedArtifact, disallow any undefined value given as properties of the dependencies object
  2. Change existing undefined / optional properties to instead be nullable

This allows the error to be generated right next to the improper usage. It also forces all callers, including tests, to consider every portion of the dependencies object - this is a little cumbersome but I think is clearly a benefit in that it makes for more accurate tests.

I decided to only throw an error in makeComputedArtifact if isUnderTest is true - in production this will simply log an error message. This is to allow any thing this PR may have missed, but was still otherwise OK, from producing false errors.

@connorjclark connorjclark requested a review from a team as a code owner March 19, 2025 21:31
@connorjclark connorjclark requested review from adamraine and removed request for a team March 19, 2025 21:31
@connorjclark connorjclark merged commit 589f798 into main Mar 20, 2025
28 checks passed
@connorjclark connorjclark deleted the computed-arts-no-undefined branch March 20, 2025 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants