mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
Add a spec that maps every component imported from perfect-design, and every directory it imports in turn, to an @source entry in main.css. Extend the bundle gate spec to check that utilities unique to recently added components appear in the built CSS.
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
// Gate scope: gzip (level 9) of every .js and .css in dist/assets, lazy chunks included.
|
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { gzipSync } from 'node:zlib'
|
|
|
|
export const LIMIT = 324300
|
|
export const DIST = fileURLToPath(new URL('../dist/assets', import.meta.url))
|
|
|
|
export const hasDist = () => existsSync(DIST)
|
|
|
|
export function readCss(dir = DIST) {
|
|
return readdirSync(dir)
|
|
.filter((f) => f.endsWith('.css'))
|
|
.map((f) => readFileSync(join(dir, f), 'utf8'))
|
|
.join('\n')
|
|
}
|
|
|
|
export function totalGzip(dir = DIST) {
|
|
return measure(dir).reduce((n, r) => n + r.gzip, 0)
|
|
}
|
|
|
|
export function measure(dir = DIST) {
|
|
return readdirSync(dir)
|
|
.filter((f) => /\.(js|css)$/.test(f))
|
|
.map((f) => ({ file: f, gzip: gzipSync(readFileSync(join(dir, f)), { level: 9 }).length }))
|
|
.sort((a, b) => b.gzip - a.gzip)
|
|
}
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
const rows = measure()
|
|
const total = totalGzip()
|
|
for (const r of rows.slice(0, 10)) console.log(`${String(r.gzip).padStart(8)} ${r.file}`)
|
|
console.log(`total gzip JS+CSS: ${total} B (limit ${LIMIT}); ${rows.length} files`)
|
|
if (total > LIMIT) {
|
|
console.error('bundle gate FAILED')
|
|
process.exit(1)
|
|
}
|
|
}
|