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