Repository: lerna-lite/lerna-lite
Pull request #1028 (2025-04-29 16:40:17)

fix: pnpm local catalog changes should be reflected in packages
<!--- Provide a general summary of your changes in the Title above -->

## Description

continues on PR #1023

## Motivation and Context

another fix for issue #1010 since I forgot to add local deps check in previous PR #1023

## 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)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] 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.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] 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/1028?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.89%. Comparing base [(`cccc41e`)](https://app.codecov.io/gh/lerna-lite/lerna-lite/commit/cccc41e2357af41c868addef0673233921154a71?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=lerna-lite) to head [(`9a10e78`)](https://app.codecov.io/gh/lerna-lite/lerna-lite/commit/9a10e788ec91ae91208050fd2339142c91e0c53e?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    #1028      +/-   ##
==========================================
+ Coverage   97.89%   97.89%   +0.01%     
==========================================
  Files         153      153              
  Lines        9123     9127       +4     
  Branches     2327     2330       +3     
==========================================
+ Hits         8930     8934       +4     
  Misses        192      192              
  Partials        1        1              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/lerna-lite/lerna-lite/pull/1028?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/lib/make-diff-predicate.ts b/packages/core/src/utils/collect-updates/lib/make-diff-predicate.ts
index 3eeaad61..30ebebe7 100644
--- a/packages/core/src/utils/collect-updates/lib/make-diff-predicate.ts
+++ b/packages/core/src/utils/collect-updates/lib/make-diff-predicate.ts
@@ -68,7 +68,11 @@ export function makeDiffPredicate(
     }
 
     // last check, user might use pnpm catalog, if so check if current node package has changes found in catalog
-    if (!hasDiff && Array.from(node.externalDependencies).some(([depName]) => changedCatalogDeps.includes(depName))) {
+    if (
+      !hasDiff &&
+      (Array.from(node.externalDependencies).some(([depName]) => changedCatalogDeps.includes(depName)) ||
+        Array.from(node.localDependencies).some(([depName]) => changedCatalogDeps.includes(depName)))
+    ) {
       log.silly('', 'diff found in catalog dependencies on package %s', node.name);
       hasDiff = true;
     }


Test patch:
diff --git a/packages/core/src/utils/collect-updates/__tests__/lib-make-diff-predicate.spec.ts b/packages/core/src/utils/collect-updates/__tests__/lib-make-diff-predicate.spec.ts
index 34505550..47854fc4 100644
--- a/packages/core/src/utils/collect-updates/__tests__/lib-make-diff-predicate.spec.ts
+++ b/packages/core/src/utils/collect-updates/__tests__/lib-make-diff-predicate.spec.ts
@@ -48,6 +48,7 @@ test('empty diff', () => {
   const hasDiff = makeDiffPredicate('v1.0.0', { cwd: '/test' }, undefined, [], {});
   const result = hasDiff({
     location: '/test/packages/pkg-1',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['pkg-2', {}]]),
   } as PackageGraphNode);
 
@@ -75,6 +76,7 @@ test('ignore changes (globstars)', () => {
   const hasDiff = makeDiffPredicate('v1.0.0', { cwd: '/test' }, ['**/examples/**', '*.md'], [], {});
   const result = hasDiff({
     location: '/test/packages/pkg-2',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['pkg-2', {}]]),
   } as PackageGraphNode);
 
@@ -87,6 +89,7 @@ test('ignore changes (match base)', () => {
   const hasDiff = makeDiffPredicate('v1.0.0', { cwd: '/test' }, ['*.md'], [], {});
   const result = hasDiff({
     location: '/test/packages/pkg-3',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['pkg-2', {}]]),
   } as PackageGraphNode);
 
@@ -103,6 +106,7 @@ test('exclude subpackages when --independent-subpackages option is enabled and n
   });
   const result = hasDiff({
     location: '/test/packages/pkg-2',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['pkg-2', {}]]),
   } as PackageGraphNode);
 
@@ -126,6 +130,7 @@ test('not exclude any subpackages when --independent-subpackages option is enabl
   });
   const result = hasDiff({
     location: '/test/packages/pkg-2',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['pkg-2', {}]]),
   } as PackageGraphNode);
 
@@ -135,12 +140,13 @@ test('not exclude any subpackages when --independent-subpackages option is enabl
   });
 });
 
-test('diffWorkspaceCatalog with changes in pnpm workspace catalog', () => {
+test('diffWorkspaceCatalog with external dependency changes in pnpm workspace catalog', () => {
   setup([]);
 
   const hasDiff = makeDiffPredicate('v1.0.0', { cwd: '/test' }, undefined, ['vite'], {});
   const result = hasDiff({
     location: '/test/packages/pkg-1',
+    localDependencies: new Map([]),
     externalDependencies: new Map([['vite', {}]]),
   } as PackageGraphNode);
 
@@ -148,6 +154,20 @@ test('diffWorkspaceCatalog with changes in pnpm workspace catalog', () => {
   expect(childProcesses.execSync).toHaveBeenLastCalledWith('git', ['diff', '--name-only', 'v1.0.0', '--', 'packages/pkg-1'], { cwd: '/test' });
 });
 
+test('diffWorkspaceCatalog with local dependency changes in pnpm workspace catalog', () => {
+  setup([]);
+
+  const hasDiff = makeDiffPredicate('v1.0.0', { cwd: '/test' }, undefined, ['@mono/pkg-1'], {});
+  const result = hasDiff({
+    location: '/test/packages/pkg-1',
+    localDependencies: new Map([['@mono/pkg-1', {}]]),
+    externalDependencies: new Map([]),
+  } as PackageGraphNode);
+
+  expect(result).toBe(true);
+  expect(childProcesses.execSync).toHaveBeenLastCalledWith('git', ['diff', '--name-only', 'v1.0.0', '--', 'packages/pkg-1'], { cwd: '/test' });
+});
+
 test('diff workspace catalog returning dependencies that changed in the catalog', () => {
   // make a diff on the catalog for the "execa" dependency
   const mockPrevCatalogCommit = 'packages:\n  - packages/**\n\ncatalog:\n  execa: ^8.0.0\n  fs-extra: ^11.3.0';
@@ -167,7 +187,7 @@ test('diff workspace catalog returning dependencies that changed in the catalog'
   expect(changes).toEqual(['execa']);
 });
 
-test('diffWorkspaceCatalog returns changed dependencies when catalog values differ', () => {
+test('diffWorkspaceCatalog returns changed external dependencies when catalog values differ', () => {
   const prev = 'packages:\n  - packages/**\n\ncatalog:\n  execa: ^8.0.0\n  fs-extra: ^11.3.0';
   const curr = 'packages:\n  - packages/**\n\ncatalog:\n  execa: ^9.5.2\n  fs-extra: ^11.3.0';
   (readFileMock as Mock).mockReturnValueOnce(curr);
@@ -177,6 +197,16 @@ test('diffWorkspaceCatalog returns changed dependencies when catalog values diff
   expect(changes).toEqual(['execa']);
 });
 
+test('diffWorkspaceCatalog returns changed local dependencies when catalog values differ', () => {
+  const prev = 'packages:\n  - packages/**\n\ncatalog:\n  "@mono/pkg-1": ^8.0.0\n  fs-extra: ^11.3.0';
+  const curr = 'packages:\n  - packages/**\n\ncatalog:\n  "@mono/pkg-1": ^9.5.2\n  fs-extra: ^11.3.0';
+  (readFileMock as Mock).mockReturnValueOnce(curr);
+  (childProcesses.execSync as Mock).mockReturnValueOnce(prev);
+
+  const changes = diffWorkspaceCatalog('v1.0.0');
+  expect(changes).toEqual(['@mono/pkg-1']);
+});
+
 test('diffWorkspaceCatalog returns multiple changed dependencies', () => {
   const prev = 'packages:\n  - packages/**\n\ncatalog:\n  execa: ^8.0.0\n  fs-extra: ^10.0.0';
   const curr = 'packages:\n  - packages/**\n\ncatalog:\n  execa: ^9.5.2\n  fs-extra: ^11.3.0';