diff --git a/lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js b/lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js index 6f51ef8ab74d..9ea392ab0b4d 100644 --- a/lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js +++ b/lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js @@ -1,4 +1,3 @@ - /** * @license Apache-2.0 * @@ -24,6 +23,7 @@ var filter = require( '@stdlib/array/base/filter' ); var trim = require( '@stdlib/string/trim' ); var map = require( '@stdlib/utils/map' ); +var reEOL = require( '@stdlib/regexp/eol' ); var collectField = require( './collect_field.js' ); var sectionStart = require( './section_start.js' ); var sectionEnd = require( './section_end.js' ); @@ -33,10 +33,51 @@ var heading = require( './heading.js' ); // VARIABLES // var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit'; +var RE_YAML_DELIMITER = /^\s*---\s*$/; // FUNCTIONS // +/** +* Processes commit message text by removing YAML blocks and squashing multiple empty lines into a single empty line. +* +* @private +* @param {Array} lines - text lines to process +* @returns {Array} processed commit message lines +*/ +function stripYamlBlocks( lines ) { + var previousLineEmpty; + var inYaml; + var out; + var i; + + previousLineEmpty = false; + inYaml = false; + out = []; + for ( i = 0; i < lines.length; i++ ) { + // Check for YAML delimiter (---) with optional whitespace: + if ( RE_YAML_DELIMITER.test( lines[ i ] ) ) { + inYaml = !inYaml; // Toggle YAML block state + continue; + } + // Only include lines that are not part of YAML blocks: + if ( inYaml ) { + continue; + } + if ( trim( lines[ i ] ) === '' ) { + // Only add an empty line if the previous line wasn't empty: + if ( !previousLineEmpty && out.length > 0 ) { + previousLineEmpty = true; + out.push( '' ); + } + } else { + previousLineEmpty = false; + out.push( lines[ i ] ); // Preserve original line formatting + } + } + return out; +} + /** * Formats a breaking change. * @@ -54,13 +95,26 @@ var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit'; * // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep' */ function formatBreakingChange( note ) { - var parts = note.text.split( '\n' ); - var hash = trim( note.hash ); - var out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ]; - if ( parts.length > 1 ) { - out +='\n\n'; - out += ' - '; - out += parts.slice( 1 ).join( '\n ' ); + var contentLines; + var textLines; + var firstLine; + var restLines; + var hash; + var out; + + textLines = note.text.split( reEOL.REGEXP ); + contentLines = stripYamlBlocks( textLines ); + + // If we have content, first element is the first line: + firstLine = contentLines[ 0 ] || ''; + restLines = contentLines.slice( 1 ); + hash = trim( note.hash ); + + // Construct output string: + out = '- [`' + hash.substring( 0, 7 ) + '`](' + STDLIB_GITHUB_URL + '/' + hash + '): ' + firstLine; + if ( restLines.length > 0 ) { + out += '\n\n'; + out += ' - ' + restLines.join( '\n ' ); out += '\n'; } return out; @@ -88,18 +142,18 @@ function isBreakingChange( note ) { * @returns {string} list of breaking changes */ function breakingChanges( commits ) { - var breakingChanges; + var changes; var notes; var out; notes = collectField( commits, 'notes' ); - breakingChanges = filter( notes, isBreakingChange ); - if ( breakingChanges.length === 0 ) { + changes = filter( notes, isBreakingChange ); + if ( changes.length === 0 ) { return ''; } out = sectionStart( 'breaking-changes' ); out += heading( 'BREAKING CHANGES', 3 ); - out += map( breakingChanges, formatBreakingChange ).join( '\n' ); + out += map( changes, formatBreakingChange ).join( '\n' ); out += sectionEnd( 'breaking-changes' ); return out; }