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

extension: simplify bundle building #6282

Merged
merged 2 commits into from
Oct 16, 2018
Merged

extension: simplify bundle building #6282

merged 2 commits into from
Oct 16, 2018

Conversation

brendankenny
Copy link
Member

(we should probably expand the pr lint to include the other bundles besides extension :)

This is a simplification of the building of the bundles (mostly dt/extension).

Primary change is that extension-entry.js no longer relies on importing devtools-entry.js, so all the entry points are independent of each other (they all just rely on core). There were two functions extension-entry.js was still depending on:

  • getDefaultCategories() (which returns the categories in the default config)
  • getDefaultConfigForCategories() (which returns a config that extends the default config but sets onlyCategories to the passed in categories)

Turns out getDefaultCategories() wasn't used in devtools-entry.js anyways, so just moved it into extension-entry.js. getDefaultConfigForCategories(), meanwhile, is so short and straightforward this just duplicates the function in both files.

Things become a lot simpler to understand without the layering/pseudo-inheritance. Things are either set for the consumer of the file (e.g. on self for devtools) or exposed at the module level for unit testing.

The other set of changes are a few simple fixes in the extension gulpfile, deleting stuff that wasn't actually doing anything.

/** @param {(status: [string, string, string]) => void} listenCallback */
function listenForStatus(listenCallback) {
log.events.addListener('status', listenCallback);
}

if (typeof module !== 'undefined' && module.exports) {
// export for extension-entry to require (via browserify).
// export for require()ing (via browserify).
module.exports = {
Copy link
Member Author

@brendankenny brendankenny Oct 15, 2018

Choose a reason for hiding this comment

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

since there's no unit tests for this bundle, it's not clear we actually want this module.exports block anymore. Do we? (e.g. more annoying to figure out later but minimal overhead to keep today)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I'm not sure we need it either, but +1 to being paranoid for now :)

@@ -180,23 +207,23 @@ if (typeof window !== 'undefined' && 'chrome' in window && chrome.runtime) {
}

if (typeof module !== 'undefined' && module.exports) {
// Export for importing types into popup.js, require()ing into unit tests.
// Export for importing types into popup.js and require()ing into unit tests.
Copy link
Member Author

Choose a reason for hiding this comment

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

require()ing into unit tests is also a lie, but could be true someday :) Meanwhile this block is needed for the mentioned popup.js use

@@ -1,37 +0,0 @@
/**
Copy link
Member Author

Choose a reason for hiding this comment

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

had no effect on the output. Maybe it was required for some ancient version of speedline that pulled in catapult?

return gulp.src('app/manifest.json')
.pipe(chromeManifest(manifestOpts))
Copy link
Member Author

Choose a reason for hiding this comment

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

this may have come from the original generator. Not entirely sure what it's supposed to do, maybe copy over deps? But since the only target we give is the script bundle, and because we copy that ourselves below after browserifying it, this also has no effect but copying over the manifest file (which we can do more simply)


// Inject the new browserified contents back into our gulp pipeline
file.contents = bundle.bundle();
}))
Copy link
Member Author

Choose a reason for hiding this comment

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

popup.js doesn't require() any other files and hasn't in a long time, so no need to run it through browserify.

@brendankenny
Copy link
Member Author

Aside from the entry file split, diffing a generated lighthouse-extension/dist against one generated by master yields only a difference of the header commit-hash comment and the browserify wrapper of popup.js (which does nothing since it calls itself), so not much going on here but cleaning up some cruft

@@ -27,7 +27,7 @@ const LR_PRESETS = {
* @return {Promise<string|Array<string>|void>}
*/
async function runLighthouseInLR(connection, url, flags, {lrDevice, categoryIDs, logAssets}) {
// Certain fixes need to kick-in under LR, see https://github.com/GoogleChrome/lighthouse/issues/5839
// Certain fixes need to kick in under LR, see https://github.com/GoogleChrome/lighthouse/issues/5839
Copy link
Collaborator

Choose a reason for hiding this comment

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

😆

.pipe(gulp.dest(distDir));
});

function applyBrowserifyTransforms(bundle) {
// Fix an issue with imported speedline code that doesn't brfs well.
return bundle.transform('./fs-transform', {global: true})
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

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!

@brendankenny brendankenny merged commit da218ff into master Oct 16, 2018
@brendankenny brendankenny deleted the builds branch October 16, 2018 19:02
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.

3 participants