Skip to content

Commit

Permalink
fix: not working if the mkcert in directory with special charaters
Browse files Browse the repository at this point in the history
close #61
  • Loading branch information
liuweiGL committed Feb 16, 2023
1 parent 3ebe393 commit e3a5b63
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions plugin/mkcert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,23 @@ class Mkcert {
}

private async getMkcertBinnary() {
let binnary

if (this.localMkcert) {
if (await exists(this.localMkcert)) {
return this.localMkcert
}
this.logger.error(
pc.red(
`${this.localMkcert} does not exist, please check the mkcertPath parameter`
binnary = this.localMkcert
} else {
this.logger.error(
pc.red(
`${this.localMkcert} does not exist, please check the mkcertPath parameter`
)
)
)
return undefined
}
} else if (await exists(this.savedMkcert)) {
return this.savedMkcert
binnary = this.savedMkcert
}
return undefined

return escape(binnary)
}

private async checkCAExists() {
Expand All @@ -157,7 +160,11 @@ class Mkcert {
}

const mkcertBinnary = await this.getMkcertBinnary()
const commandResult = await exec(`${mkcertBinnary} -CAROOT`)
const commandStatement = `${mkcertBinnary} -CAROOT`

debug(`Exec ${commandStatement}`)

const commandResult = await exec(commandStatement)
const caDirPath = path.resolve(
commandResult.stdout.toString().replaceAll('\n', '')
)
Expand Down Expand Up @@ -187,7 +194,6 @@ class Mkcert {

private async createCertificate(hosts: string[]) {
const names = hosts.join(' ')

const mkcertBinnary = await this.getMkcertBinnary()

if (!mkcertBinnary) {
Expand All @@ -199,7 +205,7 @@ class Mkcert {
await ensureDirExist(this.savePath)
await this.retainExistedCA()

const cmd = `${escape(mkcertBinnary)} -install -key-file ${escape(
const cmd = `${mkcertBinnary} -install -key-file ${escape(
this.keyFilePath
)} -cert-file ${escape(this.certFilePath)} ${names}`

Expand Down

0 comments on commit e3a5b63

Please sign in to comment.