Update changelog helper options (#993)

This commit is contained in:
Elizabeth Craig 2024-09-10 00:37:51 -07:00 коммит произвёл GitHub
Родитель b339fa7e54
Коммит f857744ac9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 75 добавлений и 69 удалений

Просмотреть файл

@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Update internal changelog helper options",
"packageName": "beachball",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
}

Просмотреть файл

@ -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',
};
@ -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: {
@ -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: {
@ -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' });
});
@ -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({
@ -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: [
@ -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();

Просмотреть файл

@ -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);
@ -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;

Просмотреть файл

@ -1,13 +1,11 @@
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.
@ -15,20 +13,18 @@ import { DeepReadonly } from '../types/DeepReadonly';
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);

Просмотреть файл

@ -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
@ -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 };