Skip to content

Commit e0fe4fa

Browse files
committed
Update moduleReport to include external field for LiveObjects plugin
1 parent a21740b commit e0fe4fa

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

scripts/moduleReport.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ const functions = [
3737
{ name: 'constructPresenceMessage', transitiveImports: [] },
3838
];
3939

40+
// List of all buildable plugins available as a separate export
41+
interface PluginInfo {
42+
description: string;
43+
path: string;
44+
external?: string[];
45+
}
46+
47+
const buildablePlugins: Record<'push' | 'liveObjects', PluginInfo> = {
48+
push: { description: 'Push', path: './build/push.js', external: ['ulid'] },
49+
liveObjects: { description: 'LiveObjects', path: './build/liveobjects.js', external: ['deep-equal'] },
50+
};
51+
4052
function formatBytes(bytes: number) {
4153
const kibibytes = bytes / 1024;
4254
const formatted = kibibytes.toFixed(2);
@@ -70,7 +82,7 @@ function getModularBundleInfo(exports: string[]): BundleInfo {
7082
}
7183

7284
// Uses esbuild to create a bundle containing the named exports from a given module
73-
function getBundleInfo(modulePath: string, exports?: string[]): BundleInfo {
85+
function getBundleInfo(modulePath: string, exports?: string[], external?: string[]): BundleInfo {
7486
const outfile = exports ? exports.join('') : 'all';
7587
const exportTarget = exports ? `{ ${exports.join(', ')} }` : '*';
7688
const result = esbuild.buildSync({
@@ -84,7 +96,7 @@ function getBundleInfo(modulePath: string, exports?: string[]): BundleInfo {
8496
outfile,
8597
write: false,
8698
sourcemap: 'external',
87-
external: ['ulid'],
99+
external,
88100
});
89101

90102
const pathHasBase = (component: string) => {
@@ -183,9 +195,9 @@ async function calculateAndCheckFunctionSizes(): Promise<Output> {
183195
return output;
184196
}
185197

186-
async function calculatePluginSize(options: { path: string; description: string }): Promise<Output> {
198+
async function calculatePluginSize(options: PluginInfo): Promise<Output> {
187199
const output: Output = { tableRows: [], errors: [] };
188-
const pluginBundleInfo = getBundleInfo(options.path);
200+
const pluginBundleInfo = getBundleInfo(options.path, undefined, options.external);
189201
const sizes = {
190202
rawByteSize: pluginBundleInfo.byteSize,
191203
gzipEncodedByteSize: (await promisify(gzip)(pluginBundleInfo.code)).byteLength,
@@ -200,11 +212,11 @@ async function calculatePluginSize(options: { path: string; description: string
200212
}
201213

202214
async function calculatePushPluginSize(): Promise<Output> {
203-
return calculatePluginSize({ path: './build/push.js', description: 'Push' });
215+
return calculatePluginSize(buildablePlugins.push);
204216
}
205217

206218
async function calculateLiveObjectsPluginSize(): Promise<Output> {
207-
return calculatePluginSize({ path: './build/liveobjects.js', description: 'LiveObjects' });
219+
return calculatePluginSize(buildablePlugins.liveObjects);
208220
}
209221

210222
async function calculateAndCheckMinimalUsefulRealtimeBundleSize(): Promise<Output> {
@@ -291,7 +303,8 @@ async function checkBaseRealtimeFiles() {
291303
}
292304

293305
async function checkPushPluginFiles() {
294-
const pushPluginBundleInfo = getBundleInfo('./build/push.js');
306+
const { path, external } = buildablePlugins.push;
307+
const pushPluginBundleInfo = getBundleInfo(path, undefined, external);
295308

296309
// These are the files that are allowed to contribute >= `threshold` bytes to the Push bundle.
297310
const allowedFiles = new Set([
@@ -305,7 +318,8 @@ async function checkPushPluginFiles() {
305318
}
306319

307320
async function checkLiveObjectsPluginFiles() {
308-
const pluginBundleInfo = getBundleInfo('./build/liveobjects.js');
321+
const { path, external } = buildablePlugins.liveObjects;
322+
const pluginBundleInfo = getBundleInfo(path, undefined, external);
309323

310324
// These are the files that are allowed to contribute >= `threshold` bytes to the LiveObjects bundle.
311325
const allowedFiles = new Set([

0 commit comments

Comments
 (0)