1
- const execa = require ( require . resolve ( 'execa' ) )
2
- const { promisify } = require ( 'util' )
3
- const fs = require ( 'fs' )
4
- const path = require ( 'path' )
5
- const read = promisify ( fs . readFile )
6
- const write = fs . writeFileSync
1
+ import execa from 'execa'
2
+ import { promises as fs , writeFile } from 'fs'
3
+ import path from 'pathe'
4
+
5
+ const dirname = path . dirname ( new URL ( import . meta. url ) . pathname )
6
+
7
+ async function readJson ( path ) {
8
+ const data = await fs . readFile ( path , 'utf8' )
9
+ return JSON . parse ( data )
10
+ }
7
11
8
12
function extractSpecificChangelog ( changelog , version ) {
9
13
if ( ! changelog ) {
@@ -31,17 +35,17 @@ async function commitChangelog(current, next) {
31
35
)
32
36
const matches = regex . exec ( stdout . toString ( ) )
33
37
const head = matches ? matches [ 1 ] : stdout
34
- const changelog = await read ( './CHANGELOG.md' , 'utf8' )
35
- return write ( './CHANGELOG.md' , `${ head } \n\n${ changelog } ` )
38
+ const changelog = await fs . readFile ( './CHANGELOG.md' , 'utf8' )
39
+ return writeFile ( './CHANGELOG.md' , `${ head } \n\n${ changelog } ` )
36
40
}
37
41
38
42
module . exports = {
39
43
mergeStrategy : { toSameBranch : [ 'master' ] } ,
40
44
monorepo : undefined ,
41
45
updateChangelog : false ,
42
46
beforeCommitChanges : ( { nextVersion, exec, dir } ) => {
43
- return new Promise ( resolve => {
44
- const pkg = require ( './package.json' )
47
+ return new Promise ( async resolve => {
48
+ const pkg = await readJson ( path . relative ( dirname , './package.json' ) )
45
49
commitChangelog ( pkg . version , nextVersion ) . then ( resolve )
46
50
} )
47
51
} ,
@@ -51,10 +55,10 @@ module.exports = {
51
55
`${ releaseType } release v${ version } ` ,
52
56
shouldRelease : ( ) => true ,
53
57
releases : {
54
- extractChangelog : ( { version, dir } ) => {
58
+ extractChangelog : async ( { version, dir } ) => {
55
59
const changelogPath = path . resolve ( dir , 'CHANGELOG.md' )
56
60
try {
57
- const changelogFile = fs . readFileSync ( changelogPath , 'utf-8' ) . toString ( )
61
+ const changelogFile = await fs . readFile ( changelogPath , 'utf8' )
58
62
const ret = extractSpecificChangelog ( changelogFile , version )
59
63
return ret
60
64
} catch ( err ) {
0 commit comments