From 478298d6d7b1d7db87bf0bc83b213f14c77d4f3f Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Fri, 17 Nov 2023 14:16:59 -0300 Subject: [PATCH] Perform a check on bundle size of minimal useful Realtime client Another protection against regressions in bundle size. Resolves #1497. --- scripts/moduleReport.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/moduleReport.ts b/scripts/moduleReport.ts index 394eb7e8e3..4b9aec1738 100644 --- a/scripts/moduleReport.ts +++ b/scripts/moduleReport.ts @@ -2,6 +2,9 @@ import esbuild from 'esbuild'; import path from 'path'; import { explore } from 'source-map-explorer'; +// The maximum size we allow for a minimal useful Realtime bundle (i.e. one that can subscribe to a channel) +const minimalUsefulRealtimeBundleSizeThresholdKiB = 108; + // List of all modules accepted in ModulesMap const moduleNames = [ 'Rest', @@ -147,6 +150,27 @@ function printAndCheckFunctionSizes() { return errors; } +function printAndCheckMinimalUsefulRealtimeBundleSize() { + const errors: Error[] = []; + + const exports = ['BaseRealtime', 'FetchRequest', 'WebSocketTransport']; + const size = getImportSize(exports); + + console.log(`Minimal useful Realtime (${exports.join(' + ')}): ${formatBytes(size)}`); + + if (size > minimalUsefulRealtimeBundleSizeThresholdKiB * 1024) { + errors.push( + new Error( + `Minimal useful Realtime bundle is ${formatBytes( + size + )}, which is greater than allowed maximum of ${minimalUsefulRealtimeBundleSizeThresholdKiB} KiB.` + ) + ); + } + + return errors; +} + // Performs a sense check that there are no unexpected files making a large contribution to the BaseRealtime bundle size. async function checkBaseRealtimeFiles() { const baseRealtimeBundleInfo = getBundleInfo(['BaseRealtime']); @@ -234,6 +258,7 @@ async function checkBaseRealtimeFiles() { (async function run() { const errors: Error[] = []; + errors.push(...printAndCheckMinimalUsefulRealtimeBundleSize()); errors.push(...printAndCheckModuleSizes()); errors.push(...printAndCheckFunctionSizes()); errors.push(...(await checkBaseRealtimeFiles()));