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

misc(build): refactor viewer bundler into reusable GhPagesApp #11564

Merged
merged 8 commits into from
Nov 5, 2020

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Oct 14, 2020

ref https://github.com/GoogleChrome/lighthouse/pull/11545/files#r503644206

  • Provides interface for bundling an app for gh pages
  • Uses simpler synchronous methods (instead of promisfying everything)
  • removed service worker from viewer (doesn't do anything, no plan to add functionality, and I think it messed with my local dev every now and then...)

Next immediate use will be treemap app. If we ever port the scorecalc to this repo, it'd use this code too.

image

@connorjclark connorjclark changed the title build: GhPagesApp for building apps like viewer misc(build): GhPagesApp for building apps like viewer Oct 14, 2020
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 will be great for sourcemap app thanks :)

LGTM % few Qs

<script>
window.addEventListener('DOMContentLoaded', main);

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
Copy link
Collaborator

Choose a reason for hiding this comment

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

we had a serviceworker? 😆

lighthouse-viewer/app/index.html Show resolved Hide resolved
package.json Show resolved Hide resolved
@patrickhulce patrickhulce changed the title misc(build): GhPagesApp for building apps like viewer misc(build): refactor viewer bundler into reusable GhPagesApp Oct 14, 2020
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

package.json Show resolved Hide resolved
@patrickhulce
Copy link
Collaborator

Vercel doesn't seem to like this though, and I can't pull up the details. Did something break there with our viewer deployment?

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.

Can you add some documentation here? It's a definite loss readability-wise otherwise. The current file is simple and more or less self contained. This new version drops any internal comments because the viewer-specific gotchas don't apply, but as a result it's less clear what's going on to build viewer and if you're writing a new "GhPagesApp", there are a bunch of implicit things going on. e.g. where do you put the main html file? (implicit vs the explicit css and js). Why are some js files included by default (and browserified) and not others? etc

@brendankenny
Copy link
Member

(to answer the earlier DRY question, I'm a big fan of the rule of three, personally (master is currently at one gh-pages build file), and if Patrick wants to move to rollup he should just say so :P, but this is fine with some documentation so I don't have to read two build files and open devtools just to figure out what files are going to be included in the bundle :)

@patrickhulce
Copy link
Collaborator

If we ever port the scorecalc to this repo, it'd use this code too.

and CPU throttling calc :)

if Patrick wants to move to rollup he should just say so

Yes, for the record again, I think it would be better if we used any modern bundler that's maintained (rollup, webpack, parcel) instead of rolling our own in multiple places. Asking @connorjclark to pickup that effort for just treemap though seemed unreasonable. In my judgement I don't view this to be a loss to readability (it actually seemed to be an improvement IMO even if we have no additional copies at all. Viewer now calls something resembling a bundler API without needing to understand the implementation of a bundler just to make sense of the script). I'm sorry if everyone else on the team views this as wasted effort, but I do appreciate it greatly and think it's a win :)

@brendankenny
Copy link
Member

Viewer now calls something resembling a bundler API without needing to understand the implementation of a bundler just to make sense of the script

But that's the point I was making, you do still have to understand the implementation, just now it's in two different places and there are fewer comments :) Some scripts are manually added, some are pulled automatically, some are browserified, some are concatted, html just appears, etc.

@connorjclark
Copy link
Collaborator Author

connorjclark commented Oct 14, 2020

Instead of automatically/magically adding sources (like adding app/src/*.js to the js), could instead do more explicit:

const app = new GhPagesApp({
    name: 'viewer',
    appDir: `${__dirname}/../lighthouse-viewer/app`,
    htmlReplacements: {
      '%%LIGHTHOUSE_TEMPLATES%%': htmlReportAssets.REPORT_TEMPLATES,
    },
    html: 'index.html', // ----------- NEW CODE ----------------
    javascripts: [
      await generatorJsPromise,
      htmlReportAssets.REPORT_JAVASCRIPT,
      fs.readFileSync(require.resolve('idb-keyval/dist/idb-keyval-min.js'), 'utf8'),
      {path: 'src/*'}, // ----------- NEW CODE ----------------
    ],
    stylesheets: [
      htmlReportAssets.REPORT_CSS,
      {path: 'styles/*'}, // ----------- NEW CODE ----------------
    ],
    assetPaths: [
      'images/**/*',
      'manifest.json',
    ],
  });

paths would use appDir as root. and be glob-able. Better?

@brendankenny
Copy link
Member

nice, yeah, that does seem like a good change

@connorjclark
Copy link
Collaborator Author

cool, that works out a lot better.

* @property {string} htmlPath
* @property {Array<{path: string} | string>} stylesheets
* @property {Array<{path: string} | string>} javascripts
* @property {string[]} assetPaths
Copy link
Member

Choose a reason for hiding this comment

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

it makes more sense to me to make all four of these Array<{path: string} | string> if some of them are going to go this way, but it's not a huge deal

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can't do it for assetPaths without having some way to interpret a literal string as an asset. {path: string}[] might work?

Concating an array of html files doesn't make sense, but perhaps {path: string} | string could be allowed?

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, cause assets are just copied over, nothing new is created.

Yeah, maybe having them be be {path: string} helps self document by making them consistent with the others, but it also makes sense how you have it here.

* @property {string} name
* @property {string} appDir
* @property {string} htmlPath
* @property {Array<{path: string} | string>} stylesheets
Copy link
Member

Choose a reason for hiding this comment

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

jsdocs for these (especially the ones with the options like this) please? :)

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