UNPKG

apisurf

Version:

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

59 lines (58 loc) 2.76 kB
/** * Formats the diff result as clean markdown output without console formatting. */ export function formatMarkdownOutput(result, verbose = false) { let output = '## API Surface Analysis\n\n'; // Add package and version information if available if (result.npmPackage && result.fromVersion && result.toVersion) { output += `Analyzing ${result.npmPackage} api surface changes: ${result.fromVersion} to ${result.toVersion}\n\n`; } // Summary if (!result.hasBreakingChanges && result.packages.length === 0) { output += '✅ No changes detected\n\n'; } else if (result.hasBreakingChanges) { output += '❌ Breaking changes detected\n\n'; } else { output += '✅ No breaking changes detected\n\n'; } // Semver impact output += `**Semver impact:** ${result.semverImpact.minimumBump} (${result.semverImpact.reason})\n\n`; // Package changes for (const pkg of result.packages) { if (pkg.breakingChanges.length > 0 || pkg.nonBreakingChanges.length > 0) { output += `### ${pkg.name}\n\n`; // Breaking changes if (pkg.breakingChanges.length > 0) { output += '#### Breaking Changes\n\n'; for (const change of pkg.breakingChanges) { // Remove chalk formatting and convert bold to markdown let cleanDescription = change.description.replace(/\x1b\[[0-9;]*m/g, ''); // Convert quoted items to markdown bold cleanDescription = cleanDescription.replace(/'([^']+)'/g, '**$1**'); output += `- ${cleanDescription}\n`; // Add Before/After sub-bullets for signature changes (only in verbose mode) if (verbose && change.after && change.before) { output += ` - Before: \`${change.before}\`\n`; output += ` - After: \`${change.after}\`\n`; } } output += '\n'; } // Non-breaking changes if (pkg.nonBreakingChanges.length > 0) { output += '#### Non-Breaking Changes\n\n'; for (const change of pkg.nonBreakingChanges) { // Remove chalk formatting and convert bold to markdown let cleanDescription = change.description.replace(/\x1b\[[0-9;]*m/g, ''); // Convert quoted items to markdown bold cleanDescription = cleanDescription.replace(/'([^']+)'/g, '**$1**'); output += `- ${cleanDescription}\n`; } output += '\n'; } } } return output.trim(); }