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

Adopt handlebars precompiled templates #1752

Merged
merged 14 commits into from Mar 4, 2017

Conversation

sendilkumarn
Copy link
Contributor

#1448

@paulirish this will need us to run watch even when we are testing locally on cli, in order to compile the templated. Otherwise we have to split the generateReport into 2 different methods one handles with html files and other with precompiled template file.

Note: This is my first attempt with precompile ;)

@paulirish
Copy link
Member

paulirish commented Feb 22, 2017

Hmm! So it looks like after this PR, a few of the compiled files actually get larger.

  • viewer/main.js goes from 320kb to 344kb
  • lighthouse-background.js goes from 2.5mb to 2.6mb

(i checked gzip sizes and they get a tiny bit bigger as well: 520k to 525k and 92.5k to 96.4k)

so it's not a win in filesize, at least. It might still be worth it for either runtime or complexity but i'm not sure about that yet.

regardless, i really appreciate you giving this one a shot, @sendilkumarn! super interesting.

@sendilkumarn
Copy link
Contributor Author

sendilkumarn commented Feb 22, 2017

@paulirish
Sorry.
Apparently, I did not include partials. So after including partials and then removing html references. This is what I ended up with. ( completely dereferencing handlebar to handlebar/runtime )

  • viewer/main.js goes from 320kb to 283kb
  • lighthouse-background.js goes from 2,541,212 kb to 2,452,002kb

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

Nice work. Yeah the runtime require is key. :)

Happy this is in good shape.

WDYT, @ebidel? Shall we move ahead with this?

@@ -178,6 +207,14 @@ gulp.task('watch', ['lint', 'browserify', 'html'], () => {
'app/src/**/*.js',
'../lighthouse-core/**/*.js'
], ['browserify']);

gulp.watch([
'../lighthouse-core/**/*.html'
Copy link
Member

Choose a reason for hiding this comment

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

this and the partials wildcard should overlap, right? does the order of these compile tasks matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. If we want to change anything, straightway in that precompiled file, this will help.

Order, yeah we have to run compile first and then browserify.

Copy link
Contributor

Choose a reason for hiding this comment

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

So they can't be combined? Also can we utilize config.report and config.partials for the globs?

@@ -0,0 +1,283 @@
this["report"] = this["report"] || {};
Copy link
Member

Choose a reason for hiding this comment

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

wondering if we should put this in gitignore instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is debatable. If we add in gitignore, we need to make sure that it will be generated on the fly for people who just clones the repo and runs node-cli command.

@ebidel
Copy link
Contributor

ebidel commented Feb 23, 2017

I like anything that makes our build smaller :)

But I'm not sure we should have the compile steps as part of the extension/viewer. For one, it's duplicated code. It would be nice to have shared tasks in a gulp_scripts dir in the top level repo. The other issue is that it might be time for a main gulpfile.js in lighthouse/? The compilation should really live above the viewer/extension.

@sendilkumarn
Copy link
Contributor Author

Yeah that would be awesome. It will also solves the above comment
wondering if we should put this in gitignore instead.

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.

This is awesome stuff thanks @sendilkumarn!

Really unfortunate we're maintaining so many separate gulpfiles though :/ Also not a huge fan of introducing another forgettable build step when developing the CLI locally, especially a non-obvious one that requires you to run the watch of the extension to put files back into core. If we move forward with it, I agree with @ebidel on moving it up to a top-level gulpfile.

@@ -164,7 +150,11 @@ class ReportGenerator {
Handlebars.registerHelper(helpers);
}

Handlebars.registerPartial(audit.name, formatter.getFormatter('html'));
const partials =reportPartials.report.partials;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: space after =

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wondering why eslint did not complain ...

@@ -133,7 +119,7 @@ class ReportGenerator {
* @return {string} HTML of the exception page.
*/
renderException(err, results) {
const template = Handlebars.compile(this.getExceptionTemplate());
const template = reportTemplate.report.template['exception'];
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: .exception

const partials =reportPartials.report.partials;
Handlebars.registerPartial(audit.name,
Handlebars.template(
partials[audit.name] ? partials[audit.name] : partials['empty-formatter']
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: partials[audit.name] || partials['empty-formatter']

@sendilkumarn
Copy link
Contributor Author

Thanks @patrickhulce 👍

@sendilkumarn
Copy link
Contributor Author

sendilkumarn commented Feb 27, 2017

Added a gulp folder to write the common tasks and refer common tasks from there.

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Nice drying up the gulpfiles :)

Up until now, we haven't checked in built files. Personally, I don't think we should start going down that road to be consistent with other places in the codebase.

@@ -0,0 +1,19 @@
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you drop our license header in these new files?

@@ -43,6 +42,7 @@ const walkTree = new Promise((resolve, reject) => {
});

describe('Formatters', () => {
/* TODO : Remove these tests and add appropriate tests based on handlebar pre-compiled templates
it('has no formatters failing when getFormatter("html") is called', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use .skip instead:

it.skip('processes an empty trace for screenshot data', () => {

@@ -178,6 +207,14 @@ gulp.task('watch', ['lint', 'browserify', 'html'], () => {
'app/src/**/*.js',
'../lighthouse-core/**/*.js'
], ['browserify']);

gulp.watch([
'../lighthouse-core/**/*.html'
Copy link
Contributor

Choose a reason for hiding this comment

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

So they can't be combined? Also can we utilize config.report and config.partials for the globs?

], ['browserify']);
});
gulp.watch([
'../lighthouse-core/**/*.html'
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment here.

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Do you know why the null-formatter.html is being included in files changed?

Do we also need to update https://github.com/GoogleChrome/lighthouse/blob/master/.travis.yml to run gulp? I would change https://github.com/GoogleChrome/lighthouse/blob/master/.travis.yml#L22-L24 to npm run build-all and add your gulp to the build-all script: https://github.com/GoogleChrome/lighthouse/blob/master/package.json#L18

* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about combining these two files into one and exporting both functions? They're very similar.

changes to templates
@sendilkumarn
Copy link
Contributor Author

sendilkumarn commented Mar 2, 2017

@ebidel null-formatter is used for partials with no partial-template right ? am I wrong ?

@sendilkumarn
Copy link
Contributor Author

👍 for travis I think that will be enough.

@ebidel
Copy link
Contributor

ebidel commented Mar 2, 2017

Right. But it has 0 LOC changed:

screen shot 2017-03-01 at 6 43 04 pm

Never seen that before. Not sure why that file is being touched.

@sendilkumarn
Copy link
Contributor Author

Well it is just an empty file.

I created it. Before that null-formatter js will just return an empty string. Since we cannot use that for pre-compiling templates. Added that file

@ebidel
Copy link
Contributor

ebidel commented Mar 2, 2017

Looks good @sendilkumarn! Did you see my comments on .travis.yml and package.json updates? #1752 (review)

@sendilkumarn
Copy link
Contributor Author

Yeah absolutely fine with that.
Check here

I will add and push.

@sendilkumarn sendilkumarn reopened this Mar 2, 2017
package.json Outdated
@@ -15,7 +15,7 @@
"install-cli": "cd ./lighthouse-cli && npm install",
"install-extension": "cd ./lighthouse-extension && npm install",
"install-viewer": "cd ./lighthouse-viewer && npm install",
"build-all": "npm run build-cli && npm run build-extension && npm run build-viewer",
"build-all": "npm run build-cli && npm run build-extension && npm run build-viewer && gulp",
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't gulp be first so the templates are compiled by the time other places need them?

changed the order of build

running gulp at first
@sendilkumarn
Copy link
Contributor Author

@ebidel yeah exactly. Thanks 👍

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

LGTM from me. I'll keep open if anyone else has further comments.

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.

thanks for all this work!

package.json Outdated
@@ -24,7 +24,7 @@
"coverage": "node $(npm bin)/istanbul cover -x \"**/third_party/**\" _mocha -- $(find */test -name '*-test.js') --timeout 10000 --reporter progress",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
"start": "node ./lighthouse-cli/index.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to add gulp to start too since it won't be able to run without it now?

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 leaning towards not incurring that cost every start, but a note in the README or something would be nice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we need to have pre-compiled templates for global installs ? currently we are ignoring those.
I added gulp as an extra step in develop section. [Edited]

@paulirish
Copy link
Member

Huge. Thanks @sendilkumarn for taking this on. This was a yeoman's work and we're really jazzed about it.

@paulirish paulirish merged commit 3649322 into GoogleChrome:master Mar 4, 2017
@sendilkumarn
Copy link
Contributor Author

Thank you 👍

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

4 participants