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

clients(devtools): export report files as resources for devtools #7567

Merged
merged 10 commits into from
Mar 25, 2019

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Mar 18, 2019

Some changes requested from Chromium side.

  1. export as resource files, consumable via Runtime.cachedResources. mostly for theming.
  2. use a namespace for report generator: Lighthouse.ReportGenerator

WIP awaiting https://chromium-review.googlesource.com/c/chromium/src/+/1510732.

@connorjclark connorjclark changed the title clients(devtools): export report files as resources for devtools. use… clients(devtools): export report files as resources for devtools Mar 18, 2019
@connorjclark connorjclark marked this pull request as ready for review March 18, 2019 23:46
fs.writeFileSync(`${distDir}/${name}`, escaped);
}

// For cached resources. Contents must be ascii.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what the ascii comment has to do with the rimraf :)

* @param {string} name
* @param {string} content
*/
function cachedResource(name, content) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like this might be the ascii thing you were talking about? let's give the function a bit more descriptive name then

convertToAsciiAndWriteFile, is that what it's doing?

clients/devtools-report-assets.js Show resolved Hide resolved
build/dt-report-generator-bundle.js Outdated Show resolved Hide resolved

const distDir = __dirname + '/../dist';
const outFile = `${distDir}/report-generator.js`;
const distDir = __dirname + '/../dist/dt-resources';
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I know it was pre-existing but let's path.join this sucker :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

meant to do this in the last one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ya, done

# copy report generator
cp dist/report-generator.js $fe_lh_dir
# copy report generator + cached resources
cp -r dist/dt-resources/ $fe_lh_dir
Copy link
Collaborator

Choose a reason for hiding this comment

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

kinda unrelated but the power of the trailing / always terrifies me in cp commands...

this means we want dt-resources to now be at $fe_lh_dir/dt-resources or we want $fe_lh_dir to be dt-resources?

Copy link
Collaborator Author

@connorjclark connorjclark Mar 19, 2019

Choose a reason for hiding this comment

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

added comment to clarify. -r + trailing / on the source copies the contents of the folder. If the destination doesn't exist or is not a folder, it fails.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah OK, so it's equivalent to dist/dt-resources/* in our case, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, but they'd act differently in some cases like (had to look this up):

  • glob does not capture hidden files
  • there is only one file matching the glob + destination folder does not exist => single file is copied as a file. no destination directory created
  • if there are multiple files matching the glob + destination folder does not exist => errors

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

of course, the above is a consequence of the shell expanding the glob, and the difference between cp -r f1 f2 sd and cp -r f1 sd

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.

LGTM!


/**
* @fileoverview Instead of loading report assets form the filesystem, in Devtools we must load
* them via Runtime.cachedResources. We use this module to shim ./html/html-report-assets
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use lighthouse-core/report/html/html-report-assets.js instead of ./html/html-report-assets since it's not relative to this file :)

# copy report generator
cp dist/report-generator.js $fe_lh_dir
# copy report generator + cached resources
cp -r dist/dt-resources/ $fe_lh_dir
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah OK, so it's equivalent to dist/dt-resources/* in our case, right?


const distDir = __dirname + '/../dist';
const outFile = `${distDir}/report-generator.js`;
const distDir = __dirname + '/../dist/dt-resources';
Copy link
Collaborator

Choose a reason for hiding this comment

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

meant to do this in the last one?

Copy link
Member

@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.

with the changes on the devtools side, can we remove ReportGenerator.getAssets()?

couple of things, but looking good

convertToAsciiAndWriteFile('report.js', htmlReportAssets.REPORT_JAVASCRIPT);
convertToAsciiAndWriteFile('report.css', htmlReportAssets.REPORT_CSS);
convertToAsciiAndWriteFile('template.html', htmlReportAssets.REPORT_TEMPLATE);
convertToAsciiAndWriteFile('templates.html', htmlReportAssets.REPORT_TEMPLATES);
Copy link
Member

Choose a reason for hiding this comment

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

asserting something about htmlReportAssets in here might catch at least some issues whenever yarn build-all is run. Could be something stupid simple like Object.keys is only the ones we expect. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how's that?

Copy link
Member

Choose a reason for hiding this comment

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

how's that?

seems good?


const distDir = __dirname + '/../dist';
const outFile = `${distDir}/report-generator.js`;
const distDir = path.join(__dirname, '..', 'dist', 'dt-resources');
Copy link
Member

Choose a reason for hiding this comment

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

can we rename these so they match the other build scripts (and the build script name goes with the output directory name).

what about
this script -> build-dt-report-resources.js
distDir -> dist/dt-report-resources/

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@connorjclark
Copy link
Collaborator Author

with the changes on the devtools side, can we remove ReportGenerator.getAssets()?

No: https://chromium-review.googlesource.com/c/chromium/src/+/1510732/13/third_party/blink/renderer/devtools/front_end/audits2/Audits2Panel.js#b142

@brendankenny
Copy link
Member

No: https://chromium-review.googlesource.com/c/chromium/src/+/1510732/13/third_party/blink/renderer/devtools/front_end/audits2/Audits2Panel.js#b142

but isn't Runtime.cachedResources['audits2/lighthouse/templates.html'] going to be populated after this PR, so it won't need Lighthouse.ReportGenerator.getAssets().REPORT_TEMPLATES?

@connorjclark
Copy link
Collaborator Author

but isn't Runtime.cachedResources['audits2/lighthouse/templates.html'] going to be populated after this PR, so it won't need Lighthouse.ReportGenerator.getAssets().REPORT_TEMPLATES?

Oh, of course. let's kill it now.

*/
'use strict';

const browserify = require('browserify');
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps gulp would do better here?

Copy link
Member

Choose a reason for hiding this comment

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

nope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just of curiousity, why are you using browserify?

Copy link
Member

Choose a reason for hiding this comment

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

Just of curiosity, why are you using browserify?

we need to run the same files in node and the browser. Even if we ran a different bundler, we'd probably run the same browserify transforms, so, might as well run the real deal until such a time something better comes along :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Thanks for sharing

Copy link
Member

@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.

report.json included by mistake, it looks like

convertToAsciiAndWriteFile('report.js', htmlReportAssets.REPORT_JAVASCRIPT);
convertToAsciiAndWriteFile('report.css', htmlReportAssets.REPORT_CSS);
convertToAsciiAndWriteFile('template.html', htmlReportAssets.REPORT_TEMPLATE);
convertToAsciiAndWriteFile('templates.html', htmlReportAssets.REPORT_TEMPLATES);
Copy link
Member

Choose a reason for hiding this comment

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

doesn't this still result in a Runtime.cachedResources['audits2/lighthouse/templates.html'] (seems like it has to, since that's where devtools-report-assets.js loads it from), so we still don't need Lighthouse.ReportGenerator.getAssets()?

Copy link
Collaborator Author

@connorjclark connorjclark Mar 25, 2019

Choose a reason for hiding this comment

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

yup. already removed getAssets

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops. now i did :)

Copy link
Member

@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.

LGTM!

@brendankenny brendankenny merged commit 9790337 into master Mar 25, 2019
@brendankenny brendankenny deleted the dt-report-generator-2 branch March 25, 2019 19:47
devtools-bot pushed a commit to ChromeDevTools/devtools-frontend that referenced this pull request Apr 9, 2019
Changelog: GoogleChrome/lighthouse@v4.2.0...9790337

Relevant LH build changes:

GoogleChrome/lighthouse#7421
GoogleChrome/lighthouse#7567

Bug: 772558

Change-Id: I50296da5059d6f90fbd69346691529a5feff15ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1510732
Commit-Queue: Connor Clark <cjamcl@google.com>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#649003}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 1df082f1ff78ab6009a972d861537484f967d3d5
aarongable pushed a commit to chromium/chromium that referenced this pull request Apr 9, 2019
Changelog: GoogleChrome/lighthouse@v4.2.0...9790337

Relevant LH build changes:

GoogleChrome/lighthouse#7421
GoogleChrome/lighthouse#7567

Bug: 772558

Change-Id: I50296da5059d6f90fbd69346691529a5feff15ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1510732
Commit-Queue: Connor Clark <cjamcl@google.com>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649003}
babot pushed a commit to binaryage/dirac that referenced this pull request Apr 9, 2019
Changelog: GoogleChrome/lighthouse@v4.2.0...9790337

Relevant LH build changes:

GoogleChrome/lighthouse#7421
GoogleChrome/lighthouse#7567

Bug: 772558

Change-Id: I50296da5059d6f90fbd69346691529a5feff15ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1510732
Commit-Queue: Connor Clark <cjamcl@google.com>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649003}
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.

None yet

5 participants