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

Integrate bundlesize and cap main binary size #14405

Merged
merged 8 commits into from
Apr 5, 2018

Conversation

dreamofabear
Copy link

Fixes #14394.

  • Checks amp.js on PR builds with max size of 315 KB (current 314.65 KB)
  • Checks v0.js on push builds with max size of 75 KB (current 74.9 KB)

@rsimha @erwinmombay Needs some extra work for GitHub integration: https://github.com/siddharthkp/bundlesize#2-build-status

@dreamofabear dreamofabear requested a review from rsimha April 3, 2018 23:33
Copy link
Contributor

@rsimha rsimha left a comment

Choose a reason for hiding this comment

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

Two more changes, in addition to the comments below:

package.json Outdated
@@ -59,6 +59,7 @@
"body-parser": "1.18.2",
"browserify": "16.1.1",
"browserify-istanbul": "3.0.1",
"bundlesize": "^0.17.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an exact version. Use:

yarn add --dev --exact bundlesize

Copy link
Author

Choose a reason for hiding this comment

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

Done, thanks.

const args = compiled
? '-f "./dist/v0.js" -s "75 kB"'
: '-f "./dist/amp.js" -s "315 kB"';
timedExecOrDie(`npx bundlesize ${args}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on https://github.com/siddharthkp/bundlesize#cli, shouldn't this be...

timedExecOrDie(`bundlesize ${args}`);

... without the npx?

Copy link
Author

Choose a reason for hiding this comment

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

That only works if bundlesize is installed as a global package. Check out npx: https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b

@dreamofabear
Copy link
Author

dreamofabear commented Apr 4, 2018

Weird, Travis appears to build amp.js with a different size vs. my local build on macOS.

Travis:

FAIL  ./dist/amp.js: 332.28KB > maxSize 315KB (gzip) 

Local:

 PASS  ./dist/amp.js: 315KB < maxSize 315KB (gzip) 

@rsimha
Copy link
Contributor

rsimha commented Apr 4, 2018

Weird. Travis runs on Linux VMs. I ran this locally on Linux, and the size is 315 KB.

npx bundlesize -f "./dist/amp.js" -s "315 kB"
 PASS  ./dist/amp.js: 315KB < maxSize 315KB (gzip) 

@rsimha
Copy link
Contributor

rsimha commented Apr 4, 2018

@choumx maybe do a debug Travis build where you print the contents of dist/amp.js if it's over the limit, and diff it against your local build?

@dreamofabear
Copy link
Author

There are actually many differences e.g. how class functions are declared:

screen shot 2018-04-05 at 1 13 22 am

It's because we have a different browsers target for Babel on Travis:

amphtml/gulpfile.js

Lines 1100 to 1104 in 970642f

if (process.env.TRAVIS) {
browsers.push('last 2 versions', 'safari >= 9');
} else {
browsers.push('Last 4 Chrome versions');
}

TIL...

@dreamofabear
Copy link
Author

dreamofabear commented Apr 5, 2018

@erwinmombay Any problems if we also use browsers: ['last 2 versions', 'safari >= 9'] for local dev?

@dreamofabear dreamofabear requested a review from erwinmombay April 5, 2018 19:26
@erwinmombay
Copy link
Member

@choumx nope. LGTM

gulpfile.js Outdated
@@ -797,9 +798,27 @@ function performBuild(watch) {
buildExtensions({bundleOnlyIfListedInFiles: !watch, watch}),
compile(watch),
]);
}).then(() => {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this block?

gulpfile.js Outdated
if (p.status != 0) {
log(cyan('bundlesize: ') + red('The main bundle (amp.js/v0.js) has ' +
'exceeded its size cap.') + ' This is part of a new effort to reduce ' +
'bundle size (see #14392). Please contact @choumx if this blocks you.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Style nit: Standard warning and error formats used elsewhere in this file are:

log(red('ERROR:'), 'Something bad happened while doing', cyan('foo'), 'to', cyan('bar'), '. Talk to @choumx.');
log(yellow('WARNING:'), 'Something not so bad happened while doing', cyan('foo'), 'to', cyan('bar'), '. Talk to @choumx.');

@dreamofabear
Copy link
Author

@rsimha Thanks for the quick reviews.

@rsimha
Copy link
Contributor

rsimha commented Apr 5, 2018

Looks like this tool needs r/w access to commit statuses in order to enable GitHub PR integration. Unfortunately, if we store BUNDLESIZE_GITHUB_TOKEN as a secure variable on Travis, it won't be visible to PR builds, and PR integration is useless on push builds.

See https://github.com/siddharthkp/bundlesize#2-build-status

/cc @cramforce

const size = compiled ? '75.1kB' : '332.3kB';
const cmd = `npx bundlesize -f "${file}" -s "${size}"`;
log(green('Running ') + cyan(cmd) + green('...\n'));
const p = exec(cmd);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will result in a warning being printed to advertise the tool's GH integration feature. Not sure it's worth trying to silence it.

https://travis-ci.org/ampproject/amphtml/jobs/362305001#L663-L666

Copy link
Author

Choose a reason for hiding this comment

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

siddharthkp/bundlesize#158 I think it's harmless.

@dreamofabear dreamofabear merged commit 3abc401 into ampproject:master Apr 5, 2018
@dreamofabear dreamofabear deleted the bundlesize branch April 5, 2018 22:03
@dreamofabear
Copy link
Author

Unfortunately, if we store BUNDLESIZE_GITHUB_TOKEN as a secure variable on Travis, it won't be visible to PR builds, and PR integration is useless on push builds.

Huh, so how can PR integration on Travis work in the first place?

@rsimha
Copy link
Contributor

rsimha commented Apr 5, 2018

I think it's possible on repositories that don't use forks for pull requests.

See the text in the blue box here: https://docs.travis-ci.com/user/environment-variables/#Defining-encrypted-variables-in-.travis.yml

@dreamofabear
Copy link
Author

Right-o. 😄 Thanks for the link.

glevitzky pushed a commit that referenced this pull request Apr 27, 2018
* Add bundlesize dep.

* Move config from package.jsoon to CLI.

* Use exact version.

* Also run in integration shard in PR builds.

* Debugging amp.js.

* Revert debugging, use same Babel browser target in Travis and local dev.

* Move logic from pr-check.js to gulpfile.js.

* Raghu's comments.
@rsimha
Copy link
Contributor

rsimha commented May 2, 2018

@choumx I've created siddharthkp/bundlesize#219 to track the feasibility of GH integration for AMP, given that we accept PRs from forks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants