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

core: extract independent LHR types #12914

Merged
merged 2 commits into from
Aug 13, 2021
Merged

core: extract independent LHR types #12914

merged 2 commits into from
Aug 13, 2021

Conversation

brendankenny
Copy link
Member

  • Extracts the types necessary to define the LHR into files with no dependencies to the rest of lighthouse core
    • the means no more pulling in just the result type and getting almost the entire world transitively through artifacts.d.ts and gatherer.d.ts, etc
  • enforces this by making types/lhr/*.d.ts a project reference to the rest of the code. The rest of lighthouse can still reference those files normally, but it's kind of an opaque barrier, similar to referencing a library in a node module. Code inside of types/lhr/, however, mostly can't reference code outside (mostly, but close enough for us), which means it should be easy to keep the LHR types standalone
  • Going forward, if something in a Lighthouse run is going to be in the LHR it generally needs to be defined there and then referenced in the other place, e.g. how Settings have moved to types/lhr/settings.d.ts and then referenced from config.d.ts.
    • I think this is a good thing because the LHR is what we expect the world and our report renderer to interoperate with, but happy to discuss other takes.

There's a few moving pieces here, so I can try to split up if that's easier to review. This PR at least shows the point of the moves.

Next: the report/viewer/treemap can build on just the LHR and not the entirety of lighthouse-core/, making the report considerably simpler to deal with on its own.

@brendankenny brendankenny requested a review from a team as a code owner August 13, 2021 19:41
@brendankenny brendankenny requested review from patrickhulce and removed request for a team August 13, 2021 19:41
@google-cla google-cla bot added the cla: yes label Aug 13, 2021
if (!filename.endsWith('util.js')) throw new Error(`Unexpected message: ${icuMessageId}`);

const key = /** @type {keyof LH.I18NRendererStrings} */ (varName);
Copy link
Member Author

Choose a reason for hiding this comment

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

this code doesn't actually verify that's what these strings are (it's just looking for any i18n strings starting with 'report/'), and there's really no reason for lighthouse-core/ to keep track of that anyways. It is verified in a report test, so we just move the type cast over there (reuse an existing one, actually) so that the report Util.i18n.strings.* usages are still type checked

@@ -67,7 +67,7 @@
"dogfood-lhci": "./lighthouse-core/scripts/dogfood-lhci.sh",
"timing-trace": "node lighthouse-core/scripts/generate-timing-trace.js",
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file",
"type-check": "tsc -p . && tsc -p lighthouse-viewer/ && tsc -p lighthouse-treemap/",
"type-check": "tsc -b . && tsc -p lighthouse-viewer/ && tsc -p lighthouse-treemap/",
Copy link
Member Author

Choose a reason for hiding this comment

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

using -b/--build

"diagnostics": true
"diagnostics": true,
"composite": true,
"outDir": ".tmp/tsbuildinfo/",
Copy link
Member Author

Choose a reason for hiding this comment

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

build mode outputs tsconfig.tsbuildinfo files so that project references can be faster and re-use already built projects (if files aren't newer than the tsbuildinfo file). We're still not emitting, but it uses this path for the tsbuildinfo files so they're not in the way. It's ok if .tmp is deleted at any time, it'll just recreate them on the next build

},
"include": [
"root.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

all the files added here were already in the compile through transitive import/require references, composite projects are just required to have all included files to actually be declared in include or files

@@ -31,23 +35,6 @@ declare module Audit {
median: number;
}

interface ScoreDisplayModes {
Copy link
Member Author

Choose a reason for hiding this comment

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

these were moved to a new audit-result.d.ts file

@@ -148,97 +146,6 @@ declare global {
}
}

/** Simulation settings that control the amount of network & cpu throttling in the run. */
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to new settings.d.ts file

/** The unit of `numericValue`, used when the consumer wishes to convert numericValue to a display string. */
numericUnit?: string;
/** Extra information about the page provided by some types of audits, in one of several possible forms that can be rendered in the HTML report. */
details?: FormattedIcu<AuditDetails>;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is definitely a wart, removing the IcuMessage from the AuditDetails types. The LHR shouldn't know anything about IcuMessage, because there aren't any by the time it's an LHR.

I haven't found a way to cleanly define AuditDetails without the IcuMessages as part of the LHR and then add them for internal usage (kind of like AuditProduct vs AuditResult) without needing a ton of subsequent changes, though.

Something to definitely fix before thinking about publishing any types, at least :)

tsconfig.json Outdated Show resolved Hide resolved
Co-authored-by: Connor Clark <[email protected]>
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants