fix(cli): compress the embedded web UI at brotli's best quality (#53644)

This commit is contained in:
Luke Parker
2026-10-07 11:35:20 +10:00
committed by GitHub
Unverified
parent 8b45c5674b
commit a7f3d570ae
+7 -4
View File
@@ -1,6 +1,7 @@
import { $ } from "bun"
import path from "node:path"
import { brotliCompressSync, constants } from "node:zlib"
import { promisify } from "node:util"
import { brotliCompress, constants } from "node:zlib"
import { AppArchive } from "../src/app-archive"
import { collectFiles } from "./files"
@@ -19,14 +20,16 @@ export async function buildAppArchive(channel: string, options?: { skipBuild?: b
.map(async (key) => {
const body = Buffer.from(await Bun.file(path.join(root, "dist", key)).arrayBuffer())
// Independent entries let the server materialize only assets the browser requests.
return [key, compress(body)] as const
return [key, await compress(body)] as const
}),
),
)
}
// The assets compress once per release, so they take brotli's best quality: about 11% smaller than quality 6 for the
// web UI. Each runs on the thread pool, which keeps the build to about a minute.
function compress(body: Buffer) {
return brotliCompressSync(body, {
params: { [constants.BROTLI_PARAM_QUALITY]: 6 },
return promisify(brotliCompress)(body, {
params: { [constants.BROTLI_PARAM_QUALITY]: 11, [constants.BROTLI_PARAM_SIZE_HINT]: body.length },
})
}