UNPKG

apisurf

Version:

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

58 lines (57 loc) • 2.25 kB
/** * Formats validation results into the specified output format. */ export function formatValidationOutput(result, format) { switch (format) { case 'json': return JSON.stringify(result, null, 2); case 'md': return formatValidationMarkdown(result); case 'html': return formatValidationHtml(result); case 'console': default: return formatValidationConsole(result); } } function formatValidationConsole(result) { if (!result.hasViolations) { return 'āœ… No semver violations detected in dependencies'; } let output = 'āŒ Semver violations detected:\n\n'; for (const violation of result.violations) { output += `šŸ“¦ ${violation.packageName}: ${violation.oldVersion} → ${violation.newVersion}\n`; output += ` Type: ${violation.violationType}\n`; if (violation.breakingChanges.length > 0) { output += ' Breaking changes:\n'; for (const change of violation.breakingChanges) { output += ` • ${change}\n`; } } output += '\n'; } return output; } function formatValidationMarkdown(result) { if (!result.hasViolations) { return '## Dependency Validation\n\nāœ… No semver violations detected in dependencies'; } let output = '## Dependency Validation\n\nāŒ Semver violations detected:\n\n'; for (const violation of result.violations) { output += `### ${violation.packageName}: ${violation.oldVersion} → ${violation.newVersion}\n\n`; output += `**Violation Type:** ${violation.violationType}\n\n`; if (violation.breakingChanges.length > 0) { output += '**Breaking changes:**\n'; for (const change of violation.breakingChanges) { output += `- ${change}\n`; } output += '\n'; } } return output; } function formatValidationHtml(_result) { // For now, return a simple message. This could be enhanced to generate a full HTML report // similar to formatHtmlOutput in the diff command return 'HTML validation reports are not yet implemented. Use console, json, or md format instead.'; }