Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mkcert binary download failed on the first time #13

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions packages/plugin/src/mkcert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class Mkcert {

public async init() {
await this.config.init()

if (this.autoUpgrade || !(await this.checkMkcert())) {
await this.updateMkcert()
const exist = await this.checkMkcert()
if (this.autoUpgrade || !exist) {
await this.updateMkcert(exist)
}
}

public async updateMkcert() {
public async updateMkcert(mkcertExist: boolean) {
const versionManger = new VersionManger({ config: this.config })
const sourceInfo = await this.source.getSourceInfo()

Expand All @@ -189,33 +189,44 @@ class Mkcert {
return
}

const versionInfo = await versionManger.compare(sourceInfo.version)
// if binary exist, compare version
if (mkcertExist) {
const versionInfo = versionManger.compare(sourceInfo.version)

if (!versionInfo.shouldUpdate) {
debug('Mkcert is kept latest version, update skipped')
return
}
if (!versionInfo.shouldUpdate) {
debug('Mkcert is kept latest version, update skipped')
return
}

if (versionInfo.breakingChange) {
debug(
'The current version of mkcert is %s, and the latest version is %s, there may be some breaking changes, update skipped',
versionInfo.currentVersion,
versionInfo.nextVersion
)
return
}

if (versionInfo.breakingChange) {
debug(
'The current version of mkcert is %s, and the latest version is %s, there may be some breaking changes, update skipped',
'The current version of mkcert is %s, and the latest version is %s, mkcert will be updated',
versionInfo.currentVersion,
versionInfo.nextVersion
)
return
}

debug(
'The current version of mkcert is %s, and the latest version is %s, mkcert will be updated',
versionInfo.currentVersion,
versionInfo.nextVersion
)
await this.downloadMkcert(sourceInfo.downloadUrl, this.mkcertSavedPath)
versionManger.update(versionInfo.nextVersion)

} else {
debug('mkcert does not exist, download it now')

versionManger.update(versionInfo.nextVersion)
await this.downloadMkcert(sourceInfo.downloadUrl, this.mkcertSavedPath)
versionManger.update(sourceInfo.version)
}
}

public async downloadMkcert(sourceUrl: string, distPath: string) {
const downloader = Downloader.create()

await downloader.download(sourceInfo.downloadUrl, this.mkcertSavedPath)
await downloader.download(sourceUrl, distPath)
}

public async renew(hosts: string[]) {
Expand Down