Skip to content

build: round payload size for comparison #7174

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

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tools/gulp/tasks/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ async function calculatePayloadDiff(database: firebaseAdmin.database.Database, c

// Calculate the payload diffs by subtracting the previous size of the FESM ES2015 bundles.
const cdkFullSize = currentPayload.cdk_fesm_2015;
const cdkDiff = cdkFullSize - previousPayload.cdk_fesm_2015;
const cdkDiff = roundFileSize(cdkFullSize - previousPayload.cdk_fesm_2015);
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use toFixed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It returns a string instead of a number. I don't think re-parsing is better.

Copy link
Member

Choose a reason for hiding this comment

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

Generally you want to keep your values in number format as long as possible and them format them just before or past of displaying them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's what this does now. toFixed() returns a string instead of a number. The formatting will happen in the Firebase function.


const materialFullSize = currentPayload.material_fesm_2015;
const materialDiff = materialFullSize - previousPayload.material_fesm_2015;
const materialDiff = roundFileSize(materialFullSize - previousPayload.material_fesm_2015);

// Set the Github statuses for the packages by sending a HTTP request to the dashboard functions.
await Promise.all([
Expand Down Expand Up @@ -174,3 +174,8 @@ function getCommitFromPreviousPayloadUpload(): string {
return spawnSync('git', ['rev-parse', process.env['TRAVIS_BRANCH']]).stdout.toString().trim();
}
}

/** Rounds the specified file size to two decimal places. */
function roundFileSize(fileSize: number) {
return Math.round(fileSize * 100) / 100;
}