// Explicit generation only: authenticated Git acquisition must never run package scripts. import { execFileSync } from 'node:child_process' import { mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' const root = dirname(dirname(fileURLToPath(import.meta.url))) const check = process.argv.includes('--check') const output = check ? mkdtempSync(join(tmpdir(), 'agent-contracts-build-')) : join(root, 'package') try { mkdirSync(output, { recursive: true }) execFileSync(process.execPath, [join(root, 'node_modules/typescript/bin/tsc'), '-p', join(root, 'tsconfig.package.json'), '--outDir', output], { cwd: root, stdio: 'inherit' }) for (const extension of ['js', 'd.ts']) renameSync(join(output, `types.${extension}`), join(output, `index.${extension}`)) if (check) { for (const file of ['index.js', 'index.d.ts']) { if (!readFileSync(join(root, 'package', file)).equals(readFileSync(join(output, file)))) { throw new Error(`package/${file} is stale; run npm run build before committing the provider`) } } } } finally { if (check) rmSync(output, { recursive: true, force: true }) }