@@ -40,10 +40,10 @@ async function* readChangelog(project: Project): AsyncGenerator<IChangelogEntry>
40
40
const fp = fs . createReadStream ( path . join ( project . dir , 'CHANGELOG.md' ) ) ;
41
41
const rl = readline . createInterface ( fp ) ;
42
42
43
- let version ;
43
+ let version : string ;
44
44
let fullText = '' ;
45
45
for await ( const line of rl ) {
46
- const matches = / ^ C h a n g e s i n \[ ( [ \d \ w. - ] + ) \ ]/ . exec ( line ) ;
46
+ const matches = / ^ C h a n g e s i n \[ ( [ \w . - ] + ) ] / . exec ( line ) ;
47
47
if ( matches ) {
48
48
if ( version ) {
49
49
yield {
@@ -107,7 +107,7 @@ function sanitiseMarkdown(text: string): string {
107
107
return text ;
108
108
}
109
109
110
- function engJoin ( things ) : string {
110
+ function engJoin ( things : string [ ] ) : string {
111
111
if ( things . length === 1 ) return things [ 0 ] ;
112
112
113
113
const firstLot = things . slice ( 0 , things . length - 2 ) ;
@@ -239,6 +239,15 @@ export async function updateChangelog(project: Project, changes: IChange[], forV
239
239
// This is the exact version we should be updating: replace it
240
240
await outHandle . write ( makeChangelogEntry ( changes , forVersion , project ) ) ;
241
241
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
+ }
242
251
} else if ( forReleaseSemVer . compare ( entry . version ) === 1 ) {
243
252
// This one comes before the one we're updating, so if we haven't yet written
244
253
// our changeset, we need to do it now.
@@ -249,14 +258,6 @@ export async function updateChangelog(project: Project, changes: IChange[], forV
249
258
}
250
259
// and then write the one we found too
251
260
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
- }
260
261
} else {
261
262
log . debug ( `Found ${ entry . version } which is newer than the version we should be updating` ) ;
262
263
await outHandle . write ( entry . text ) ;
0 commit comments