-
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
report: extract independent report-generator types #12940
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Lighthouse Report Generator | ||
|
||
## Overview | ||
|
||
Lighthouse's report generator is the entry point for creating reports from an **LHR** (Lighthouse Result object). It returns results as HTML, JSON, and CSV. | ||
|
||
It runs natively in Node.js but can run in the browser after a compile step is applied during our bundling pipeline. That compile step uses `brfs`, which takes any `fs.readFileSync()` calls and replaces them with the stringified file content. | ||
|
||
Because it's shared between core and the report, dependencies (both code and types) should be kept minimal. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "commonjs", | ||
"//": "Preserve commonjs in this directory. Temporary file until converted to type: module" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
|
||
const htmlReportAssets = require('./report-assets.js'); | ||
|
||
/** @typedef {import('../../types/lhr/lhr').default} LHResult */ | ||
/** @typedef {import('../../types/lhr/flow').default} FlowResult */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could make a globals |
||
|
||
class ReportGenerator { | ||
/** | ||
* Replaces all the specified strings in source without serial replacements. | ||
|
@@ -40,7 +43,7 @@ class ReportGenerator { | |
|
||
/** | ||
* Returns the standalone report HTML as a string with the report JSON and renderer JS inlined. | ||
* @param {LH.Result} lhr | ||
* @param {LHResult} lhr | ||
* @return {string} | ||
*/ | ||
static generateReportHtml(lhr) { | ||
|
@@ -58,7 +61,7 @@ class ReportGenerator { | |
|
||
/** | ||
* Returns the standalone flow report HTML as a string with the report JSON and renderer JS inlined. | ||
* @param {LH.FlowResult} flow | ||
* @param {FlowResult} flow | ||
* @return {string} | ||
*/ | ||
static generateFlowReportHtml(flow) { | ||
|
@@ -81,7 +84,7 @@ class ReportGenerator { | |
* - the score type that is used for the audit | ||
* - the score value of the audit | ||
* | ||
* @param {LH.Result} lhr | ||
* @param {LHResult} lhr | ||
* @return {string} | ||
*/ | ||
static generateReportCSV(lhr) { | ||
|
@@ -118,8 +121,8 @@ class ReportGenerator { | |
|
||
/** | ||
* Creates the results output in a format based on the `mode`. | ||
* @param {LH.Result} lhr | ||
* @param {LH.Config.Settings['output']} outputModes | ||
* @param {LHResult} lhr | ||
* @param {LHResult['configSettings']['output']} outputModes | ||
* @return {string|string[]} | ||
*/ | ||
static generateReport(lhr, outputModes) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "../../.tmp/tsbuildinfo/report/generator", | ||
"emitDeclarationOnly": true, | ||
"declarationMap": true, | ||
|
||
"target": "ES2020", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
|
||
"allowJs": true, | ||
"checkJs": true, | ||
"strict": true, | ||
// TODO: remove the next line to be fully `strict`. | ||
"useUnknownInCatchVariables": false, | ||
|
||
// "listFiles": true, | ||
// "noErrorTruncation": true, | ||
"extendedDiagnostics": true, | ||
}, | ||
"references": [ | ||
{"path": "../../types/lhr/"}, | ||
], | ||
"include": [ | ||
"**/*.js", | ||
], | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "commonjs", | ||
"//": "Preserve commonjs in this directory. Temporary file until converted to type: module" | ||
} |
This file was deleted.
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.
@connorjclark sorry, these had to move off using
root.js
because that would expose generator code to all the dependencies of the roottsconfig.json
(reallyroot.js
is a leaf file as well for the main tsconfig, but tsc isn't smart enough to allow a simple case like that).The report assets won't ever have that many paths to look up, so we could use
import.meta.url
just for these files, we could make aroot.js
copy for generator code, or we could (eventually?) do the "shared" directory idea from above and putroot.js
in there. This seemed ok for now sincereport-assets.js
still uses__dirname
too.