/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
internal/scripts/check-worker-bundle.ts
65 строк
2 KB
Mitja Bezenšek
chore: share the worker esbuild externals list between dev and CI scripts (#9557)
10 июл 2026, 13:51
Не верифицирован
10 июл 2026, 13:51
3f9cb5e
Код
Авторство
О чём код?
import { existsSync, readFileSync, rmSync } from 'fs' import { resolve } from 'path' import kleur from 'kleur' import minimist from 'minimist' import { exec } from './lib/exec' import { WORKER_EXTERNAL_DEPS } from './lib/worker-externals' const args = minimist(process.argv.slice(2)) const sizeLimit = Number(args['size-limit-bytes']) if (!isFinite(sizeLimit) || sizeLimit < 1) { console.error( 'Invalid usage. Usage: yarn tsx check-worker-bundle.ts --size-limit-bytes <size> --entry <entry>' ) process.exit(1) } const entry = args['entry'] if (!existsSync(entry)) { console.error('Entry file does not exist:', entry) process.exit(1) } const bundleMetaFileName = '.bundle-meta.json' interface Meta { outputs: { [fileName: string]: { bytes: number } } } async function checkBundleSize() { rmSync(bundleMetaFileName, { force: true }) console.log('checking bundle size') await exec('yarn', [ 'esbuild', entry, '--bundle', '--outfile=/dev/null', '--minify', '--metafile=' + bundleMetaFileName, ...WORKER_EXTERNAL_DEPS.map((dep) => '--external:' + dep), ]) console.log(kleur.cyan().bold('Checking bundle size'), 'of', resolve(entry) + '\n') const meta = JSON.parse(readFileSync(bundleMetaFileName).toString()) as Meta const totalSize = Object.values(meta.outputs).reduce((acc, output) => acc + output.bytes, 0) if (totalSize === 0) { throw new Error('Invalid bundle meta in ' + process.cwd() + '/' + bundleMetaFileName) } if (totalSize > sizeLimit) { console.error( `${kleur.red().bold('ERROR')} Bundle size exceeds limit: ${totalSize} > ${sizeLimit}` ) process.exit(1) } console.log(`Bundle size is within limit: ${totalSize} < ${sizeLimit}`) } checkBundleSize()