From a4cf76aca9d46f42900835274ecc812eeeab0aca Mon Sep 17 00:00:00 2001 From: n30nex Date: Wed, 9 Sep 2026 18:36:00 -0400 Subject: [PATCH] build: account explicitly for the MapLibre 6 worker cost --- scripts/check-frontend-budget.mjs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/check-frontend-budget.mjs b/scripts/check-frontend-budget.mjs index d3c48f4..8b47b40 100644 --- a/scripts/check-frontend-budget.mjs +++ b/scripts/check-frontend-budget.mjs @@ -1,9 +1,14 @@ import { gzipSync } from "node:zlib"; import { readdir, readFile } from "node:fs/promises"; -import { join } from "node:path"; +import { basename, join } from "node:path"; const root = process.argv[2] ?? "web/dist"; -const limit = Number(process.env.CARTOLITE_GZIP_BUDGET ?? 350 * 1024); +// MapLibre 6 requires a separate Vite worker (129,701 gzip bytes in Actions). +// Keep the previous cap for all other JS/CSS; account for the worker explicitly. +// Combined measured cost: 446,084 bytes. Runtime timing/route gates are unchanged. +const uiLimit = 350 * 1024; +const workerLimit = 128 * 1024; +const limit = Number(process.env.CARTOLITE_GZIP_BUDGET ?? (uiLimit + workerLimit)); async function assets(dir, pattern) { const found = []; @@ -15,15 +20,25 @@ async function assets(dir, pattern) { return found; } -const files = await assets(root, /\.(?:css|js)$/); +const files = await assets(root, /\.(?:css|m?js)$/); if (files.length === 0) throw new Error(`no JavaScript or CSS assets found in ${root}`); let total = 0; +let workerBytes = 0; +let workerCount = 0; for (const file of files) { const bytes = gzipSync(await readFile(file), { level: 9 }).byteLength; total += bytes; + if (/^maplibre-gl-worker-.*\.m?js$/.test(basename(file))) { + workerBytes += bytes; + workerCount += 1; + } console.log(`${bytes.toString().padStart(8)} ${file}`); } console.log(`${total} gzip bytes total (budget ${limit})`); -if (total > limit) process.exitCode = 1; +console.log(`${total - workerBytes} gzip bytes excluding map worker (budget ${uiLimit})`); +console.log(`${workerBytes} gzip bytes for map worker (budget ${workerLimit})`); +if (workerCount !== 1) throw new Error(`expected one map worker, found ${workerCount}`); +if (!Number.isFinite(limit) || limit <= 0) throw new Error('invalid total frontend budget'); +if (total > limit || total - workerBytes > uiLimit || workerBytes > workerLimit) process.exitCode = 1;