Skip to content

Commit 5ac000a

Browse files
authored
Fix: changelog-update retain history for renamed packages (#182)
1 parent f65c16b commit 5ac000a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/cli.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type UpdateOptions = {
9292
projectRootDirectory?: string;
9393
tagPrefix: string;
9494
formatter: Formatter;
95+
/**
96+
* The package rename properties, used in case of package is renamed
97+
*/
98+
packageRename?: PackageRename;
9599
};
96100

97101
/**
@@ -105,6 +109,8 @@ type UpdateOptions = {
105109
* @param options.projectRootDirectory - The root project directory.
106110
* @param options.tagPrefix - The prefix used in tags before the version number.
107111
* @param options.formatter - A custom Markdown formatter to use.
112+
* @param options.packageRename - The package rename properties.
113+
* An optional, which is required only in case of package renamed.
108114
*/
109115
async function update({
110116
changelogPath,
@@ -114,6 +120,7 @@ async function update({
114120
projectRootDirectory,
115121
tagPrefix,
116122
formatter,
123+
packageRename,
117124
}: UpdateOptions) {
118125
const changelogContent = await readChangelog(changelogPath);
119126

@@ -125,6 +132,7 @@ async function update({
125132
projectRootDirectory,
126133
tagPrefixes: [tagPrefix],
127134
formatter,
135+
packageRename,
128136
});
129137

130138
if (newChangelogContent) {
@@ -465,6 +473,13 @@ async function main() {
465473
};
466474

467475
if (command === 'update') {
476+
let packageRename: PackageRename | undefined;
477+
if (versionBeforePackageRename && tagPrefixBeforePackageRename) {
478+
packageRename = {
479+
versionBeforeRename: versionBeforePackageRename,
480+
tagPrefixBeforeRename: tagPrefixBeforePackageRename,
481+
};
482+
}
468483
await update({
469484
changelogPath,
470485
currentVersion,
@@ -473,6 +488,7 @@ async function main() {
473488
projectRootDirectory,
474489
tagPrefix,
475490
formatter,
491+
packageRename,
476492
});
477493
} else if (command === 'validate') {
478494
let packageRename: PackageRename | undefined;

src/update-changelog.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type Changelog from './changelog';
55
import { Formatter } from './changelog';
66
import { ChangeCategory, Version } from './constants';
77
import { parseChangelog } from './parse-changelog';
8+
import { PackageRename } from './shared-types';
89

910
/**
1011
* Get the most recent tag for a project.
@@ -164,6 +165,10 @@ export type UpdateChangelogOptions = {
164165
projectRootDirectory?: string;
165166
tagPrefixes?: [string, ...string[]];
166167
formatter?: Formatter;
168+
/**
169+
* The package rename properties, used in case of package is renamed
170+
*/
171+
packageRename?: PackageRename;
167172
};
168173

169174
/**
@@ -186,6 +191,8 @@ export type UpdateChangelogOptions = {
186191
* @param options.tagPrefixes - A list of tag prefixes to look for, where the first is the intended
187192
* prefix and each subsequent prefix is a fallback in case the previous tag prefixes are not found.
188193
* @param options.formatter - A custom Markdown formatter to use.
194+
* @param options.packageRename - The package rename properties.
195+
* An optional, which is required only in case of package renamed.
189196
* @returns The updated changelog text.
190197
*/
191198
export async function updateChangelog({
@@ -196,12 +203,14 @@ export async function updateChangelog({
196203
projectRootDirectory,
197204
tagPrefixes = ['v'],
198205
formatter = undefined,
206+
packageRename,
199207
}: UpdateChangelogOptions): Promise<string | undefined> {
200208
const changelog = parseChangelog({
201209
changelogContent,
202210
repoUrl,
203211
tagPrefix: tagPrefixes[0],
204212
formatter,
213+
packageRename,
205214
});
206215

207216
// Ensure we have all tags on remote

0 commit comments

Comments
 (0)