Skip to content

Commit

Permalink
WIP Tracerbench Travis setup
Browse files Browse the repository at this point in the history
dont checkin results

configure azure job, make first thing for testing

config updates

Able to get results from Tracerbench

redirect for tracerbench

Update URLs to include ?tracerbench=true

wip

moves .server-replay.json to root

wip

cleanup

cleanup

cleanup

cleanup

change command

Make process terminate with exit code 0

Ignore tracerbench-results files

Delete generated JSON file

rename directory

Bump ember-decorators-polyfill from 1.0.6 to 1.1.0

Bumps [ember-decorators-polyfill](https://github.com/pzuraq/ember-decorators-polyfill) from 1.0.6 to 1.1.0.
- [Release notes](https://github.com/pzuraq/ember-decorators-polyfill/releases)
- [Commits](ember-polyfills/ember-decorators-polyfill@1.0.6...1.1.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @ember/optional-features from 1.0.0 to 1.1.0

Bumps [@ember/optional-features](https://github.com/emberjs/ember-optional-features) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/emberjs/ember-optional-features/releases)
- [Changelog](https://github.com/emberjs/ember-optional-features/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember-optional-features@v1.0.0...v1.1.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

[CHORE] fix Typo (emberjs#6635)

Happen to run into this typo. Been using Ember for years, love your work! Good luck!

Co-authored-by: igorT <[email protected]>

Update Changelog for v3.13.0

update changelog for v3.13.1

[CHORE] adds infra for testing calls to Ember warn|deprecate|assert (emberjs#6626)

* [CHORE] adds infra for testing calls to Ember warn|deprecate|assert

* fix production tests

* address feedback

* feedback on labels

* remove id checks

[CHORE] Refactor integration/multiple-stores-test.js in order to remove run loop usage (emberjs#6632)

Bump ember-simple-tree from 0.7.0 to 0.7.1

Bumps [ember-simple-tree](https://github.com/btecu/ember-simple-tree) from 0.7.0 to 0.7.1.
- [Release notes](https://github.com/btecu/ember-simple-tree/releases)
- [Commits](btecu/ember-simple-tree@0.7.0...0.7.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump ember-decorators-polyfill from 1.1.0 to 1.1.1

Bumps [ember-decorators-polyfill](https://github.com/pzuraq/ember-decorators-polyfill) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/pzuraq/ember-decorators-polyfill/releases)
- [Commits](ember-polyfills/ember-decorators-polyfill@1.1.0...1.1.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

cleanup serializer documentation (emberjs#6575)

ISSUE-6012: test: added test for meta property and bug fix. (emberjs#6640)

[FEAT links] ensures full links object support for relationships (emberjs#6606)

* [FEAT links] ensures full links object support for relationships

* fix lint

* add feature flags

[BUGFIX release] Enable `store.createRecord` in FastBoot (emberjs#6568)

* Add FastBoot test for store.createRecord

Fails at the moment.

* Enable store.createRecord in FastBoot

Changes the V4 UUID generation to leverage `FastBoot.require` when
possible. This currently requires that the host application add the
following to their `package.json`:

```
"fastbootDependencies": [
  "crypto"
]
```

* fix types

[CHORE] rename and restructure packages to clarify unpublished/private status

move unpublished packages into directories marked private

move published but private into better naming convention

move unpublished into better naming convention

change -build-infra imports to private-build-infra

larger re-org

Bump eslint-config-prettier from 6.4.0 to 6.5.0

Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 6.4.0 to 6.5.0.
- [Release notes](https://github.com/prettier/eslint-config-prettier/releases)
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/master/CHANGELOG.md)
- [Commits](prettier/eslint-config-prettier@v6.4.0...v6.5.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump eslint from 6.5.1 to 6.6.0

Bumps [eslint](https://github.com/eslint/eslint) from 6.5.1 to 6.6.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](eslint/eslint@v6.5.1...v6.6.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

[CHORE] refactor: Remove runloop usage in destroy module of integration/store… (emberjs#6646)

* refactor: Remove runloop usage in destroy module of integration/store-test

* fix linter errors

Bump @types/ember__debug from 3.0.5 to 3.0.6 (emberjs#6647)

Bumps [@types/ember__debug](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/ember__debug) from 3.0.5 to 3.0.6.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/ember__debug)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump eslint-plugin-mocha from 6.2.0 to 6.2.1

Bumps [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha) from 6.2.0 to 6.2.1.
- [Release notes](https://github.com/lo1tuma/eslint-plugin-mocha/releases)
- [Changelog](https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/CHANGELOG.md)
- [Commits](lo1tuma/eslint-plugin-mocha@6.2.0...6.2.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump qunit-dom from 0.9.0 to 0.9.1

Bumps [qunit-dom](https://github.com/simplabs/qunit-dom) from 0.9.0 to 0.9.1.
- [Release notes](https://github.com/simplabs/qunit-dom/releases)
- [Changelog](https://github.com/simplabs/qunit-dom/blob/master/CHANGELOG.md)
- [Commits](mainmatter/qunit-dom@v0.9.0...v0.9.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @typescript-eslint/parser from 2.5.0 to 2.6.0

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.0/packages/parser)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @typescript-eslint/eslint-plugin from 2.5.0 to 2.6.0

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.0/packages/eslint-plugin)

Signed-off-by: dependabot-preview[bot] <[email protected]>

fix tracerbench command for renamed test app folder

Setup har-remix

replace server-replay with har-remix

Use concurrently from node_modules instead of global installation

wip

Update bash script to use ember-data workspace for experiment

relationship performance bash script updates

removes line breaks

removes .travis.yml from test app

cleanup linting

change eslint config

cleanup

remove comments

updates azure-pipelines.yml

adds tracerbench to github action workflow

Update CI to install PM2 globally

[CHORE] allow asserting all tests for deprecations (emberjs#6627)

* [CHORE] configure the ability to filter deprecations from assertNoDeprecations

* turn off helpers until tests are fixed

[DOC] Close code block in the description

Bump ember-qunit from 4.5.1 to 4.6.0

Bumps [ember-qunit](https://github.com/emberjs/ember-qunit) from 4.5.1 to 4.6.0.
- [Release notes](https://github.com/emberjs/ember-qunit/releases)
- [Changelog](https://github.com/emberjs/ember-qunit/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember-qunit@v4.5.1...v4.6.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump ember-fetch from 6.7.1 to 6.7.2

Bumps [ember-fetch](https://github.com/ember-cli/ember-fetch) from 6.7.1 to 6.7.2.
- [Release notes](https://github.com/ember-cli/ember-fetch/releases)
- [Changelog](https://github.com/ember-cli/ember-fetch/blob/v6.7.2/CHANGELOG.md)
- [Commits](ember-cli/ember-fetch@v6.7.1...v6.7.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump ember-load-initializers from 2.1.0 to 2.1.1

Bumps [ember-load-initializers](https://github.com/ember-cli/ember-load-initializers) from 2.1.0 to 2.1.1.
- [Release notes](https://github.com/ember-cli/ember-load-initializers/releases)
- [Changelog](https://github.com/ember-cli/ember-load-initializers/blob/master/CHANGELOG.md)
- [Commits](ember-cli/ember-load-initializers@v2.1.0...v2.1.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump ember-source from 3.13.3 to 3.14.1

Bumps [ember-source](https://github.com/emberjs/ember.js) from 3.13.3 to 3.14.1.
- [Release notes](https://github.com/emberjs/ember.js/releases)
- [Changelog](https://github.com/emberjs/ember.js/blob/master/CHANGELOG.md)
- [Commits](emberjs/ember.js@v3.13.3...v3.14.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump eslint-plugin-ember from 7.2.0 to 7.3.0

Bumps [eslint-plugin-ember](https://github.com/ember-cli/eslint-plugin-ember) from 7.2.0 to 7.3.0.
- [Release notes](https://github.com/ember-cli/eslint-plugin-ember/releases)
- [Changelog](https://github.com/ember-cli/eslint-plugin-ember/blob/master/CHANGELOG.md)
- [Commits](ember-cli/eslint-plugin-ember@v7.2.0...v7.3.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

[CHORE] adds asset reporting infra (emberjs#6655)

* adds asset reporting infra

* generify compression and use zlib brotli to compress

* avoid jq for the comment

* the moon is pretty

* fix byte size calc

[BUGFIX adapter]: Fix problem with headers precedence emberjs#6588 (emberjs#6650)

[CHORE] fix location of fastboot test for new person (emberjs#6668)

Bump ember-cli-pretender from 3.1.1 to 3.2.0

Bumps [ember-cli-pretender](https://github.com/rwjblue/ember-cli-pretender) from 3.1.1 to 3.2.0.
- [Release notes](https://github.com/rwjblue/ember-cli-pretender/releases)
- [Changelog](https://github.com/rwjblue/ember-cli-pretender/blob/master/CHANGELOG.md)
- [Commits](rwjblue/ember-cli-pretender@v3.1.1...v3.2.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @typescript-eslint/eslint-plugin from 2.6.0 to 2.6.1

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.1/packages/eslint-plugin)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @typescript-eslint/parser from 2.6.0 to 2.6.1

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v2.6.1/packages/parser)

Signed-off-by: dependabot-preview[bot] <[email protected]>

[CHORE] move Errors into @ember-data/model (emberjs#6675)

[BUGFIX] modelFor should return a stable ShimModelClass (emberjs#6610)

[BUGFIX modelFor] ensures modelFor works for models with schemas but no classes

add test for referential stability

ensure relationships also trigger

[CHORE] test fixes for deprecations, enables asserting all deprecations (emberjs#6628)

* [CHORE] test fixes for deprecations, enables asserting all deprecations

* fix lint

* dont run in prod

* make prod happy

* fix lint

* fix deprecations in ff code

Bump ember-cli-yuidoc from 0.8.8 to 0.9.1 (emberjs#6664)

Bumps [ember-cli-yuidoc](https://github.com/cibernox/ember-cli-yuidoc) from 0.8.8 to 0.9.1.
- [Release notes](https://github.com/cibernox/ember-cli-yuidoc/releases)
- [Changelog](https://github.com/cibernox/ember-cli-yuidoc/blob/master/CHANGELOG.md)
- [Commits](cibernox/ember-cli-yuidoc@v0.8.8...v0.9.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Bump @babel/plugin-transform-typescript from 7.6.3 to 7.7.0

Bumps [@babel/plugin-transform-typescript](https://github.com/babel/babel) from 7.6.3 to 7.7.0.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/master/CHANGELOG.md)
- [Commits](babel/babel@v7.6.3...v7.7.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

[CHORE] Improve output and fail test for Asset size Check (emberjs#6676)

* [CHORE] Improve output and fail test for Asset size Check

* when using tee we need to ensure failures are propagated

wip

rename shell scripts

docs
  • Loading branch information
David Tang committed Nov 6, 2019
1 parent 45b7e91 commit ef51280
Show file tree
Hide file tree
Showing 59 changed files with 1,977 additions and 799 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
'.mocharc.js',
'.eslintrc.js',
'.prettierrc.js',
'bin/*',
'bin/**',
'packages/private-build-infra/src/**/*.js',
'packages/unpublished-relationship-performance-test-app/bin/*.js',
'packages/unpublished-test-infra/src/**/*.js',
Expand Down Expand Up @@ -109,12 +109,13 @@ module.exports = {

// bin files
{
files: ['bin/*', 'packages/unpublished-relationship-performance-test-app/bin/*'],
files: ['bin/**', 'packages/unpublished-relationship-performance-test-app/bin/*'],
// eslint-disable-next-line node/no-unpublished-require
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
'no-console': 'off',
'no-process-exit': 'off',
'node/no-unpublished-require': 'off',
'node/no-unsupported-features/node-builtins': 'off',
}),
},
],
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/asset-size-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: AssetSizeCheck

on:
pull_request:
branches:
- master

jobs:
asset-size-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: 12.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check SHA
run: |
sha=$(git rev-parse --short=8 HEAD)
echo "HEAD sha=$sha"
echo "GITHUB_SHA sha=$GITHUB_SHA"
mkdir -p tmp
echo $sha > tmp/sha-for-check.txt
originSha=$(git rev-parse HEAD^2)
echo $originSha > tmp/sha-for-commit.txt
git show --format=short --no-patch $originSha
- name: Checkout master
run: git checkout master
- name: Install dependencies for master
run: yarn install
- name: Build Production master
# This will leave the assets in a dist that is maintained when
# We switch back to the primary branch
run: yarn workspace ember-data ember build -e production
- name: Checkout ${{github.ref}}
# We checkout the PR Branch before parsing the master vendor file
# So that we are always using the current analysis tooling
run: |
sha=$(cat tmp/sha-for-check.txt)
git checkout --progress --force $sha
- name: Install dependencies for ${{github.ref}}
run: yarn install
- name: Parse Master Assets
run: |
node ./bin/asset-size-tracking/generate-analysis.js
mkdir -p tmp
mkdir -p tmp/asset-sizes
node ./bin/asset-size-tracking/print-analysis.js -show > tmp/asset-sizes/master-analysis.txt
- name: Upload Master Dist Artifacts
uses: actions/upload-artifact@v1
with:
name: master-dist
path: packages/-ember-data/dist/assets
- name: Build Production ${{github.ref}}
run: yarn workspace ember-data ember build -e production
- name: Test Asset Sizes
run: |
mkdir -p tmp
mkdir -p tmp/asset-sizes
set -o pipefail
node ./bin/asset-size-tracking/generate-diff.js | tee tmp/asset-sizes/diff.txt
- name: Prepare Data For Report
if: failure() || success()
run: |
node ./bin/asset-size-tracking/generate-analysis.js
- name: Print Asset Size Report
if: failure() || success()
run: |
set -o pipefail
node ./bin/asset-size-tracking/print-analysis.js | tee tmp/asset-sizes/commit-analysis.txt
- name: Upload ${{github.ref}} Dist Artifacts
uses: actions/upload-artifact@v1
with:
name: commit-dist
path: packages/-ember-data/dist/assets
- name: Upload Report Artifacts
uses: actions/upload-artifact@v1
with:
name: reports
path: tmp/asset-sizes
- name: Report Asset Sizes
if: failure() || success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
COMMENT_MARKER="Asset Size Report for "=
sha=$(cat tmp/sha-for-commit.txt)
node ./bin/asset-size-tracking/src/create-comment-text.js $sha > tmp/asset-sizes/comment.txt
COMMENT_TEXT="@./tmp/asset-sizes/comment.txt"
source bin/asset-size-tracking/src/post-comment.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tmp
# dependencies
bower_components
node_modules
bin/asset-size-tracking/current-data.json

# misc
.env*
Expand Down
20 changes: 20 additions & 0 deletions bin/asset-size-tracking/generate-analysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
/**
* Analyze Ember-Data Modules
*
* Generates a JSON file with details of size costs of each individual module
* and package. You should crate a production build of the ember-data
* package prior to running this script.
*
*/
const fs = require('fs');
const path = require('path');
let INPUT_FILE = process.argv[2] || false;
const parseModules = require('./src/parse-modules');
const getBuiltDist = require('./src/get-built-dist');

const builtAsset = getBuiltDist(INPUT_FILE);
const library = parseModules(builtAsset);
const outputPath = path.resolve(__dirname, './current-data.json');

fs.writeFileSync(outputPath, JSON.stringify(library, null, 2));
246 changes: 246 additions & 0 deletions bin/asset-size-tracking/generate-diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
'use strict';

const fs = require('fs');
const path = require('path');
const Library = require('./src/library');
const parseModules = require('./src/parse-modules');
const getBuiltDist = require('./src/get-built-dist');
const chalk = require('chalk');
const library_failure_threshold = 15;
const package_warn_threshold = 0;

let BASE_DATA_FILE = process.argv[2] || false;
let NEW_VENDOR_FILE = process.argv[3] || false;

if (!BASE_DATA_FILE) {
BASE_DATA_FILE = path.resolve(__dirname, './current-data.json');
}

const data = fs.readFileSync(BASE_DATA_FILE, 'utf-8');
const current_library = Library.fromData(JSON.parse(data));

const builtAsset = getBuiltDist(NEW_VENDOR_FILE);
const new_library = parseModules(builtAsset);

function getDiff(oldLibrary, newLibrary) {
const diff = {
name: oldLibrary.name,
currentSize: oldLibrary.absoluteSize,
newSize: newLibrary.absoluteSize,
currentSizeCompressed: oldLibrary.compressedSize,
newSizeCompressed: newLibrary.compressedSize,
packages: {},
};
oldLibrary.packages.forEach(pkg => {
diff.packages[pkg.name] = {
name: pkg.name,
currentSize: pkg.absoluteSize,
newSize: 0,
currentSizeCompressed: pkg.compressedSize,
newSizeCompressed: 0,
modules: {},
};
let modules = diff.packages[pkg.name].modules;
pkg.modules.forEach(m => {
modules[m.name] = {
name: m.name,
currentSize: m.absoluteSize,
newSize: 0,
currentSizeCompressed: m.compressedSize,
newSizeCompressed: 0,
};
});
});
newLibrary.packages.forEach(pkg => {
diff.packages[pkg.name] = diff.packages[pkg.name] || {
name: pkg.name,
currentSize: 0,
newSize: pkg.absoluteSize,
currentSizeCompressed: 0,
newSizeCompressed: pkg.compressedSize,
modules: {},
};
diff.packages[pkg.name].newSize = pkg.absoluteSize;
diff.packages[pkg.name].newSizeCompressed = pkg.compressedSize;
let modules = diff.packages[pkg.name].modules;
pkg.modules.forEach(m => {
modules[m.name] = modules[m.name] || {
name: m.name,
currentSize: 0,
newSize: m.absoluteSize,
currentSizeCompressed: 0,
newSizeCompressed: m.compressedSize,
};
modules[m.name].newSize = m.absoluteSize;
modules[m.name].newSizeCompressed = m.compressedSize;
});
});
diff.packages = Object.values(diff.packages);
diff.packages.forEach(pkg => {
pkg.modules = Object.values(pkg.modules);
});

return diff;
}

const diff = getDiff(current_library, new_library);

function analyzeDiff(diff) {
let failures = [];
let warnings = [];

if (diff.currentSize < diff.newSize) {
let delta = diff.newSize - diff.currentSize;
let compressedDelta = diff.newSizeCompressed - diff.currentSizeCompressed;
if (delta > library_failure_threshold && compressedDelta > 0) {
failures.push(
`The size of the library ${diff.name} has increased by ${formatBytes(delta)} (${formatBytes(
compressedDelta
)} compressed) which exceeds the failure threshold of ${library_failure_threshold} bytes.`
);
}
}

diff.packages.forEach(pkg => {
if (pkg.currentSize < pkg.newSize) {
let delta = pkg.newSize - pkg.currentSize;
if (delta > package_warn_threshold) {
warnings.push(`The uncompressed size of the package ${pkg.name} has increased by ${formatBytes(delta)}.`);
}
}
});

return { failures, warnings };
}

function printDiff(diff) {
console.log('\n```\n');
printItem(diff);
diff.packages.forEach(pkg => {
printItem(pkg, 2);
pkg.modules.forEach(m => {
printItem(m, 4);
});
});
console.log('\n```\n');
}

function printItem(item, indent = 0) {
if (item.currentSize !== item.newSize) {
const indentColor = indent >= 4 ? 'grey' : indent >= 2 ? 'yellow' : indent >= 0 ? 'magenta' : 'green';
console.log(
leftPad(chalk[indentColor](item.name) + ' ' + formatSize(item, false) + ' ' + formatSize(item, true), indent * 2)
);
}
}

function formatSize(item, isCompressed = false) {
let size = formatBytes(isCompressed ? item.newSizeCompressed : item.newSize);
let delta = formatDelta(item, isCompressed);

return isCompressed ? chalk.grey(`(${chalk.white(size)} ${delta} compressed)`) : `${chalk.white(size)} ${delta}`;
}

function formatDelta(item, isCompressed = false) {
let delta = isCompressed ? item.newSizeCompressed - item.currentSizeCompressed : item.newSize - item.currentSize;

if (delta === 0) {
return chalk.black('±0 B');
}

if (delta < 0) {
return chalk.green(`${formatBytes(delta)}`);
} else {
return chalk.red(`+${formatBytes(delta)}`);
}
}

function humanizeNumber(n) {
let s = n.toFixed(2);
if (s.charAt(s.length - 1) === '0') {
s = n.toFixed(1);

if (s.charAt(s.length - 2) === '0') {
s = n.toFixed(0);
}
}
return s;
}

function formatBytes(b) {
let str;
if (b > 1024 || b < -1024) {
str = humanizeNumber(b / 1024) + ' KB';
} else {
str = humanizeNumber(b) + ' B';
}

return str;
}

function leftPad(str, len, char = ' ') {
for (let i = 0; i < len; i++) {
str = char + str;
}
return str;
}

const { failures, warnings } = analyzeDiff(diff);

if (failures.length) {
console.log(`\n<details>\n <summary>${failures[0]}</summary>`);
if (failures.length > 1) {
console.log('\nFailed Checks\n-----------------------');
failures.forEach(f => {
console.log(f);
});
}
if (warnings.length) {
console.log('\nWarnings\n-----------------------');
warnings.forEach(w => {
console.log(w);
});
}
console.log('\n**Changeset**\n');
printDiff(diff);
console.log('\n</details>');
process.exit(1);
} else {
let delta = diff.currentSize - diff.newSize;
if (delta === 0) {
console.log(`\n<details>\n <summary>${diff.name} has not changed in size</summary>`);
} else if (delta > 0) {
console.log(
`\n<details>\n <summary>${diff.name} shrank by ${formatBytes(delta)} (${formatBytes(
diff.currentSizeCompressed - diff.newSizeCompressed
)} compressed)</summary>`
);
} else {
let compressedDelta = diff.newSizeCompressed - diff.currentSizeCompressed;
if (-1 * delta < library_failure_threshold) {
console.log(
`\n<details>\n <summary>${diff.name} increased by ${formatBytes(-1 * delta)} (${formatBytes(
compressedDelta
)} compressed) which is within the allowed tolerance of ${library_failure_threshold} bytes uncompressed</summary>`
);
} else {
console.log(
`\n<details>\n <summary>${diff.name} increased by ${formatBytes(
-1 * delta
)} uncompressed but decreased by ${formatBytes(-1 * compressedDelta)} compressed</summary>`
);
}
}
if (warnings.length) {
console.log('\nWarnings\n-----------------------');
warnings.forEach(w => {
console.log(w);
});
} else {
console.log('\nIf any packages had changed sizes they would be listed here.');
}
console.log('\n**Changeset**\n');
printDiff(diff);
console.log('\n</details>');
process.exit(0);
}
Loading

0 comments on commit ef51280

Please sign in to comment.