Skip to content

Commit

Permalink
Perform a check on bundle size of minimal useful Realtime client
Browse files Browse the repository at this point in the history
Another protection against regressions in bundle size.

Resolves #1497.
  • Loading branch information
lawrence-forooghian committed Nov 17, 2023
1 parent 31d2e2d commit 478298d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/moduleReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 478298d

Please sign in to comment.