snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
43
packages/lit-query/scripts/measure-bundle.mjs
Normal file
43
packages/lit-query/scripts/measure-bundle.mjs
Normal file
@@ -0,0 +1,43 @@
|
||||
import { readFile, readdir, stat } from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import { gzipSync } from 'node:zlib'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
const repoRoot = path.resolve(scriptDir, '..')
|
||||
const distDir = path.join(repoRoot, 'build', 'modern')
|
||||
const entryFile = path.join(distDir, 'index.js')
|
||||
|
||||
async function getDirSizeBytes(dirPath) {
|
||||
let total = 0
|
||||
const entries = await readdir(dirPath, { withFileTypes: true })
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dirPath, entry.name)
|
||||
if (entry.isDirectory()) {
|
||||
total += await getDirSizeBytes(fullPath)
|
||||
} else if (entry.isFile()) {
|
||||
total += (await stat(fullPath)).size
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const entry = await readFile(entryFile)
|
||||
const entryGzip = gzipSync(entry)
|
||||
const distBytes = await getDirSizeBytes(distDir)
|
||||
|
||||
const output = {
|
||||
measuredAt: new Date().toISOString(),
|
||||
entryJsBytes: entry.length,
|
||||
entryJsGzipBytes: entryGzip.length,
|
||||
distTotalBytes: distBytes,
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(output, null, 2))
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user