From 7243bd58fc09f01e23c5c036413802f62d7977e5 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Thu, 14 Sep 2023 15:58:42 +0200 Subject: [PATCH 1/4] Replace bundle size reporter filter to include more entries in the danger report --- dangerfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dangerfile.ts b/dangerfile.ts index 72d77fe2615db4..7953d36065f3b5 100644 --- a/dangerfile.ts +++ b/dangerfile.ts @@ -62,7 +62,7 @@ function createComparisonFilter(parsedThreshold: number, gzipThreshold: number) */ function isPackageComparison(comparisonEntry: [string, any]) { const [bundleKey] = comparisonEntry; - return /^@[\w-]+\/[\w-]+$/.test(bundleKey); + return !/^@[\w-]+\/[\w-]+\/.+$/.test(bundleKey); } /** From ae83c1916540e225d5c292d9e14f516de800c9a2 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Thu, 14 Sep 2023 19:15:43 +0200 Subject: [PATCH 2/4] clean up comments --- dangerfile.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/dangerfile.ts b/dangerfile.ts index 7953d36065f3b5..bd769f141ae6b3 100644 --- a/dangerfile.ts +++ b/dangerfile.ts @@ -1,4 +1,4 @@ -// inspire by reacts dangerfile +// Inspire by React dangerfile // danger has to be the first thing required! import { danger, markdown } from 'danger'; import { exec } from 'child_process'; @@ -13,7 +13,7 @@ const parsedSizeChangeThreshold = 300; const gzipSizeChangeThreshold = 100; /** - * executes a git subcommand + * Executes a git subcommand. * @param {any} args */ function git(args: any) { @@ -40,8 +40,8 @@ async function reportBundleSizeCleanup() { } /** - * creates a callback for Object.entries(comparison).filter that excludes every - * entry that does not exceed the given threshold values for parsed and gzip size + * Creates a callback for Object.entries(comparison).filter that excludes every + * entry that does not exceed the given threshold values for parsed and gzip size. * @param {number} parsedThreshold * @param {number} gzipThreshold */ @@ -56,8 +56,8 @@ function createComparisonFilter(parsedThreshold: number, gzipThreshold: number) } /** - * checks if the bundle is of a package e.b. `@mui/material` but not - * `@mui/material/Paper` + * 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]) { @@ -66,7 +66,7 @@ function isPackageComparison(comparisonEntry: [string, any]) { } /** - * Generates a user-readable string from a percentage change + * Generates a user-readable string from a percentage change. * @param {number} change * @param {string} goodEmoji emoji on reduction * @param {string} badEmoji emoji on increase @@ -91,7 +91,7 @@ function generateEmphasizedChange([bundle, { parsed, gzip }]: [ } /** - * Puts results in different buckets wh + * Puts results in different buckets. * @param {*} results */ function sieveResults(results: Array<[string, T]>) { @@ -137,8 +137,7 @@ async function loadLastComparison( } async function reportBundleSize() { - // Use git locally to grab the commit which represents the place - // where the branches differ + // Use git locally to grab the commit which represents the place where the branches differ const upstreamRepo = danger.github.pr.base.repo.full_name; const upstreamRef = danger.github.pr.base.ref; try { From dfacb226baf8d65bcbef5df94b94c15b6507fcf1 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:03:04 +0200 Subject: [PATCH 3/4] Update dangerfile.ts --- dangerfile.ts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/dangerfile.ts b/dangerfile.ts index bd769f141ae6b3..46e886243b3ff6 100644 --- a/dangerfile.ts +++ b/dangerfile.ts @@ -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 From 5183a337c7f5d54169fcec41048bf2ff18b45f6e Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:06:27 +0200 Subject: [PATCH 4/4] Update dangerfile.ts --- dangerfile.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dangerfile.ts b/dangerfile.ts index 46e886243b3ff6..ef5b39acff3744 100644 --- a/dangerfile.ts +++ b/dangerfile.ts @@ -163,9 +163,9 @@ async function reportBundleSize() { const lines = importantChanges.slice(0, maxVisible); - const hiddenChanges = Math.max(0, importantChanges.length - maxVisible); - if (hiddenChanges > 0) { - lines.push(`and [${hiddenChanges} more changes](${detailedComparisonToolpadUrl})`); + const nrOfHiddenChanges = Math.max(0, importantChanges.length - maxVisible); + if (nrOfHiddenChanges > 0) { + lines.push(`and [${nrOfHiddenChanges} more changes](${detailedComparisonToolpadUrl})`); } markdown(lines.join('\n'));