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

Size limit support #691

Closed
wants to merge 11 commits into from
10 changes: 8 additions & 2 deletions plugins/size/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ export default class SizePlugin implements Plugin<SizeArgs> {
});
const header = args.css ? cssHeader : defaultHeader;

const underFailureThreshold = size &&
size.percent <= FAILURE_THRESHOLD ||
size.percent === Infinity;
const underSizeLimit = args.limit ? size.pr.js + size.pr.css <= args.limit : true;
const success = underFailureThreshold && underSizeLimit;

await reportResults(
name,
size.percent <= FAILURE_THRESHOLD || size.percent === Infinity,
success,
Boolean(args.comment),
table(
args.detailed
Expand All @@ -107,7 +113,7 @@ export default class SizePlugin implements Plugin<SizeArgs> {
createDiff();
}

if (size && size.percent > FAILURE_THRESHOLD && size.percent !== Infinity) {
if (!success) {
process.exit(1);
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/size/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface SizeArgs {
ignore?: string[]
/** The registry to install packages from */
registry?: string
/** Size limit failure threshold */
limit?: number
JordanForeman marked this conversation as resolved.
Show resolved Hide resolved
/** Size Failure Threshold */
failureThreshold?: number
/** Run the plugin against merge base. (Will be slower due to additional build process) */
Expand Down