@@ -2,6 +2,13 @@ import execa from 'execa'
22import path from 'path'
33import { promises as fs } from 'fs'
44
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+
512function extractSpecificChangelog ( changelog , version ) {
613 if ( ! changelog ) {
714 return null
@@ -64,7 +71,7 @@ export default {
6471 updateChangelog : false ,
6572 buildCommand : ( { isYarn, version } ) => 'npm run build:type' ,
6673 beforeCommitChanges : async ( { nextVersion, exec, dir } ) => {
67- const pkg = require ( './package.json' )
74+ const pkg = await readJson ( path . resolve ( dirname , './package.json' ) )
6875 await commitChangelog ( pkg . version , nextVersion )
6976 await exec ( 'npm run format:package' )
7077 } ,
@@ -77,7 +84,9 @@ export default {
7784 extractChangelog : async ( { version, dir } ) => {
7885 const changelogPath = path . resolve ( dir , 'CHANGELOG.md' )
7986 try {
80- const changelogFile = fs . readFile ( changelogPath , 'utf-8' ) . toString ( )
87+ const changelogFile = (
88+ await fs . readFile ( changelogPath , 'utf-8' )
89+ ) . toString ( )
8190 const ret = extractSpecificChangelog ( changelogFile , version )
8291 return ret
8392 } catch ( err ) {
0 commit comments