Skip to content

Commit

Permalink
🏗 Replace logging in gulp bundle-size with output from filesize (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Feb 8, 2021
1 parent 36a941b commit 01abe80
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
43 changes: 18 additions & 25 deletions build-system/tasks/bundle-size/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const {
const {
VERSION: internalRuntimeVersion,
} = require('../../compile/internal-version');
const {cyan, green, red, yellow} = require('ansi-colors');
const {cyan, red, yellow} = require('ansi-colors');
const {log} = require('../../common/logging');
const {report, Report} = require('@ampproject/filesize');
const {report, NoTTYReport} = require('@ampproject/filesize');

const requestPost = util.promisify(require('request').post);

Expand All @@ -56,25 +56,18 @@ const replacementExpression = new RegExp(internalRuntimeVersion, 'g');
*/
async function getBrotliBundleSizes() {
const bundleSizes = {};

log(cyan('brotli'), 'bundle sizes are:');
await report(
const sizes = await report(
filesizeConfigPath,
(content) => content.replace(replacementExpression, normalizedRtvNumber),
class extends Report {
update(context) {
const completed = super.getUpdated(context);
for (const complete of completed) {
const [filePath, sizeMap] = complete;
const relativePath = path.relative('.', filePath);
const reportedSize = parseFloat((sizeMap[0][0] / 1024).toFixed(2));
log(' ', cyan(relativePath) + ':', green(reportedSize + 'KB'));
bundleSizes[relativePath] = reportedSize;
}
}
}
NoTTYReport,
/* silent */ false
);

for (const size of sizes) {
const [filePath, sizeMap] = size;
const relativePath = path.relative('.', filePath);
const reportedSize = parseFloat((sizeMap[0][0] / 1024).toFixed(2));
bundleSizes[relativePath] = reportedSize;
}
return bundleSizes;
}

Expand All @@ -95,7 +88,7 @@ function checkResponse(response, ...successMessages) {
}

/**
* Store the bundle size of a commit hash in the build artifacts storage
* Store the bundle sizes for a commit hash in the build artifacts storage
* repository to the passed value.
*/
async function storeBundleSize() {
Expand Down Expand Up @@ -138,7 +131,7 @@ async function storeBundleSize() {
cyan(shortSha(commitHash)) + '.'
);
} catch (error) {
log(red('Could not store the bundle size'));
log(red('Could not store bundle sizes'));
log(red(error));
process.exitCode = 1;
return;
Expand Down Expand Up @@ -201,7 +194,7 @@ async function reportBundleSize() {
cyan(shortSha(baseSha)) + '.'
);
} catch (error) {
log(red('Could not report the bundle size of this pull request'));
log(red('Could not report the bundle sizes for this pull request'));
log(red(error));
process.exitCode = 1;
return;
Expand All @@ -223,7 +216,7 @@ async function getLocalBundleSize() {
return;
} else {
log(
'Computing bundle size for version',
'Computing bundle sizes for version',
cyan(internalRuntimeVersion),
'at commit',
cyan(shortSha(gitCommitHash())) + '.'
Expand Down Expand Up @@ -255,11 +248,11 @@ bundleSize.description =
'Checks if the minified AMP binary has exceeded its size cap';
bundleSize.flags = {
'on_push_build':
' Store bundle size in AMP build artifacts repo ' +
' Store bundle sizes in the AMP build artifacts repo ' +
'(also implies --on_pr_build)',
'on_pr_build': ' Report the bundle size of this pull request to GitHub',
'on_pr_build': ' Report the bundle sizes for this pull request to GitHub',
'on_skipped_build':
" Set the status of this pull request's bundle " +
'size check in GitHub to `skipped`',
'on_local_build': ' Compute the bundle size of the locally built runtime',
'on_local_build': ' Compute bundle sizes for the locally built runtime',
};
54 changes: 38 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"devDependencies": {
"0x": "4.10.2",
"@ampproject/filesize": "4.2.0",
"@ampproject/filesize": "4.3.0",
"@ampproject/google-closure-compiler": "20210202.0.0",
"@ampproject/remapping": "1.0.1",
"@babel/core": "7.12.13",
Expand Down

0 comments on commit 01abe80

Please sign in to comment.