Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

query.mjs

45 lines1.2 KB

1#!/usr/bin/env node
2​
3import fs from 'node:fs'
4import path from 'node:path'
5import { parseArgs } from 'node:util'
6​
7const { values } = parseArgs({
8 allowPositionals: false,
9 options: {
10 current: {
11 type: 'string',
12 default: 'benchmarks/bundle-size/results/current.json',
13 },
14 id: { type: 'string' },
15 json: { type: 'boolean' },
16 },
17})
18​
19const currentPath = path.resolve(values.current)
20const current = JSON.parse(fs.readFileSync(currentPath, 'utf8'))
21const metrics = values.id
22 ? (current.metrics || []).filter((metric) => metric.id === values.id)
23 : current.metrics || []
24​
25if (values.id && metrics.length === 0) {
26 throw new Error(`Unknown bundle-size metric: ${values.id}`)
28​
29if (values.json) {
30 process.stdout.write(JSON.stringify(metrics, null, 2) + '\n')
31} else {
32 for (const metric of metrics) {
33 process.stdout.write(
34 [
35 metric.id,
36 `gzip=${metric.gzipBytes}`,
37 `initial=${metric.initialGzipBytes}`,
38 `raw=${metric.rawBytes}`,
39 `brotli=${metric.brotliBytes}`,
40 `dist=${metric.outDir || metric.scenarioDir}`,
41 `files=${(metric.jsFiles || []).join(',')}`,
42 ].join(' ') + '\n',
43 )
44 }