Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update dangerfile.ts
Browse files Browse the repository at this point in the history
Janpot committed Sep 15, 2023
1 parent ae83c19 commit dfacb22
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Inspire by React dangerfile
// Inspired by React dangerfile
// danger has to be the first thing required!
import { danger, markdown } from 'danger';
import { exec } from 'child_process';
@@ -55,16 +55,6 @@ function createComparisonFilter(parsedThreshold: number, gzipThreshold: number)
};
}

/**
* Checks if the bundle is of a package e.b. `@mui/material` but not
* `@mui/material/Paper`.
* @param {[string, any]} comparisonEntry
*/
function isPackageComparison(comparisonEntry: [string, any]) {
const [bundleKey] = comparisonEntry;
return !/^@[\w-]+\/[\w-]+\/.+$/.test(bundleKey);
}

/**
* Generates a user-readable string from a percentage change.
* @param {number} change
@@ -160,12 +150,25 @@ async function reportBundleSize() {
if (anyResultsChanges.length > 0) {
const importantChanges = mainResults
.filter(createComparisonFilter(parsedSizeChangeThreshold, gzipSizeChangeThreshold))
.filter(isPackageComparison)
.sort(([, a], [, b]) => {
const aDiff = Math.abs(a.parsed.absoluteDiff) + Math.abs(a.gzip.absoluteDiff);
const bDiff = Math.abs(b.parsed.absoluteDiff) + Math.abs(b.gzip.absoluteDiff);
return bDiff - aDiff;
})
.map(generateEmphasizedChange);

// have to guard against empty strings
if (importantChanges.length > 0) {
markdown(importantChanges.join('\n'));
const maxVisible = 20;

const lines = importantChanges.slice(0, maxVisible);

const hiddenChanges = Math.max(0, importantChanges.length - maxVisible);
if (hiddenChanges > 0) {
lines.push(`and [${hiddenChanges} more changes](${detailedComparisonToolpadUrl})`);
}

markdown(lines.join('\n'));
}

const details = `## Bundle size report

0 comments on commit dfacb22

Please sign in to comment.