Skip to content

[Version] Using a custom tagVersionPrefix with conventionalCommits, lerna version incorrectly computes root CHANGELOG. #2197

@darkobits

Description

@darkobits

Expected Behavior

When running lerna version using the conventionalCommits option/flag, Lerna should produce accurate root and package-level change logs.

Current Behavior

Lerna produces accurate package-level change logs, but the root-level change log contains a very verbose change set spanning several releases.

Possible Solution

When generating root-level changelogs, this code path is taken in update-changelog.js. Notice that in the else branch on L44 for non-root packages, tagPrefix is being assigned to options, but this does not happen on the root-level code path. I believe this is sufficient to explain why package-level change logs are produced correctly, but root-level change logs are not.

I have tested this flow locally by adding the following line just below L34 in update-changelog.js, and it resulted in root-level change logs that were accurate:

options.tagPrefix = tagPrefix;

However, I am not aware of the context around why this wasn't being set in the first place, and as such, this solution may have other undesired effects for other use cases that I'm not aware of.

Steps to Reproduce (for bugs)

  1. Set the same tagVersionPrefix option for the version and publish commands in lerna.json or use the same --tag-version-prefix flag when executing lerna version and lerna publish below.
  2. With 1 or more commits representing changes to at least 1 package, run lerna version.
lerna.json

{
  "version": "1.2.3",
  "packages": [
    "packages/*"
  ],
  "command": {
    "bootstrap": {
      "ci": false,
      "hoist": true
    },
    "version": {
      "message": "chore(release): %v",
      "conventionalCommits": true,
      "gitTagVersion": true,
      "push": false,
      "tagVersionPrefix": "foo/v"
    },
    "publish": {
      "verifyAccess": false,
      "gitTagVersion": false,
      "push": false,
      "tagVersionPrefix": "foo/v"
    }
  }
}

Context

When using lerna version with a custom tagVersionPrefix and conventionalCommits, it is necessary to manually remove all extraneous information from the root-level change log that Lerna produces.

Your Environment

Executable Version
lerna --version 3.16.3
npm --version 6.10.1
node --version 10.16.0
OS Version
NAME VERSION
macOS Sierra 10.14.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions