mirror of
https://github.com/n30nex/CartoLite-Server.git
synced 2026-10-23 23:44:41 +00:00
build: account explicitly for the MapLibre 6 worker cost
This commit is contained in:
1 parent
39eaba5b2e
commit
a4cf76aca9
1 file changed
+19
-4
@@ -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;
|
||||
Reference in new issue
Block a user