jscutlery / semver

Nx plugin to automate semantic versioning and CHANGELOG generation.
MIT License
727 stars 84 forks source link

Versioning broken when tagPrefix set #653

Open mvrana-cen81948 opened 1 year ago

mvrana-cen81948 commented 1 year ago

I set tagPrefixes for my libraries. My intention is to have tag like lib@0.0.0., lib-angular@0.0.0. So i set tagPrefix for every library like that: "tagPrefix": "lib@". When i do change into lib, it generates changelog ok:

# Changelog

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

### [0.1.1](///compare/lib1@0.1.0...lib1@0.1.1) (2023-02-05)

### Bug Fixes

* **lib1:** test4 21c7115

## 0.1.0 (2023-02-05)

### Features

* **lib1:** lib1 added 81ba604
* **lib1:** lib1.test1 4f1f70b
* **lib1:** test2 b01720b

### Bug Fixes

* **lib1:** test3 35e7bc6

But changelog of lib1-angular, which is dependent on lib1, says "lib1 updated to version 0.1.0", but actually it should say "lib1 updated to version 0.1.1".

# Changelog

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

### [0.1.1](///compare/lib1-angular@0.1.0...lib1-angular@0.1.1) (2023-02-05)

### Dependency Updates

* `lib1` updated to version `0.1.0`
## 0.1.0 (2023-02-05)

### Dependency Updates

* `lib1` updated to version `0.1.0`

### Features

* **lib1-angular:** lib1 angular wrapper af60426

if i leave tagPrefix option unset, it works as expected

mvrana-cen81948 commented 1 year ago

I did some research and found the issue. At try_bump.ts._getDependencyVersions() [line 291] is this lines of code which i understand that only function is to guess what tagPrefix is used for dependency:

      const tagPrefix = formatTagPrefix({
        versionTagPrefix,
        projectName: dependencyName,
        syncVersions,
      });

simple fix for my use case is something like that:

const tagPrefix = syncVersions ? 'v' : versionTagPrefix?.replace(projectName, dependencyName) || `${projectName}-`;

But it only works when is used one opinionated pattern across entire workspace. More suitable solution will probably be list commits over projectRoot folder and just find last one, or load project.json and nx.json to get correct tagPrefix from options.