-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Bug Description
If you specify an overwrite-version for an existing version in the changelog file, everything after that version in the changelog file will be overwritten.
Steps to Reproduce
package.json configuration
{
...
"changelogger": {
....
"files": [
{
"path": "changelog.txt",
"strategy": "stellarwp-readme"
}
]
}
}changelog.txt
= [1.1.0] 2025-08-05 =
* Feature - New changelog.
= [1.0.0] 2025-08-05 =
* Feature - Old changelog.npx @stellarwp/changelogger write --overwrite-version 1.1.0Expected Behavior
The existing changelog items under 1.1.0 should be merged with the new changelog yaml files.
Actual Behavior
The entire changelog file is overwritten as it cannot properly determine the end of that changelog block.
Additional Information
On this line it attempts to grab the previous version in the event that you're attempting to merge the new changelog items with an existing changelog section. This should be fine.
However, on this line it tries to find the next previous version header to know where the section ends. ...but it uses the same version that you provided initially, so it effectively selects the whole file as part of its section as it never finds that version again.
This results in the entire changelog.txt being replaced. If we fix determining the nextVersionMatch so that it doesn't try to use the current version, we would also need to fix the sectionEnd to account for nextVersionMatch being a string as well to ensure it can return something like content.indexOf(nextVersionMatch) - 1 to ensure it doesn't replace the whole file still as it will still hit that base case.