Skip to content

Commit fcd186e

Browse files
committed
update shipjs config
1 parent a1637c5 commit fcd186e

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@intlify/shared": "^9.1.9",
3333
"chalk": "^4.1.0",
3434
"debug": "^4.3.2",
35+
"execa": "^5.1.1",
3536
"glob": "^7.2.0",
3637
"pathe": "^0.2.0",
3738
"yargs": "^17.2.0"

pnpm-lock.yaml

Lines changed: 2 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ship.config.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
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+
}
711

812
function extractSpecificChangelog(changelog, version) {
913
if (!changelog) {
@@ -31,17 +35,17 @@ async function commitChangelog(current, next) {
3135
)
3236
const matches = regex.exec(stdout.toString())
3337
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}`)
3640
}
3741

3842
module.exports = {
3943
mergeStrategy: { toSameBranch: ['master'] },
4044
monorepo: undefined,
4145
updateChangelog: false,
4246
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'))
4549
commitChangelog(pkg.version, nextVersion).then(resolve)
4650
})
4751
},
@@ -51,10 +55,10 @@ module.exports = {
5155
`${releaseType} release v${version}`,
5256
shouldRelease: () => true,
5357
releases: {
54-
extractChangelog: ({ version, dir }) => {
58+
extractChangelog: async ({ version, dir }) => {
5559
const changelogPath = path.resolve(dir, 'CHANGELOG.md')
5660
try {
57-
const changelogFile = fs.readFileSync(changelogPath, 'utf-8').toString()
61+
const changelogFile = await fs.readFile(changelogPath, 'utf8')
5862
const ret = extractSpecificChangelog(changelogFile, version)
5963
return ret
6064
} catch (err) {

0 commit comments

Comments
 (0)