Lerna problem using conventional commits with an existing project

975 Views Asked by At

I've been manually managing my package versions and changelog.md file up to the 5.2.0. Now I'm trying to integrate Lerna to manage my package but facing an issue while doing that.

Issue: lerna version --conventional-commits, Lerna is treating it as a first-time version update. As a result, it's including all the commit messages in the changelog as breaking changes and bug fixes, even though I have already maintained a manual changelog.md file up to the version 5.2.0 with all the commit messages already present there.

How can I use Lerna in a way that it will not generate the old commit messages as breaking changes and instead expect Lerna to update version as a patch version only 5.2.0 -> 5.2.1 and expect it to only generate commit message after 5.2.0 only. In my case commit message is

fix(styles): Automating the versioning using lerna.
Files present in commit messages are
 package.json, package-lock.json, lerna.json,  

Any assistance in achieving this would be greatly appreciated. Thank you

1

There are 1 best solutions below

0
On

It's a known problem and was also mentioned in the lerna version docs, however in the new Lerna these commands docs are hidden away (you can open the command docs from their website) or if you use Lerna-Lite then all docs are available from the main page.

In the case of your problem, this is the part of the docs that you need, lerna version Tips - conventional-changelog

Generating Initial Changelogs If you start using the --conventional-commits option after the monorepo has been active for awhile, you can still generate changelogs for previous releases using conventional-changelog-cli and lerna exec:

# Lerna does not actually use conventional-changelog-cli, so you need to install it temporarily
npm i -D conventional-changelog-cli
# Documentation: `npx conventional-changelog --help`

# fixed versioning (default)
# run in root, then leaves
npx conventional-changelog --preset angular --release-count 0 --outfile ./CHANGELOG.md --verbose
npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset angular --release-count 0 --commit-path $PWD --pkg $PWD/package.json --outfile $PWD/CHANGELOG.md --verbose'

# independent versioning
# (no root changelog)
npx lerna exec --concurrency 1 --stream -- 'conventional-changelog --preset angular --release-count 0 --commit-path $PWD --pkg $PWD/package.json --outfile $PWD/CHANGELOG.md --verbose --lerna-package $LERNA_PACKAGE_NAME'