-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
… namespace for ReportGenerator
build/dt-report-generator-bundle.js
Outdated
fs.writeFileSync(`${distDir}/${name}`, escaped); | ||
} | ||
|
||
// For cached resources. Contents must be ascii. |
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.
I'm not sure what the ascii comment has to do with the rimraf :)
build/dt-report-generator-bundle.js
Outdated
* @param {string} name | ||
* @param {string} content | ||
*/ | ||
function cachedResource(name, content) { |
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.
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?
build/dt-report-generator-bundle.js
Outdated
|
||
const distDir = __dirname + '/../dist'; | ||
const outFile = `${distDir}/report-generator.js`; | ||
const distDir = __dirname + '/../dist/dt-resources'; |
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.
nit: I know it was pre-existing but let's path.join
this sucker :)
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.
meant to do this in the last one?
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.
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 |
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.
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
?
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.
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.
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.
ah OK, so it's equivalent to dist/dt-resources/*
in our case, right?
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.
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
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.
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
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.
LGTM!
clients/devtools-report-assets.js
Outdated
|
||
/** | ||
* @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 |
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.
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 |
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.
ah OK, so it's equivalent to dist/dt-resources/*
in our case, right?
build/dt-report-generator-bundle.js
Outdated
|
||
const distDir = __dirname + '/../dist'; | ||
const outFile = `${distDir}/report-generator.js`; | ||
const distDir = __dirname + '/../dist/dt-resources'; |
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.
meant to do this in the last one?
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.
with the changes on the devtools side, can we remove ReportGenerator.getAssets()
?
couple of things, but looking good
build/dt-report-generator-bundle.js
Outdated
convertToAsciiAndWriteFile('report.js', htmlReportAssets.REPORT_JAVASCRIPT); | ||
convertToAsciiAndWriteFile('report.css', htmlReportAssets.REPORT_CSS); | ||
convertToAsciiAndWriteFile('template.html', htmlReportAssets.REPORT_TEMPLATE); | ||
convertToAsciiAndWriteFile('templates.html', htmlReportAssets.REPORT_TEMPLATES); |
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.
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?
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.
how's that?
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.
how's that?
seems good?
build/dt-report-generator-bundle.js
Outdated
|
||
const distDir = __dirname + '/../dist'; | ||
const outFile = `${distDir}/report-generator.js`; | ||
const distDir = path.join(__dirname, '..', 'dist', 'dt-resources'); |
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.
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/
?
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.
done
|
but isn't |
Oh, of course. let's kill it now. |
*/ | ||
'use strict'; | ||
|
||
const browserify = require('browserify'); |
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.
Perhaps gulp would do better here?
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.
nope.
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.
Just of curiousity, why are you using browserify?
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.
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 :)
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.
Gotcha. Thanks for sharing
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.
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); |
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.
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()
?
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.
yup. already removed getAssets
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.
oops. now i did :)
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.
LGTM!
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
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}
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}
Some changes requested from Chromium side.
Lighthouse.ReportGenerator
WIP awaiting https://chromium-review.googlesource.com/c/chromium/src/+/1510732.