smoke-tarball.mjs72 lines · main
| 1 | #!/usr/bin/env node |
| 2 | // Builds, packs, and consumes the resulting tarball from a clean scratch dir. |
| 3 | // Catches the class of bug where source-tree dev works (tsx fallback in |
| 4 | // bin/briven.js) but a real install is broken — exact case that motivated this. |
| 5 | import { execSync } from 'node:child_process'; |
| 6 | import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; |
| 7 | import { tmpdir } from 'node:os'; |
| 8 | import { join, resolve } from 'node:path'; |
| 9 | import { fileURLToPath } from 'node:url'; |
| 10 | |
| 11 | const here = fileURLToPath(new URL('.', import.meta.url)); |
| 12 | const cliDir = resolve(here, '..'); |
| 13 | const distPack = resolve(cliDir, '../../dist-pack'); |
| 14 | |
| 15 | const log = (m) => process.stdout.write(`[smoke] ${m}\n`); |
| 16 | const die = (m) => { |
| 17 | process.stderr.write(`[smoke] FAIL: ${m}\n`); |
| 18 | process.exit(1); |
| 19 | }; |
| 20 | |
| 21 | log('building + packing'); |
| 22 | execSync('pnpm pack:tarball', { cwd: cliDir, stdio: 'inherit' }); |
| 23 | |
| 24 | const tarballs = readdirSync(distPack) |
| 25 | .filter((f) => f.startsWith('briven-cli-') && f.endsWith('.tgz')) |
| 26 | .sort(); |
| 27 | if (tarballs.length === 0) die(`no tarball found in ${distPack}`); |
| 28 | const tarball = join(distPack, tarballs[tarballs.length - 1]); |
| 29 | log(`tarball: ${tarball}`); |
| 30 | |
| 31 | const scratch = mkdtempSync(join(tmpdir(), 'briven-cli-smoke-')); |
| 32 | log(`scratch: ${scratch}`); |
| 33 | |
| 34 | const cleanup = () => rmSync(scratch, { recursive: true, force: true }); |
| 35 | process.on('exit', cleanup); |
| 36 | |
| 37 | writeFileSync(join(scratch, 'package.json'), JSON.stringify({ private: true, type: 'module' })); |
| 38 | execSync(`npm install --silent --no-audit --no-fund "${tarball}"`, { cwd: scratch, stdio: 'inherit' }); |
| 39 | |
| 40 | log('checking briven --help'); |
| 41 | const helpOut = execSync('./node_modules/.bin/briven --help', { cwd: scratch, encoding: 'utf8' }); |
| 42 | if (!/briven/i.test(helpOut)) die(`--help output unexpected:\n${helpOut}`); |
| 43 | |
| 44 | log('checking briven --version'); |
| 45 | execSync('./node_modules/.bin/briven --version', { cwd: scratch, stdio: 'inherit' }); |
| 46 | |
| 47 | log('checking briven on unknown command exits 1'); |
| 48 | let unknownExit = 0; |
| 49 | try { |
| 50 | execSync('./node_modules/.bin/briven definitely-not-a-command', { cwd: scratch, stdio: 'pipe' }); |
| 51 | } catch (e) { |
| 52 | unknownExit = e.status ?? 0; |
| 53 | } |
| 54 | if (unknownExit !== 1) die(`unknown command exited ${unknownExit}, expected 1`); |
| 55 | |
| 56 | log('checking sub-exports import cleanly'); |
| 57 | writeFileSync( |
| 58 | join(scratch, 'check.mjs'), |
| 59 | [ |
| 60 | `import * as cli from '@briven/cli';`, |
| 61 | `import * as schema from '@briven/cli/schema';`, |
| 62 | `import * as server from '@briven/cli/server';`, |
| 63 | `if (typeof cli.run !== 'function') { console.error('cli.run not exported'); process.exit(1); }`, |
| 64 | `if (Object.keys(schema).length === 0) { console.error('schema export is empty'); process.exit(1); }`, |
| 65 | `if (Object.keys(server).length === 0) { console.error('server export is empty'); process.exit(1); }`, |
| 66 | `console.log('[smoke] sub-exports ok');`, |
| 67 | ``, |
| 68 | ].join('\n') |
| 69 | ); |
| 70 | execSync('node check.mjs', { cwd: scratch, stdio: 'inherit' }); |
| 71 | |
| 72 | log('PASS'); |