smoke-tarball.mjs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const here = fileURLToPath(new URL('.', import.meta.url));
  11. const cliDir = resolve(here, '..');
  12. const distPack = resolve(cliDir, '../../dist-pack');
  13. const log = (m) => process.stdout.write(`[smoke] ${m}\n`);
  14. const die = (m) => {
  15. process.stderr.write(`[smoke] FAIL: ${m}\n`);
  16. process.exit(1);
  17. };
  18. log('building + packing');
  19. execSync('pnpm pack:tarball', { cwd: cliDir, stdio: 'inherit' });
  20. const tarballs = readdirSync(distPack)
  21. .filter((f) => f.startsWith('briven-cli-') && f.endsWith('.tgz'))
  22. .sort();
  23. if (tarballs.length === 0) die(`no tarball found in ${distPack}`);
  24. const tarball = join(distPack, tarballs[tarballs.length - 1]);
  25. log(`tarball: ${tarball}`);
  26. const scratch = mkdtempSync(join(tmpdir(), 'briven-cli-smoke-'));
  27. log(`scratch: ${scratch}`);
  28. const cleanup = () => rmSync(scratch, { recursive: true, force: true });
  29. process.on('exit', cleanup);
  30. writeFileSync(join(scratch, 'package.json'), JSON.stringify({ private: true, type: 'module' }));
  31. execSync(`npm install --silent --no-audit --no-fund "${tarball}"`, { cwd: scratch, stdio: 'inherit' });
  32. log('checking briven --help');
  33. const helpOut = execSync('./node_modules/.bin/briven --help', { cwd: scratch, encoding: 'utf8' });
  34. if (!/briven/i.test(helpOut)) die(`--help output unexpected:\n${helpOut}`);
  35. log('checking briven --version');
  36. execSync('./node_modules/.bin/briven --version', { cwd: scratch, stdio: 'inherit' });
  37. log('checking briven on unknown command exits 1');
  38. let unknownExit = 0;
  39. try {
  40. execSync('./node_modules/.bin/briven definitely-not-a-command', { cwd: scratch, stdio: 'pipe' });
  41. } catch (e) {
  42. unknownExit = e.status ?? 0;
  43. }
  44. if (unknownExit !== 1) die(`unknown command exited ${unknownExit}, expected 1`);
  45. log('checking sub-exports import cleanly');
  46. writeFileSync(
  47. join(scratch, 'check.mjs'),
  48. [
  49. `import * as cli from '@briven/cli';`,
  50. `import * as schema from '@briven/cli/schema';`,
  51. `import * as server from '@briven/cli/server';`,
  52. `if (typeof cli.run !== 'function') { console.error('cli.run not exported'); process.exit(1); }`,
  53. `if (Object.keys(schema).length === 0) { console.error('schema export is empty'); process.exit(1); }`,
  54. `if (Object.keys(server).length === 0) { console.error('server export is empty'); process.exit(1); }`,
  55. `console.log('[smoke] sub-exports ok');`,
  56. ``,
  57. ].join('\n')
  58. );
  59. execSync('node check.mjs', { cwd: scratch, stdio: 'inherit' });
  60. log('PASS');