import { readFileSync } from 'node:fs' import { spawnSync } from 'node:child_process' const run = spawnSync('npx', ['knip', '--reporter', 'json', '--include', 'exports,nsExports,types,nsTypes'], { encoding: 'utf8', }) if (!run.stdout) { process.stderr.write(run.stderr || 'knip produced no output\n') process.exit(1) } const data = JSON.parse(run.stdout) let count = 0 for (const issue of data.issues ?? []) { for (const key of ['exports', 'types', 'nsExports', 'nsTypes']) { count += (issue[key] ?? []).length } } const limit = JSON.parse(readFileSync(new URL('../knip-baseline.json', import.meta.url))).exports if (count > limit) { console.error(`knip unused exports ${count} exceed baseline ${limit}`) process.exit(1) } console.log(`knip unused exports ${count} <= ${limit}`)