UNPKG

apisurf

Version:

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

28 lines (27 loc) 933 B
import { getVersionBumpType } from './getVersionBumpType.js'; /** * Detects if there's a semver violation between the required bump and actual bump */ export function detectSemverViolation(fromVersion, toVersion, requiredBump) { const actualBump = getVersionBumpType(fromVersion, toVersion); // No violation if the actual bump type is unknown or prerelease if (actualBump === 'unknown' || actualBump === 'prerelease') { return { hasViolation: false }; } // Check for violations if (requiredBump === 'major' && (actualBump === 'minor' || actualBump === 'patch')) { return { hasViolation: true, actualBump, requiredBump }; } else if (requiredBump === 'minor' && actualBump === 'patch') { return { hasViolation: true, actualBump, requiredBump }; } return { hasViolation: false }; }