Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→lerna-clean-changelogsnext

lerna-clean-changelogs5.2.5

Removes frivolous entries from commitizen generated changelogs

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • SECTION CLEAN…
  • LIST MARKERS…
  • LITERAL CODE
  • VERSION-HEADI…
  • API — CLEANCHANGEL…
  • LINE ENDINGS
  • EMPTY RESULTS
  • API — DEFAULTS
  • API — VERSION
  • ALGORITHM
  • Changelog

No 3rd party dependencies. All dependencies and devDependencies, checked recursively, are Codsen packages.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Empty cleaned text is a valid result; retain an existing EOF newline.
  • Fix SourceHut commit links
  • Keep literal examples while removing unfinished changelog entries.
  • Clean CR-only documents while retaining their line-ending style.
  • Preserve CRLF line endings
  • Retain a release heading while published changes remain beneath it.
  • Normalize list markers while keeping the separator between the lists.
  • Remove WIP entries and tidy the headings
  • Keep the full version and date while removing its complete Markdown link.

Purpose

This program removes the frivolous changelog file entries generated by commitizenopens in a new tab:

cleaning
cleaning

It is used in a Lerna monorepos environment.

Section cleanup

When removing entries makes a section empty, the cleaner removes its heading and any parent section that also becomes empty. Release and category headings stay when they still contain text or retained child headings. Empty headings in unaffected sections and the initial H1 document heading are preserved.

Generated changelogs can mix H1 and H2 version headings. Each new release starts a separate section for cleanup, while ordinary headings retain their nesting levels.

With extras: true, the cleaner removes lines containing the substring WIP, case-insensitively. This includes words such as swipe, wipe, and swiper, and matching text in URLs. Removal applies to individual lines; continuation paragraphs and nested bullets remain unless their own lines match WIP. A heading containing WIP is kept when retained content still belongs beneath it.

List markers and separators

Ordinary list lines beginning with * become - lines. Valid asterisk thematic breaksopens in a new tab, such as * * * or ***, keep their spelling and continue to separate neighboring lists. They contain at least three asterisks, with only ASCII spaces or tabs between or after them, and at most three leading spaces. List-marker normalization does not extend to indented or tab-prefixed markers.

Literal code

Fenced and indented code blocks bypass cleanup, including blocks inside lists and blockquotes. Their headings, WIP text, bump notes, asterisk bullets, SourceHut URLs, indentation and internal blank lines remain literal. Entries outside those blocks still receive cleanup with the selected options.

Backtick and tilde fences follow their opening marker and length. An unclosed fence protects the remaining text in its container, including trailing blank lines. Indented code preserves internal blank lines and nonblank trailing spaces; blank lines after that code use the ordinary document cleanup.

The cleaner uses the document’s selected line-ending style, including within literal blocks. Inline code remains subject to ordinary cleanup.

Version-heading links

With extras: true, the cleaner unwraps a version link at the start of an ATX heading’s text. It accepts one to six hash characters, up to three leading spaces, and spaces or tabs before the link. Unwrapping preserves the heading prefix, complete version label, dates and text after the link.

Labels use raw SemVer 2.0.0opens in a new tab syntax, including prerelease and build metadata such as 2.0.0-rc.1+build.007. Versions remain text; large numeric components are not converted to JavaScript numbers. Leading v, escaped or entity-encoded labels, and invalid version forms remain linked.

Markdown link destinationsopens in a new tab can contain balanced or escaped parentheses, use angle brackets, and have an optional title. The cleaner removes the complete valid link syntax. It leaves malformed links, reference links and later links in the heading alone; other cleanup rules can still apply to their text.

Version-link unwrapping excludes literal code and recognized HTML blocks. The existing body-H1 conversion and other cleanup rules keep their own behavior, including within HTML text.

API — cleanChangelogs()

The main function cleanChangelogs() is imported like this:

It’s a function which takes two input arguments:

The optional options object has the following shape:

KeyTypeObligatoryDefaultDescription
extras
Type: Boolean
Obligatory: no
Default: false
extrasBooleannofalseUnwraps leading version links in headings, turns body H1 headings into H2, and removes lines matching the WIP substring rule above.

Here are all defaults in one place for copying:

Function returns a plain object with the following keys:

Key’s nameTypeDescription
res
Type: String
resStringThe string you gave in the input, just cleaned.
version
Type: String
versionStringVersion as present currently in package.json. For example, 1.0.0

for example,

{
  res: "some text",
  version: "1.3.56",
}

Line endings

LF (\n), CRLF (\r\n) and CR (\r) all separate logical lines for cleanup. Single-style documents retain that style. For mixed input, any CRLF selects CRLF output; otherwise any LF selects LF, followed by CR. All retained line boundaries use the selected style, including those inside literal code blocks.

The cleaner preserves whether nonblank input ends with a newline. Ordinary trailing blank lines collapse to that one existing newline; trailing payload blanks in an unclosed fence remain protected. Empty and whitespace-only inputs are returned byte-for-byte unchanged, including mixed line endings.

Empty results

An empty string is a valid cleaned result. Removing all content returns "" when the input has no final newline, or one newline in the detected style when it does. Empty and whitespace-only inputs are returned unchanged.

const input = "## 1.0.0\n\n**Note:** Version bump only for package example";
cleanChangelogs(input).res; // ""
cleanChangelogs(`${input}\n`).res; // "\n"

Callers decide whether to write an empty result. The companion CLI preserves the original file when the result has zero length and reports it as skipped.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

Algorithm

The cleaner retains lines in reverse traversal order and reverses the collected array once before joining it. This makes line assembly linear in the number of retained lines, avoiding repeated shifts of a growing array. It preserves the original line order and the cleanup rules below.

Outside literal code blocks, this package performs the following cleaning steps:

  1. It removes bump-only changelog entries that conventional-changelog generates. For example:

    **Note:** Version bump only for package ranges-apply
    

    The matching lines are deleted. Their headings are removed only when the affected sections become empty; retained changes keep their release and category headings.

  2. If opts.extras enabled — removes diff links from headings. Change the following:

    ## [2.9.1](/os/ranges-apply/compare/ranges-apply@2.9.0...ranges-apply@2.9.1) (2018-12-27)
    

    into:

    ## 2.9.1 (2018-12-27)
    

    We need to do that because those links don’t work on BitBucket and, generally, are a noise.

  3. If opts.extras enabled — removes h1 headings and turns them into h2, with the exception of the first, main heading of the changelog.

    For example, change the following:

    # [2.0.0](/os/ranges-apply/compare/ranges-apply@2.0.0...ranges-apply@1.9.1) (2018-12-27)
    

    into:

    ## 2.0.0 (2018-12-27)
    

    (notice how a second hash character added, beside link being removed)

  4. Replaces two or more empty lines into one line. conventional-changelog itself leaves excessive whitespace which prettier might change later, causing annoying changes in git.

  5. Converts any unordered lists that use asterisks (*) into dashes (-), to match prettier. Here’s proofopens in a new tab.

  6. On Sourcehut, links are generated with plural, /commits/, for example: https://git.sr.ht/~user/project/commits/abcdef which lead to 404. This program replaces /commits/ with /commit/ if it detects a matching git.sr.ht/-domain URL.

Permalink to changelogChangelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab