Fix changelog entry insertion when no package title is present in the CHANGELOG.md file#1859
Merged
Andarist merged 8 commits intoMar 2, 2026
Conversation
…on headings
When a CHANGELOG.md file starts directly with a version heading (e.g. ## 1.3.0)
rather than a package title heading (e.g. # my-package), new version entries were
incorrectly inserted after the existing version heading line instead of before it.
This caused changelogs like:
## 1.3.0 <- existing
## 1.4.0 <- new entry, wrongly placed under old heading
### Minor Changes
...
### Minor Changes <- old content appears to be under new heading
...
The fix detects whether the first line of the changelog is a version heading using
/^#{1,6}\s+\d+\.\d+/ regex. When it is, the new entry is prepended before the
entire file content instead of after the first line.
Fixes changesets#1056
🦋 Changeset detectedLatest commit: f98b50f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1859 +/- ##
==========================================
- Coverage 81.86% 81.84% -0.02%
==========================================
Files 55 55
Lines 2360 2396 +36
Branches 706 724 +18
==========================================
+ Hits 1932 1961 +29
- Misses 423 429 +6
- Partials 5 6 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CHANGELOG.md file
Andarist
approved these changes
Mar 2, 2026
Merged
nnecec
pushed a commit
to nnecec/changesets-docs
that referenced
this pull request
Apr 16, 2026
… `CHANGELOG.md` file (changesets#1859) * fix(apply-release-plan): insert changelog entry before existing version headings When a CHANGELOG.md file starts directly with a version heading (e.g. ## 1.3.0) rather than a package title heading (e.g. # my-package), new version entries were incorrectly inserted after the existing version heading line instead of before it. This caused changelogs like: ## 1.3.0 <- existing ## 1.4.0 <- new entry, wrongly placed under old heading ### Minor Changes ... ### Minor Changes <- old content appears to be under new heading ... The fix detects whether the first line of the changelog is a version heading using /^#{1,6}\s+\d+\.\d+/ regex. When it is, the new entry is prepended before the entire file content instead of after the first line. Fixes changesets#1056 * make room for those tests * simplify test * tweak * tweak * bring back trimming * add changeset * dont use the `void` --------- Co-authored-by: Maks Pikov <[email protected]> Co-authored-by: Mateusz Burzyński <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
CHANGELOG.mdfile starts directly with a version heading (e.g.## 1.3.0) rather than a package title heading (e.g.# my-package), newly generated version entries are inserted after the first line (the existing version heading), not before it.This produces a changelog like:
This is the bug reported in #1056. The Andarist comment in that issue suggests detecting whether the top heading matches a version, which is what this PR does.
Root Cause
In
packages/apply-release-plan/src/index.ts, theprependFilefunction always inserts new content after the first line of the file. This works when the first line is a package title (# my-package), but breaks when the first line is already a version heading.Fix
The
prependFilefunction now detects whether the first line is a version heading (using/^#{1,6}\s+\d+\.\d+/). When it is, the new changelog entry is prepended before the entire existing content:Test
Added a test that:
CHANGELOG.mdstarting with## 1.0.0(no package title)1.0.0to1.1.0## 1.1.0appears before## 1.0.0in the outputFixes #1056