UNPKG

apisurf

Version:

Analyze API surface changes between npm package versions to catch breaking changes

42 lines (41 loc) 1.98 kB
import { analyzeNpmPackageVersions } from './analyzeNpmPackageVersions.js'; import { compareApiSurfaces } from './compareApiSurfaces.js'; import { calculateSemverImpact } from '../utilities/calculateSemverImpact.js'; import { writeApiSurfaceLog } from '../utilities/writeApiSurfaceLog.js'; /** * Analyzes differences between two versions of an NPM package. * Downloads specified versions and compares their API surfaces. */ export async function analyzeNpmPackageDiff(options) { if (!options.npmPackage || !options.fromVersion || !options.toVersion) { throw new Error('NPM mode requires --npm-package, --from-version, and --to-version options'); } const { base, head } = await analyzeNpmPackageVersions({ packageName: options.npmPackage, fromVersion: options.fromVersion, toVersion: options.toVersion, registry: options.registry, verbose: options.verbose, format: options.format }); // Log API surfaces if logfile is specified if (options.logfile) { await writeApiSurfaceLog(options.logfile, base, head, options.npmPackage, options.fromVersion, options.toVersion, options.format); } const pkg = { name: options.npmPackage, path: `npm:${options.npmPackage}` }; const diff = compareApiSurfaces(base, head, pkg); const hasBreakingChanges = diff.breakingChanges.length > 0; const semverImpact = calculateSemverImpact([diff]); return { hasBreakingChanges, packages: [diff], summary: hasBreakingChanges ? `Breaking changes detected between ${options.fromVersion} and ${options.toVersion}. Minimum semver bump: ${semverImpact.minimumBump}` : `No breaking changes detected between ${options.fromVersion} and ${options.toVersion}`, semverImpact, npmPackage: options.npmPackage, fromVersion: options.fromVersion, toVersion: options.toVersion, repositoryUrl: head.repositoryUrl }; }