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

report: extract independent report-generator types #12940

Merged
merged 2 commits into from
Aug 19, 2021

Conversation

brendankenny
Copy link
Member

This is the last step before isolated report types, for real this time :)

report-generator and assets are kind of the odd duck in the report/ directory. They're still commonjs and they're intended to be runnable in Node and bundleable and runnable in the browser (for e.g. the viewer). This PR moves them to their own directory and gives them their own tsconfig so they can be used as a project reference, allowing tsc to treat report-generator as a standalone dep whether being called from core code or report code.

This puts them under report/generator/, but there are other options:

  • top-level directory (e.g. report-generator/ or whatever). This makes a certain amount of sense to separate from pure browser code like the rest of report/, but the name clashing with report is unfortunate
  • lighthouse-core/report-generator/. It makes a certain amount of sense inside lighthouse-core because we sometimes include it directly in core bundles but when we ship it with report code like viewer, it's a separate report-generator bundle.
  • top-level general "shared" directory. I don't have a good name for this, but we have other code like this, e.g. util, and likely will have more in the future. Downside is less specificity and it could just become a clearinghouse of unrelated code

Functionality-wise the directory structure doesn't really seem to matter at this stage, but I wanted to throw out the options in case the current choice seems wrong to anyone.

Also:

  • moves file-namer.js to live with report generator code, because it's only used for generated reports (in node and the browser)
  • makes report/ default "type": "module" and makes report/generator/ and report/test/generator/ the exceptions as "type": "commonjs"

@brendankenny brendankenny requested a review from a team as a code owner August 19, 2021 16:36
@brendankenny brendankenny requested review from connorjclark and removed request for a team August 19, 2021 16:36
@google-cla google-cla bot added the cla: yes label Aug 19, 2021
Copy link
Member Author

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

@adamraine this is going to clash with #12929, but it's just directory renames, nothing major. If that's going to land soon I'm happy to fix over here.

But also feel free to weigh in on directory naming/structure since you're adding files to these locations right now :)

const FLOW_REPORT_TEMPLATE = fs.readFileSync(`${LH_ROOT}/flow-report/assets/standalone-flow-template.html`, 'utf8');
const FLOW_REPORT_JAVASCRIPT = fs.readFileSync(`${LH_ROOT}/dist/report/flow.js`, 'utf8');
const FLOW_REPORT_TEMPLATE = fs.readFileSync(`${__dirname}/../../flow-report/assets/standalone-flow-template.html`, 'utf8');
const FLOW_REPORT_JAVASCRIPT = fs.readFileSync(`${__dirname}/../../dist/report/flow.js`, 'utf8');
Copy link
Member Author

@brendankenny brendankenny Aug 19, 2021

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 root tsconfig.json (really root.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 a root.js copy for generator code, or we could (eventually?) do the "shared" directory idea from above and put root.js in there. This seemed ok for now since report-assets.js still uses __dirname too.

@@ -7,6 +7,9 @@

const htmlReportAssets = require('./report-assets.js');

/** @typedef {import('../../types/lhr/lhr').default} LHResult */
/** @typedef {import('../../types/lhr/flow').default} FlowResult */
Copy link
Member Author

Choose a reason for hiding this comment

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

we could make a globals d.ts file for the report generator too, but it didn't seem worth it for just these two types. I don't feel strongly either way, though

@adamraine
Copy link
Member

If that's going to land soon I'm happy to fix over here.

I don't expect it to land soon, but thanks for the heads up.


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 a browserify transform that takes any `fs.readFileSync()` calls and replaces them with the stringified file content.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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 a browserify transform that takes any `fs.readFileSync()` calls and replaces them with the stringified file content.
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.

future proof this :)

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

4 participants