Skip to content

Commit f7ea01c

Browse files
committed
Fix rc->release transition not consolidating with existing changelog entry
1 parent a5a1e0f commit f7ea01c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/changelog.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ async function* readChangelog(project: Project): AsyncGenerator<IChangelogEntry>
4040
const fp = fs.createReadStream(path.join(project.dir, 'CHANGELOG.md'));
4141
const rl = readline.createInterface(fp);
4242

43-
let version;
43+
let version: string;
4444
let fullText = '';
4545
for await (const line of rl) {
46-
const matches = /^Changes in \[([\d\w.-]+)\]/.exec(line);
46+
const matches = /^Changes in \[([\w.-]+)]/.exec(line);
4747
if (matches) {
4848
if (version) {
4949
yield {
@@ -107,7 +107,7 @@ function sanitiseMarkdown(text: string): string {
107107
return text;
108108
}
109109

110-
function engJoin(things): string {
110+
function engJoin(things: string[]): string {
111111
if (things.length === 1) return things[0];
112112

113113
const firstLot = things.slice(0, things.length - 2);
@@ -239,6 +239,15 @@ export async function updateChangelog(project: Project, changes: IChange[], forV
239239
// This is the exact version we should be updating: replace it
240240
await outHandle.write(makeChangelogEntry(changes, forVersion, project));
241241
changeWritten = true;
242+
} else if (isPrereleaseFor(semver.parse(entry.version), forReleaseSemVer)) {
243+
log.debug(`Found ${entry.version} which is a prerelease of the version we should be updating`);
244+
// This is a prerelease of the version we're trying to write, so remove the
245+
// prerelease entry from the changelog and replace it with the entry we're
246+
// writing, if we haven't already written it
247+
if (!changeWritten) {
248+
await outHandle.write(makeChangelogEntry(changes, forVersion, project));
249+
changeWritten = true;
250+
}
242251
} else if (forReleaseSemVer.compare(entry.version) === 1) {
243252
// This one comes before the one we're updating, so if we haven't yet written
244253
// our changeset, we need to do it now.
@@ -249,14 +258,6 @@ export async function updateChangelog(project: Project, changes: IChange[], forV
249258
}
250259
// and then write the one we found too
251260
await outHandle.write(entry.text);
252-
} else if (isPrereleaseFor(semver.parse(entry.version), forReleaseSemVer)) {
253-
log.debug(`Found ${entry.version} which is a prerelease of the version we should be updating`);
254-
// This is a prerelease of the version we're trying to write, so remove the
255-
// prerelease entry from the changelog and replace it with the entry we're
256-
// writing, if we haven't already written it
257-
if (!changeWritten) {
258-
await outHandle.write(makeChangelogEntry(changes, forVersion, project));
259-
}
260261
} else {
261262
log.debug(`Found ${entry.version} which is newer than the version we should be updating`);
262263
await outHandle.write(entry.text);

0 commit comments

Comments
 (0)