diff --git a/src/__tests__/bump/setDependentVersions.test.ts b/src/__tests__/bump/setDependentVersions.test.ts new file mode 100644 index 000000000..cc3f9cc4c --- /dev/null +++ b/src/__tests__/bump/setDependentVersions.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, it } from '@jest/globals'; +import { setDependentVersions } from '../../bump/setDependentVersions'; +import { BeachballOptions } from '../../types/BeachballOptions'; +import { PackageInfos } from '../../types/PackageInfo'; + +describe("dependent packages are part of the bump", () => { + it("adds dependents for new changelog entries", () => { + const packageInfos: PackageInfos = { + foo: { + combinedOptions: {} as any, + name: 'foo', + packageJsonPath: 'packages/foo/package.json', + packageOptions: {}, + private: false, + version: '1.0.0', + dependencies: { + bar: '*', + }, + }, + bar: { + combinedOptions: {} as any, + name: 'bar', + packageJsonPath: 'packages/bar/package.json', + packageOptions: {}, + private: false, + version: '1.0.0', + }, + }; + + const scopedPackages = new Set(['foo', 'bar']); + + const dependentChangedBy = setDependentVersions( + packageInfos, + scopedPackages, + { verbose: false } as BeachballOptions + ); + + expect(dependentChangedBy['foo']).toBeTruthy(); + expect(dependentChangedBy['foo'].size).toBe(1); + + }) +}) \ No newline at end of file diff --git a/src/__tests__/changelog/getPackageChangelogs.test.ts b/src/__tests__/changelog/getPackageChangelogs.test.ts index d3256d931..3ac1edee2 100644 --- a/src/__tests__/changelog/getPackageChangelogs.test.ts +++ b/src/__tests__/changelog/getPackageChangelogs.test.ts @@ -69,6 +69,58 @@ describe('getPackageChangelogs', () => { expect(Object.keys(changelogs.foo.comments.patch!)).toHaveLength(1); }); + it('should have new entries when a package was part of a dependent bump', () => { + const changeFileChangeInfos: ChangeSet = [ + { + changeFile: 'bar.json', + change: { + comment: 'comment for bar', + commit: 'deadbeef', + dependentChangeType: 'patch', + email: 'something@something.com', + packageName: 'bar', + type: 'minor', + }, + }, + ]; + + const dependentChangedBy: BumpInfo['dependentChangedBy'] = { + foo: new Set(['bar']), + }; + + const packageInfos: PackageInfos = { + foo: { + combinedOptions: {} as any, + name: 'foo', + packageJsonPath: 'packages/foo/package.json', + packageOptions: {}, + private: false, + version: '1.0.0', + dependencies: { + bar: '*', + }, + }, + bar: { + combinedOptions: {} as any, + name: 'bar', + packageJsonPath: 'packages/bar/package.json', + packageOptions: {}, + private: false, + version: '1.0.0', + }, + }; + + const changelogs = getPackageChangelogs( + changeFileChangeInfos, + { bar: 'minor', foo: 'patch' }, + dependentChangedBy, + packageInfos, + '.' + ); + + expect(Object.keys(changelogs.foo)).toBeTruthy(); + }); + it('should not generate change logs for dependent bumps of private packages', () => { const changeFileChangeInfos: ChangeSet = [ { diff --git a/src/bump/setDependentVersions.ts b/src/bump/setDependentVersions.ts index 8402f1786..55b276d3a 100644 --- a/src/bump/setDependentVersions.ts +++ b/src/bump/setDependentVersions.ts @@ -24,7 +24,7 @@ export function setDependentVersions( if (packageInfo) { const existingVersionRange = deps[dep]; const bumpedVersionRange = bumpMinSemverRange(packageInfo.version, existingVersionRange); - if (existingVersionRange !== bumpedVersionRange) { + if (bumpedVersionRange === "*" || existingVersionRange !== bumpedVersionRange) { deps[dep] = bumpedVersionRange; dependentChangedBy[pkgName] = dependentChangedBy[pkgName] || new Set();