All files / scripts/package-release/commands detect-bumps.js

0% Statements 0/24
0% Branches 0/10
0% Functions 0/3
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                                                             
import { detectBumps, bumpsToTagList } from '../lib/bumps.js';
import { error } from '../lib/log.js';
 
const VALID_FORMATS = ['tag-list', 'json', 'human'];
 
export function registerDetectBumpsCommand(program) {
  program
    .command('detect-bumps')
    .description('List packages whose version changed between two refs (machine-friendly)')
    .option('--since <ref>', 'Base ref to compare against', 'HEAD~1')
    .option('--to <ref>', 'Target ref (default: HEAD; versions are read from the working tree)', 'HEAD')
    .option(
      '--format <format>',
      `Output format: ${VALID_FORMATS.join(' | ')}. Use tag-list for piping to tag/github.`,
      'human',
    )
    .action(async (opts) => {
      try {
        await runDetectBumps(opts);
      } catch (e) {
        error(e.message);
        process.exit(1);
      }
    });
}
 
async function runDetectBumps(opts) {
  if (!VALID_FORMATS.includes(opts.format)) {
    error(`Invalid --format "${opts.format}". Valid: ${VALID_FORMATS.join(', ')}`);
    process.exit(1);
  }
 
  const bumps = detectBumps(opts.since, opts.to);
 
  if (opts.format === 'json') {
    process.stdout.write(JSON.stringify(bumps, null, 2) + '\n');
    return;
  }
 
  if (opts.format === 'tag-list') {
    if (bumps.length === 0) return;
    process.stdout.write(bumpsToTagList(bumps) + '\n');
    return;
  }
 
  if (bumps.length === 0) {
    process.stdout.write(`No package version changes between ${opts.since} and ${opts.to}.\n`);
    return;
  }
  process.stdout.write(`Detected bumps (${opts.since}...${opts.to}):\n`);
  for (const b of bumps) {
    process.stdout.write(`  ${b.name}: ${b.from} -> ${b.to}\n`);
  }
}