Skip to content

Commit

Permalink
Update changelog helper options (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecraig12345 authored Sep 10, 2024
1 parent b339fa7 commit f857744
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 69 deletions.
7 changes: 7 additions & 0 deletions change/beachball-987605db-26f2-46b5-96f4-b21468815bf8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Update internal changelog helper options",
"packageName": "beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
}
92 changes: 52 additions & 40 deletions src/__tests__/changelog/getPackageChangelogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function makeChangeInfo(pkg: string, overrides?: Partial<ChangeFileInfo>): Chang
};
}

const options: Parameters<typeof getPackageChangelogs>[0]['options'] = {
const options: Parameters<typeof getPackageChangelogs>[1] = {
path: '.',
changeDir: 'change',
};
Expand All @@ -41,12 +41,14 @@ describe('getPackageChangelogs', () => {
];
const packageInfos = makePackageInfos({ foo: { version: '1.0.0' } });

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch' },
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch' },
packageInfos,
},
options
);

expect(changelogs.foo).toEqual({
comments: {
Expand All @@ -68,12 +70,14 @@ describe('getPackageChangelogs', () => {
bar: { version: '2.0.0' },
});

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
packageInfos,
},
options
);

expect(changelogs.foo).toEqual({
comments: {
Expand All @@ -99,12 +103,14 @@ describe('getPackageChangelogs', () => {
const changeFileChangeInfos: ChangeSet = [makeChangeInfo('foo', { extra: 'prop' })];
const packageInfos: PackageInfos = makePackageInfos({ foo: { version: '1.0.0' } });

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch' },
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch' },
packageInfos,
},
options
);

expect(changelogs.foo.comments.patch![0]).toMatchObject({ extra: 'prop' });
});
Expand All @@ -121,13 +127,15 @@ describe('getPackageChangelogs', () => {
bar: { version: '2.0.0', dependencies: { foo: '^1.0.0' } },
});

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
dependentChangedBy,
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
dependentChangedBy,
packageInfos,
},
options
);

expect(Object.keys(changelogs.foo.comments.patch!)).toHaveLength(1);
expect(changelogs.bar).toEqual({
Expand Down Expand Up @@ -162,13 +170,15 @@ describe('getPackageChangelogs', () => {
bar: { version: '2.0.0', dependencies: { foo: '^1.0.0' } },
});

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
dependentChangedBy,
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { foo: 'patch', bar: 'patch' },
dependentChangedBy,
packageInfos,
},
options
);

expect(changelogs.bar.comments).toEqual({
patch: [
Expand Down Expand Up @@ -197,13 +207,15 @@ describe('getPackageChangelogs', () => {
bar: { version: '1.0.0' },
});

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes: { bar: 'patch', 'private-pkg': 'patch' },
dependentChangedBy,
packageInfos,
options,
});
const changelogs = getPackageChangelogs(
{
changeFileChangeInfos,
calculatedChangeTypes: { bar: 'patch', 'private-pkg': 'patch' },
dependentChangedBy,
packageInfos,
},
options
);

expect(changelogs.bar).toBeTruthy();
expect(changelogs['private-pkg']).toBeUndefined();
Expand Down
4 changes: 2 additions & 2 deletions src/bump/performBump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { updateLockFile } from './updateLockFile';
export async function performBump(bumpInfo: BumpInfo, options: BeachballOptions): Promise<BumpInfo> {
const { modifiedPackages, packageInfos, changeFileChangeInfos } = bumpInfo;

await callHook(options.hooks?.prebump, modifiedPackages, bumpInfo.packageInfos);
await callHook(options.hooks?.prebump, modifiedPackages, packageInfos);

updatePackageJsons(modifiedPackages, packageInfos);
await updateLockFile(options.path);
Expand All @@ -28,7 +28,7 @@ export async function performBump(bumpInfo: BumpInfo, options: BeachballOptions)
unlinkChangeFiles(changeFileChangeInfos, packageInfos, options);
}

await callHook(options.hooks?.postbump, modifiedPackages, bumpInfo.packageInfos);
await callHook(options.hooks?.postbump, modifiedPackages, packageInfos);

// This is returned from bump() for testing
return bumpInfo;
Expand Down
22 changes: 9 additions & 13 deletions src/changelog/getPackageChangelogs.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import path from 'path';
import { PackageInfo, PackageInfos } from '../types/PackageInfo';
import { PackageInfo } from '../types/PackageInfo';
import { PackageChangelog } from '../types/ChangeLog';
import { generateTag } from '../git/generateTag';
import { BumpInfo } from '../types/BumpInfo';
import { getChangePath } from '../paths';
import { getFileAddedHash } from 'workspace-tools';
import { ChangeSet } from '../types/ChangeInfo';
import type { BeachballOptions } from '../types/BeachballOptions';
import { DeepReadonly } from '../types/DeepReadonly';

/**
* Used for `ChangelogEntry.commit` if the commit hash is not available.
*/
const commitNotAvailable = 'not available';

/**
* Get the preliminary changelog info for each modified package, based on change files and dependent bumps.
* Get the preliminary changelog info for each modified package, based on change files and
* possibly dependent bumps. (Omit `dependentChangedBy` to exclude dependent bumps.)
* @returns Mapping from package name to package changelog.
*/
export function getPackageChangelogs(params: {
changeFileChangeInfos: DeepReadonly<ChangeSet>;
calculatedChangeTypes: BumpInfo['calculatedChangeTypes'];
dependentChangedBy?: BumpInfo['dependentChangedBy'];
packageInfos: PackageInfos;
options: Pick<BeachballOptions, 'path' | 'changeDir'>;
}): Record<string, PackageChangelog> {
const { changeFileChangeInfos, calculatedChangeTypes, dependentChangedBy = {}, packageInfos, options } = params;
export function getPackageChangelogs(
bumpInfo: Pick<BumpInfo, 'changeFileChangeInfos' | 'calculatedChangeTypes' | 'packageInfos'> &
Partial<Pick<BumpInfo, 'dependentChangedBy'>>,
options: Pick<BeachballOptions, 'path' | 'changeDir'>
): Record<string, PackageChangelog> {
const { changeFileChangeInfos, calculatedChangeTypes, dependentChangedBy = {}, packageInfos } = bumpInfo;

const changelogs: Record<string, PackageChangelog> = {};

const changeFileCommits: { [changeFile: string]: string } = {};
const changePath = getChangePath(options);

Expand Down
19 changes: 5 additions & 14 deletions src/changelog/writeChangelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ export async function writeChangelog(
bumpInfo: Pick<BumpInfo, 'changeFileChangeInfos' | 'calculatedChangeTypes' | 'dependentChangedBy' | 'packageInfos'>,
options: Pick<BeachballOptions, 'changeDir' | 'changelog' | 'generateChangelog' | 'path'>
): Promise<void> {
const { changeFileChangeInfos, calculatedChangeTypes, dependentChangedBy, packageInfos } = bumpInfo;
const { packageInfos } = bumpInfo;

const groupedChangelogDirs = await writeGroupedChangelog(bumpInfo, options);

const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes,
dependentChangedBy,
packageInfos,
options,
});
// Get changelogs including dependent changes
const changelogs = getPackageChangelogs(bumpInfo, options);

// Write package changelogs.
// Use a standard for loop here to prevent potentially firing off multiple network requests at once
Expand Down Expand Up @@ -63,12 +58,8 @@ async function writeGroupedChangelog(
}

// Get changelogs without dependency bump entries
const changelogs = getPackageChangelogs({
changeFileChangeInfos,
calculatedChangeTypes,
packageInfos,
options,
});
// (do NOT spread the bump info here!)
const changelogs = getPackageChangelogs({ changeFileChangeInfos, calculatedChangeTypes, packageInfos }, options);

const groupedChangelogs: {
[changelogAbsDir: string]: { changelogs: PackageChangelog[]; masterPackage: PackageInfo };
Expand Down

0 comments on commit f857744

Please sign in to comment.