1
- import { hasChangelog , readChangelog } from './packages.js' ;
1
+ import { getPackageFile } from './packages.js' ;
2
+ import { fileExists , readFile } from './fs.js' ;
2
3
4
+ /** @typedef {{ version: string; date?: Date; body: string } } Changes */
3
5
/** @typedef {Record<string, Changes> } AllChanges */
4
6
5
7
/** @type (packageName: string) => AllChanges | null */
6
8
export function getAllChanges ( packageName ) {
7
- if ( ! hasChangelog ( packageName ) ) {
9
+ let changelogFile = getPackageFile ( packageName , 'CHANGELOG.md' ) ;
10
+
11
+ if ( ! fileExists ( changelogFile ) ) {
8
12
return null ;
9
13
}
10
14
11
- let changelog = readChangelog ( packageName ) ;
15
+ let changelog = readFile ( changelogFile ) ;
12
16
let parser = / ^ # # ( [ a - z \d \. \- ] + ) (?: \( ( [ ^ ) ] + ) \) ) ? $ / gim;
13
17
14
18
/** @type {AllChanges } */
@@ -21,16 +25,14 @@ export function getAllChanges(packageName) {
21
25
let version = versionString . startsWith ( 'v' ) ? versionString . slice ( 1 ) : versionString ;
22
26
let date = dateString ? new Date ( dateString ) : undefined ;
23
27
let nextMatch = parser . exec ( changelog ) ;
24
- let changes = changelog . slice ( lastIndex , nextMatch ? nextMatch . index : undefined ) . trim ( ) ;
25
- result [ version ] = { version, date, changes } ;
28
+ let body = changelog . slice ( lastIndex , nextMatch ? nextMatch . index : undefined ) . trim ( ) ;
29
+ result [ version ] = { version, date, body } ;
26
30
parser . lastIndex = lastIndex ;
27
31
}
28
32
29
33
return result ;
30
34
}
31
35
32
- /** @typedef {{ version: string; date?: Date; changes: string } } Changes */
33
-
34
36
/** @type (packageName: string, version: string) => Changes | null */
35
37
export function getChanges ( packageName , version ) {
36
38
let allChanges = getAllChanges ( packageName ) ;
0 commit comments