Repository: lerna-lite/lerna-lite
Pull request #1001 (2025-03-22 19:10:58)

fix(version)!: change default "describe [Git] tag" pattern to `v*`
<!--- Provide a general summary of your changes in the Title above -->

## Description

Reopening an older PR #932 that was closed earlier because it introduced a breaking change. 

> Changed the default --describe-tag pattern from an empty string to 'v*' for non-independent mode in the lerna version command. Updated related documentation and tests to reflect this change.
This change is being done to have --describe-tag and --tag-version-prefix in sync for non-independent mode.

## Motivation and Context

> When using `fixed` mode, I ran into similar problems as described in #220. Setting `describeTag` to `v*` helped.
> 
> In my opinion, it should be the default to have `describeTag` and `tagVersionPrefix` synced.

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Chore (change that has absolutely no effect on users)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/lerna-lite/lerna-lite/pull/1001?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 97.92%. Comparing base [(`6eb5a80`)](https://app.codecov.io/gh/lerna-lite/lerna-lite/commit/6eb5a80d9dd42898b8028712cd15abc7959ade3b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite) to head [(`4a7fe21`)](https://app.codecov.io/gh/lerna-lite/lerna-lite/commit/4a7fe21623d339bcddac7af97ac40a109e5b5c5b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #1001   +/-   ##
=======================================
  Coverage   97.92%   97.92%           
=======================================
  Files         148      148           
  Lines        9016     9016           
  Branches     2288     2289    +1     
=======================================
  Hits         8828     8828           
  Misses        187      187           
  Partials        1        1           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/lerna-lite/lerna-lite/pull/1001?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>

Patch:
diff --git a/packages/core/src/utils/collect-updates/collect-updates.ts b/packages/core/src/utils/collect-updates/collect-updates.ts
index a9bbdee5..b0d9aa6f 100644
--- a/packages/core/src/utils/collect-updates/collect-updates.ts
+++ b/packages/core/src/utils/collect-updates/collect-updates.ts
@@ -44,7 +44,7 @@ export function collectUpdates(
       : new Map(filteredPackages.map(({ name }) => [name, packageGraph.get(name)]));
 
   let committish = commandOptions.since;
-  const tagPattern = describeTag ? describeTag : isIndependent ? '*@*' : '';
+  const tagPattern = describeTag ? describeTag : isIndependent ? '*@*' : 'v*';
 
   if (hasTags(execOpts, tagPattern)) {
     const describeOptions: DescribeRefOptions = {
diff --git a/packages/version/README.md b/packages/version/README.md
index 0107ff70..2e7c2725 100644
--- a/packages/version/README.md
+++ b/packages/version/README.md
@@ -481,7 +481,7 @@ lerna version --create-release gitlab --skip-bump-only-releases
 ### `--describe-tag <pattern>`
 When `lerna version` is executed, it will identifies packages that have been updated since the previous tagged release. The rules it identifies are based on describe tag pattern (excuted `git describe --match` behind the scenes).
 
-The tag pattern defaults to `*@*` (independent mode) or `""` (non-independent mode). You can configure `describeTag` in `lerna.json` to specify the tag pattern.
+The tag pattern defaults to `*@*` (independent mode) or `"v*"` (non-independent mode). You can configure `describeTag` in `lerna.json` to specify the tag pattern.
 
 The `describeTag` will also take effect under `lerna publish`, for example `lerna publish --canary`, but it will not take effect under `lerna publish from-git`.
 


Test patch:
diff --git a/packages/core/src/utils/collect-updates/__tests__/collect-updates.spec.ts b/packages/core/src/utils/collect-updates/__tests__/collect-updates.spec.ts
index 5b6c09f2..7dd7e213 100644
--- a/packages/core/src/utils/collect-updates/__tests__/collect-updates.spec.ts
+++ b/packages/core/src/utils/collect-updates/__tests__/collect-updates.spec.ts
@@ -78,8 +78,8 @@ describe('collectUpdates()', () => {
         name: 'package-standalone',
       }),
     ]);
-    expect(hasTags).toHaveBeenLastCalledWith(execOpts, '');
-    expect(describeRefSync).toHaveBeenLastCalledWith({ cwd: '/test', match: '' }, undefined);
+    expect(hasTags).toHaveBeenLastCalledWith(execOpts, 'v*');
+    expect(describeRefSync).toHaveBeenLastCalledWith({ cwd: '/test', match: 'v*' }, undefined);
     expect(makeDiffPredicate).toHaveBeenLastCalledWith('v1.0.0', execOpts, undefined, {
       independentSubpackages: undefined,
     });
@@ -507,7 +507,7 @@ describe('collectUpdates()', () => {
     expect(describeRefSync).toHaveBeenCalledWith({ cwd: '/test', match: '*custom-tag*' }, true);
   });
 
-  it('no use "describeTag" in non-independent mode', async () => {
+  it('use "describeTag" with default value in non-independent mode', async () => {
     const graph = buildGraph();
     const pkgs = graph.rawPackageList;
     const execOpts = { cwd: '/test' };
@@ -516,10 +516,10 @@ describe('collectUpdates()', () => {
       isIndependent: false,
       includeMergedTags: true,
     });
-    expect(describeRefSync).toHaveBeenCalledWith({ cwd: '/test', match: '' }, true);
+    expect(describeRefSync).toHaveBeenCalledWith({ cwd: '/test', match: 'v*' }, true);
   });
 
-  it('use "describeTag" with empty value in independent mode', async () => {
+  it('use "describeTag" with default value in independent mode', async () => {
     const graph = buildGraph();
     const pkgs = graph.rawPackageList;
     const execOpts = { cwd: '/test' };
diff --git a/packages/publish/src/__tests__/publish-canary.spec.ts b/packages/publish/src/__tests__/publish-canary.spec.ts
index 0d1afb9d..681f9826 100644
--- a/packages/publish/src/__tests__/publish-canary.spec.ts
+++ b/packages/publish/src/__tests__/publish-canary.spec.ts
@@ -180,6 +180,7 @@ test("publish --canary --tag-version-prefix='abc'", async () => {
       "package-1": 1.0.1-alpha.0.SHA,
       "package-2": 1.0.1-alpha.0.SHA,
       "package-3": 1.0.1-alpha.0.SHA,
+      "package-4": 1.0.1-alpha.0.SHA,
     }
   `);
 });