Skip to content

Commit e70ec83

Browse files
committed
fix(scripts): detect version heading at file start
indexOf('\n## ') required a preceding newline, so a root CHANGELOG that begins directly with a "## <version>" heading (e.g. after a human strips the "# Changelog" header) was treated as having no version block, and new content got appended to the end instead of spliced at the top. Switch to a multiline regex that matches "## " at any line start, including line 0.
1 parent a5394ca commit e70ec83

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

scripts/consolidate-changelog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ function consolidate(): void {
171171

172172
if (fs.existsSync(ROOT_CHANGELOG)) {
173173
const content = fs.readFileSync(ROOT_CHANGELOG, 'utf-8');
174-
const firstVersionIdx = content.indexOf('\n## ');
175-
if (firstVersionIdx !== -1) {
176-
header = content.slice(0, firstVersionIdx + 1);
177-
body = content.slice(firstVersionIdx + 1);
174+
const firstHeadingMatch = content.match(/^## /m);
175+
if (firstHeadingMatch && firstHeadingMatch.index !== undefined) {
176+
header = content.slice(0, firstHeadingMatch.index);
177+
body = content.slice(firstHeadingMatch.index);
178178
} else {
179179
header = content.endsWith('\n') ? content : content + '\n';
180180
body = '';

0 commit comments

Comments
 (0)