@@ -2,6 +2,13 @@ import execa from 'execa'
2
2
import path from 'path'
3
3
import { promises as fs } from 'fs'
4
4
5
+ const dirname = path . dirname ( new URL ( import . meta. url ) . pathname )
6
+
7
+ async function readJson ( target ) {
8
+ const file = await fs . readFile ( target , 'utf8' )
9
+ return JSON . parse ( file )
10
+ }
11
+
5
12
function extractSpecificChangelog ( changelog , version ) {
6
13
if ( ! changelog ) {
7
14
return null
@@ -64,7 +71,7 @@ export default {
64
71
updateChangelog : false ,
65
72
buildCommand : ( { isYarn, version } ) => 'npm run build:type' ,
66
73
beforeCommitChanges : async ( { nextVersion, exec, dir } ) => {
67
- const pkg = require ( './package.json' )
74
+ const pkg = await readJson ( path . resolve ( dirname , './package.json' ) )
68
75
await commitChangelog ( pkg . version , nextVersion )
69
76
await exec ( 'npm run format:package' )
70
77
} ,
@@ -77,7 +84,9 @@ export default {
77
84
extractChangelog : async ( { version, dir } ) => {
78
85
const changelogPath = path . resolve ( dir , 'CHANGELOG.md' )
79
86
try {
80
- const changelogFile = fs . readFile ( changelogPath , 'utf-8' ) . toString ( )
87
+ const changelogFile = (
88
+ await fs . readFile ( changelogPath , 'utf-8' )
89
+ ) . toString ( )
81
90
const ret = extractSpecificChangelog ( changelogFile , version )
82
91
return ret
83
92
} catch ( err ) {
0 commit comments