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: make main tsc compile cacheable #13069

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ lighthouse.getAuditList = Runner.getAuditList;
lighthouse.traceCategories = require('./gather/driver.js').traceCategories;
lighthouse.Audit = require('./audits/audit.js');
lighthouse.Gatherer = require('./gather/gatherers/gatherer.js');

// Explicit type reference (hidden by makeComputedArtifact) for d.ts export.
// TODO(esmodules): should be a workaround for module.export and can be removed when in esm.
/** @type {typeof import('./computed/network-records.js')} */
Comment on lines +74 to +76
Copy link
Member Author

Choose a reason for hiding this comment

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

kind of a dumb workaround :) The need for it is kind of covered by microsoft/TypeScript#37832 (comment) and microsoft/TypeScript#41672, but it's obviously not fixed and it's not a typedef causing the issue.

tl;dr: typescript creates an (ESM-ish) export object for the d.ts file, but needs a type for NetworkRecords. It then gets confused by the type because NetworkRecords is a computed artifact, which subsumes the original NetworkRecords type, but the original NetworkRecords is still needed because the computed artifact return type is NetworkRecords & {request(artifacts: DevTools, cache: LH.Artifacts.ComputedContext): Promise<whatever>}, hence the "requires using private name 'NetworkRecords'" complaint.

"Kind of dumb" because the annotation is exactly the expected type for the require(), but just need to explicitly type it to unconfuse the compiler and it should go aways with the conversion to es modules anyways, so 🤷

lighthouse.NetworkRecords = require('./computed/network-records.js');

module.exports = lighthouse;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"noEmit": true,
"emitDeclarationOnly": true,
"module": "commonjs",
"target": "ES2020",
"allowJs": true,
Expand Down