lerna: Bug: Conventional commits do not respect '!' or "BREAKING CHANGE"

Lerna conventional commits do not respect ‘!’ as denoting a breaking change when part of the ‘types’ on a conventional commit. Additionally, It seems like including the ‘!’ may make lerna not recognize that commit as a valid conventional commit in some cases. This repo also highlights this problem.

EDIT: Looks like “BREAKING CHANGE:” is also not being respected.

Repro repo: https://github.com/alexforsyth/lerna-conventional-commits

Expected Behavior

The generated changelog should list breaking changes, when a ‘!’ is included on a type.

ex. 2 from conventional commits

refactor!: drop support for Node 6

Should be equal to using the BREAKING CHANGE: phrase in the footer.

Current Behavior

The generated changelog does not include the change when ‘!’ is included on a type.

ex.

refactor!: drop support for Node 6

Possible Solution

Steps to Reproduce (for bugs)

This repo is a live example that highlights this problem.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 17
  • Comments: 20 (4 by maintainers)

Most upvoted comments

@richardkazuomiller your comment really help me. I was trying to get a major bump with a commit on a shared folder for all packages. As soon I did a silly change with a commit inside a package it recognized as a major change.

Commit: git commit -a -m 'feat!: Dummy breaking change' Command: lerna version --no-push --conventional-commits --changelog-preset conventionalcommits --no-changelog

(We do not want the Angular preset, to be able to use the conventionalcommits preset you need to install the conventional-changelog-conventionalcommits package)

This has been the ONLY way I have been able to get a Major bump. I have been struggling with this for hours.

If your package is in major version zero (eg. v0.x.y), the semver rules are shifted over, so breaking changes happen in v0.x.0, and features & patches happen in v0.0.y.

Therefore, a breaking change in a package that is in 0.x.y, will only bump x.

I wish this was better documented, but it’s in the npm docs:

^1.2.3 := >=1.2.3 <2.0.0 ^0.2.3 := >=0.2.3 <0.3.0 ^0.0.3 := >=0.0.3 <0.0.4


Requested for improved documentation around this here.

I tried a few things and finally got the major version bump 😂.

Doing an empty commit (git commit --allow-empty ...) like this looks like it should work when not using independent mode, but doesn’t:

feat(my-package): aaa

BREAKING CHANGE: bbb

Putting BREAKING CHANGE in a merge commit, somehow is recognized by conventional commits, shown by the fact that it shows up in the changelog, however it also doesn’t bump the version.

What finally worked is we reworded a recent commit to a file inside one of the packages to include BREAKING CHANGE in the description of the commit. For people like me who prefer to think in terms of PRs rather than individual commits, this might be an easy place to get stuck. If anyone else has this problem, try rewording a commit (not a merge commit) that changes a file inside one of the packages. package.json should always work, but probably any file included in the package should also work.

This can also be specified in lerna.json: https://github.com/lerna/lerna/tree/master/commands/version#--create-release-type

i.e.

{
  "changelogPreset": {
    "name": "conventionalcommits",
    "issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
  }
}

The default settings uses conventional-changelog-angular which is not the conventional commits spec, and doesn’t support !.

It will work if you add --changelog-preset conventionalcommits, see https://github.com/lerna/lerna/issues/2138

Also in your repro, you’re explicitly specifying the bump as minor, which overrides using conventional commits to determine the desired bump - maybe that’s what you want, though.

https://github.com/alexforsyth/lerna-conventional-commits/blob/b575a9278be8ea053a8e1617014fe9be679d1272/package.json#L12

I read it differently, as it says or appends a ! after the type/scope so I would expect the ! be enough. But I agree adding BREAKING CHANGE: <description>} works.

Screenshot 2023-03-14 at 14 50 02

@richardkazuomiller your comment really help me. I was trying to get a major bump with a commit on a shared folder for all packages. As soon I did a silly change with a commit inside a package it recognized as a major change.

Commit: git commit -a -m 'feat!: Dummy breaking change' Command: lerna version --no-push --conventional-commits --changelog-preset conventionalcommits --no-changelog

(We do not want the Angular preset, to be able to use the conventionalcommits preset you need to install the conventional-changelog-conventionalcommits package)

This has been the ONLY way I have been able to get a Major bump. I have been struggling with this for hours.

Thank you so much @qrosmeli and @richardkazuomiller . Passing --changelog-preset conventionalcommits was the only way it worked for me too.

Digging further I found this: image

which is the right behavior as button has breaking changes.

which seems to be related to https://github.com/lerna/lerna/issues/2761, https://github.com/lerna/lerna/issues/2766

After upgrading packages to 1.x, versioning seems to do the right thing (respect feat!:...)

image

I managed to make it work!

TL;DR: Just add BREAKING CHANGE: <description>} footer to the bottom of your commit message.

I managed to resolve that using breaking change footer convention in the commit message:

feat(lang)!: changed property name
BREAKING CHANGE: Changed property name `action` to `callback`

As you can also see here: https://www.conventionalcommits.org/en/v1.0.0/#specification The ! doesn’t signal conventional commits that there is a breaking change, it’s only used to draw attention. The BREAKING CHANGE footer on the other hand actually does that. So running lerna version --conventional-commits or lerna publish --conventional-commits will actually bump major versions for the affected files.

@qrosmeli That’s great! I’m glad I could help 😸