{"version":3,"sources":["jsdelivr-header.js","/npm/vite-plugin-mkcert@1.17.1/plugin/index.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/lib/constant.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/lib/util.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/index.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/lib/logger.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/config.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/lib/request.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/downloader.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/record.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/source.ts","/npm/vite-plugin-mkcert@1.17.1/plugin/mkcert/version.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,svBCNA,eAAA,GAAA,SAAA,eAAA,CAAA,WAAA,IAAA,WAAA,QAAA,IAAA,iBAAA,OAAA,QAAA,aAAA,gBAAA,IAAA,YAAgD,QAAA,QCAhD,UAAe,QAAA,QAAA,OACf,YAAiB,QAAA,QAAA,SAEJ,SAAW,qBAEX,YAAc,SAAS,QAAQ,KAAM,KAErC,gBAAkB,YAAA,QAAK,KAAK,UAAA,QAAG,UAAW,IAAI,YCP3D,qBAA2C,QAAA,QAAA,kBAC3C,cAAmB,QAAA,QAAA,WACnB,UAAe,QAAA,QAAA,OACf,WAAe,QAAA,QAAA,OACf,aAAiB,QAAA,QAAA,SACjB,YAAiB,QAAA,QAAA,SAUJ,OAAS,MAAO,IAC3B,IAEE,aADM,UAAA,QAAG,SAAS,OAAO,IAClB,CACT,OAAS,GACP,OAAO,CACT,GAGW,MAAQ,MAAO,UACJ,OAAO,UAGrB,UAAA,QAAG,SAAS,MAAM,EAAS,CAAE,WAAW,GAChD,EAGW,eAAiB,MAAO,EAAkB,GAAQ,KAC7D,MAAM,EAAU,EAAQ,aAAA,QAAK,QAAQ,GAAY,QA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1/dist/mkcert.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { createLogger, type PluginOption } from 'vite'\n\nimport { PLUGIN_NAME } from './lib/constant'\nimport { getDefaultHosts } from './lib/util'\nimport Mkcert, { MkcertBaseOptions } from './mkcert/index'\n\nexport { BaseSource, type SourceInfo } from './mkcert/source'\n\nexport type MkcertPluginOptions = MkcertBaseOptions & {\n  /**\n   * The hosts that needs to generate the certificate.\n   */\n  hosts?: string[]\n}\n\nconst plugin = (options: MkcertPluginOptions = {}): PluginOption => {\n  return {\n    name: PLUGIN_NAME,\n    apply: 'serve',\n    config: async ({ server = {}, logLevel }) => {\n      // v5.0 以下支持 boolean 类型的 https 配置\n      if (typeof server.https === 'boolean' && server.https === false) {\n        return\n      }\n\n      const { hosts = [], ...mkcertOptions } = options\n\n      const logger = createLogger(logLevel, {\n        prefix: PLUGIN_NAME\n      })\n      const mkcert = Mkcert.create({\n        logger,\n        ...mkcertOptions\n      })\n\n      await mkcert.init()\n\n      const allHosts = [...getDefaultHosts(), ...hosts]\n\n      if (typeof server.host === 'string') {\n        allHosts.push(server.host)\n      }\n\n      const uniqueHosts = Array.from(new Set(allHosts)).filter(Boolean)\n\n      const certificate = await mkcert.install(uniqueHosts)\n      const httpsConfig = {\n        key: certificate.key && Buffer.from(certificate.key),\n        cert: certificate.cert && Buffer.from(certificate.cert)\n      }\n\n      return {\n        server: {\n          https: httpsConfig\n        },\n        preview: {\n          https: httpsConfig\n        }\n      }\n    }\n  }\n}\n\nexport default plugin\n","import os from 'os'\nimport path from 'path'\n\nexport const PKG_NAME = 'vite-plugin-mkcert'\n\nexport const PLUGIN_NAME = PKG_NAME.replace(/-/g, ':')\n\nexport const PLUGIN_DATA_DIR = path.join(os.homedir(), `.${PKG_NAME}`)\n","import child_process, { ExecOptions } from 'child_process'\nimport crypto from 'crypto'\nimport fs from 'fs'\nimport os from 'os'\nimport path from 'path'\nimport util from 'util'\n\nimport { PLUGIN_NAME } from './constant'\n\n/**\n * Check if file exists\n *\n * @param filePath file path\n * @returns does the file exist\n */\nexport const exists = async (filePath: string) => {\n  try {\n    await fs.promises.access(filePath)\n    return true\n  } catch (error) {\n    return false\n  }\n}\n\nexport const mkdir = async (dirname: string) => {\n  const isExist = await exists(dirname)\n\n  if (!isExist) {\n    await fs.promises.mkdir(dirname, { recursive: true })\n  }\n}\n\nexport const ensureDirExist = async (filePath: string, strip = false) => {\n  const dirname = strip ? path.dirname(filePath) : filePath\n  await mkdir(dirname)\n}\n\nexport const readFile = async (filePath: string) => {\n  const isExist = await exists(filePath)\n  return isExist ? (await fs.promises.readFile(filePath)).toString() : undefined\n}\n\nexport const writeFile = async (\n  filePath: string,\n  data: string | Uint8Array\n) => {\n  await ensureDirExist(filePath, true)\n  await fs.promises.writeFile(filePath, data)\n  await fs.promises.chmod(filePath, 0o777)\n}\n\nexport const readDir = async (source: string) => {\n  return fs.promises.readdir(source)\n}\n\nexport const copyDir = async (source: string, dest: string) => {\n  try {\n    await fs.promises.cp(source, dest, {\n      recursive: true\n    })\n  } catch (error: any) {\n    // Fails when nodejs version < 16.7.0, ignore?\n    console.log(`${PLUGIN_NAME}:`, error)\n  }\n}\n\nexport const exec = async (cmd: string, options?: ExecOptions) => {\n  return util.promisify(child_process.exec)(cmd, options)\n}\n\n/**\n * http://nodejs.cn/api/os/os_networkinterfaces.html\n */\nconst isIPV4 = (family: string | number) => {\n  return family === 'IPv4' || family === 4\n}\n\nexport const getLocalV4Ips = () => {\n  const interfaceDict = os.networkInterfaces()\n  const addresses: string[] = []\n  for (const key in interfaceDict) {\n    const interfaces = interfaceDict[key]\n    if (interfaces) {\n      for (const item of interfaces) {\n        if (isIPV4(item.family)) {\n          addresses.push(item.address)\n        }\n      }\n    }\n  }\n\n  return addresses\n}\n\nexport const getDefaultHosts = () => {\n  return ['localhost', ...getLocalV4Ips()]\n}\n\nexport const getHash = async (filePath: string) => {\n  const content = await readFile(filePath)\n\n  if (content) {\n    const hash = crypto.createHash('sha256')\n    hash.update(content)\n    return hash.digest('hex')\n  }\n\n  return undefined\n}\n\nconst isObj = (obj: any) =>\n  Object.prototype.toString.call(obj) === '[object Object]'\n\nconst mergeObj = (target: any, source: any) => {\n  if (!(isObj(target) && isObj(source))) {\n    return target\n  }\n\n  for (const key in source) {\n    if (Object.prototype.hasOwnProperty.call(source, key)) {\n      const targetValue = target[key]\n      const sourceValue = source[key]\n\n      if (isObj(targetValue) && isObj(sourceValue)) {\n        mergeObj(targetValue, sourceValue)\n      } else {\n        target[key] = sourceValue\n      }\n    }\n  }\n}\n\nexport const deepMerge = (target: any, ...source: any[]) => {\n  return source.reduce((a, b) => mergeObj(a, b), target)\n}\n\nexport const prettyLog = (obj?: Record<string, any>) => {\n  return JSON.stringify(obj, null, 2)\n}\n\nexport const escape = (path?: string) => {\n  return `\"${path}\"`\n}\n","import path from 'path'\nimport process from 'process'\n\nimport pc from 'picocolors'\nimport { Logger } from 'vite'\n\nimport { PLUGIN_DATA_DIR } from '../lib/constant'\nimport { debug } from '../lib/logger'\nimport {\n  copyDir,\n  ensureDirExist,\n  escape,\n  exec,\n  exists,\n  getHash,\n  prettyLog,\n  readDir,\n  readFile\n} from '../lib/util'\n\nimport Config from './config'\nimport Downloader from './downloader'\nimport Record from './record'\nimport { BaseSource, GithubSource, CodingSource } from './source'\nimport VersionManger from './version'\n\nexport type SourceType = 'github' | 'coding' | BaseSource\n\nexport type MkcertBaseOptions = {\n  /**\n   * Whether to force generate\n   */\n  force?: boolean\n\n  /**\n   * Automatically upgrade mkcert\n   *\n   * @default false\n   */\n  autoUpgrade?: boolean\n\n  /**\n   * Specify mkcert download source\n   *\n   * @default github\n   */\n  source?: SourceType\n\n  /**\n   * If your network is restricted, you can specify a local binary file instead of downloading, it should be an absolute path\n   *\n   * @default none\n   */\n  mkcertPath?: string\n\n  /**\n   * The location to save the files, such as key and cert files\n   */\n  savePath?: string\n\n  /**\n   * The name of private key file generated by mkcert\n   */\n  keyFileName?: string\n\n  /**\n   * The name of cert file generated by mkcert\n   */\n  certFileName?: string\n}\n\nexport type MkcertOptions = MkcertBaseOptions & {\n  logger: Logger\n}\n\nclass Mkcert {\n  private force?: boolean\n  private autoUpgrade?: boolean\n  private sourceType: SourceType\n  private savePath: string\n  private logger: Logger\n\n  private source: BaseSource\n  private localMkcert?: string\n  private savedMkcert: string\n  private keyFilePath: string\n  private certFilePath: string\n\n  private config: Config\n\n  public static create(options: MkcertOptions) {\n    return new Mkcert(options)\n  }\n\n  private constructor(options: MkcertOptions) {\n    const {\n      force,\n      autoUpgrade,\n      source,\n      mkcertPath,\n      savePath = PLUGIN_DATA_DIR,\n      keyFileName = 'dev.pem',\n      certFileName = 'cert.pem',\n      logger\n    } = options\n\n    this.force = force\n    this.logger = logger\n    this.autoUpgrade = autoUpgrade\n    this.localMkcert = mkcertPath\n    this.savePath = path.resolve(savePath)\n    this.keyFilePath = path.resolve(savePath, keyFileName)\n    this.certFilePath = path.resolve(savePath, certFileName)\n    this.sourceType = source || 'github'\n\n    if (this.sourceType === 'github') {\n      this.source = GithubSource.create()\n    } else if (this.sourceType === 'coding') {\n      this.source = CodingSource.create()\n    } else {\n      this.source = this.sourceType\n    }\n\n    this.savedMkcert = path.resolve(\n      savePath,\n      process.platform === 'win32' ? 'mkcert.exe' : 'mkcert'\n    )\n\n    this.config = new Config({ savePath: this.savePath })\n  }\n\n  private async getMkcertBinary() {\n    let binary\n\n    if (this.localMkcert) {\n      if (await exists(this.localMkcert)) {\n        binary = this.localMkcert\n      } else {\n        this.logger.error(\n          pc.red(\n            `${this.localMkcert} does not exist, please check the mkcertPath parameter`\n          )\n        )\n      }\n    } else if (await exists(this.savedMkcert)) {\n      binary = this.savedMkcert\n    }\n    return binary ? escape(binary) : undefined\n  }\n\n  private async checkCAExists() {\n    const files = await readDir(this.savePath)\n    return files.some(file => file.includes('rootCA'))\n  }\n\n  private async retainExistedCA() {\n    if (await this.checkCAExists()) {\n      return\n    }\n\n    const mkcertBinary = await this.getMkcertBinary()\n    const commandStatement = `${mkcertBinary} -CAROOT`\n\n    debug(`Exec ${commandStatement}`)\n\n    const commandResult = await exec(commandStatement)\n    const caDirPath = path.resolve(\n      commandResult.stdout.toString().replace(/\\n/g, '')\n    )\n\n    if (caDirPath === this.savePath) {\n      return\n    }\n\n    const caDirExists = await exists(caDirPath)\n\n    if (!caDirExists) {\n      return\n    }\n\n    await copyDir(caDirPath, this.savePath)\n  }\n\n  private async getCertificate() {\n    const key = await readFile(this.keyFilePath)\n    const cert = await readFile(this.certFilePath)\n\n    return {\n      key,\n      cert\n    }\n  }\n\n  private async createCertificate(hosts: string[]) {\n    const names = hosts.join(' ')\n    const mkcertBinary = await this.getMkcertBinary()\n\n    if (!mkcertBinary) {\n      debug(\n        `Mkcert does not exist, unable to generate certificate for ${names}`\n      )\n    }\n\n    await ensureDirExist(this.savePath)\n    await this.retainExistedCA()\n\n    const cmd = `${mkcertBinary} -install -key-file ${escape(\n      this.keyFilePath\n    )} -cert-file ${escape(this.certFilePath)} ${names}`\n\n    await exec(cmd, {\n      env: {\n        ...process.env,\n        CAROOT: this.savePath,\n        JAVA_HOME: undefined\n      }\n    })\n\n    this.logger.info(\n      `The list of generated files:\\n${this.keyFilePath}\\n${this.certFilePath}`\n    )\n  }\n\n  private getLatestHash = async () => {\n    return {\n      key: await getHash(this.keyFilePath),\n      cert: await getHash(this.certFilePath)\n    }\n  }\n\n  private async regenerate(record: Record, hosts: string[]) {\n    await this.createCertificate(hosts)\n\n    const hash = await this.getLatestHash()\n\n    record.update({ hosts, hash })\n  }\n\n  public async init() {\n    await ensureDirExist(this.savePath)\n    await this.config.init()\n\n    const mkcertBinary = await this.getMkcertBinary()\n\n    if (!mkcertBinary) {\n      await this.initMkcert()\n    } else if (this.autoUpgrade) {\n      await this.upgradeMkcert()\n    }\n  }\n\n  private async getSourceInfo() {\n    const sourceInfo = await this.source.getSourceInfo()\n\n    if (!sourceInfo) {\n      const message =\n        typeof this.sourceType === 'string'\n          ? `Unsupported platform. Unable to find a binary file for ${\n              process.platform\n            } platform with ${process.arch} arch on ${\n              this.sourceType === 'github'\n                ? 'https://github.com/FiloSottile/mkcert/releases'\n                : 'https://liuweigl.coding.net/p/github/artifacts?hash=8d4dd8949af543159c1b5ac71ff1ff72'\n            }`\n          : 'Please check your custom \"source\", it seems to return invalid result'\n      throw new Error(message)\n    }\n\n    return sourceInfo\n  }\n\n  private async initMkcert() {\n    const sourceInfo = await this.getSourceInfo()\n\n    debug('The mkcert does not exist, download it now')\n\n    await this.downloadMkcert(sourceInfo.downloadUrl, this.savedMkcert)\n  }\n\n  private async upgradeMkcert() {\n    const versionManger = new VersionManger({ config: this.config })\n    const sourceInfo = await this.getSourceInfo()\n\n    if (!sourceInfo) {\n      this.logger.error(\n        'Can not obtain download information of mkcert, update skipped'\n      )\n      return\n    }\n\n    const versionInfo = versionManger.compare(sourceInfo.version)\n\n    if (!versionInfo.shouldUpdate) {\n      debug('Mkcert is kept latest version, update skipped')\n      return\n    }\n\n    if (versionInfo.breakingChange) {\n      debug(\n        'The current version of mkcert is %s, and the latest version is %s, there may be some breaking changes, update skipped',\n        versionInfo.currentVersion,\n        versionInfo.nextVersion\n      )\n      return\n    }\n\n    debug(\n      'The current version of mkcert is %s, and the latest version is %s, mkcert will be updated',\n      versionInfo.currentVersion,\n      versionInfo.nextVersion\n    )\n\n    await this.downloadMkcert(sourceInfo.downloadUrl, this.savedMkcert)\n    versionManger.update(versionInfo.nextVersion)\n  }\n\n  private async downloadMkcert(sourceUrl: string, distPath: string) {\n    const downloader = Downloader.create()\n    await downloader.download(sourceUrl, distPath)\n  }\n\n  public async renew(hosts: string[]) {\n    const record = new Record({ config: this.config })\n\n    if (this.force) {\n      debug(`Certificate is forced to regenerate`)\n\n      await this.regenerate(record, hosts)\n    }\n\n    if (!record.contains(hosts)) {\n      debug(\n        `The hosts changed from [${record.getHosts()}] to [${hosts}], start regenerate certificate`\n      )\n\n      await this.regenerate(record, hosts)\n      return\n    }\n\n    const hash = await this.getLatestHash()\n\n    if (!record.equal(hash)) {\n      debug(\n        `The hash changed from ${prettyLog(record.getHash())} to ${prettyLog(\n          hash\n        )}, start regenerate certificate`\n      )\n\n      await this.regenerate(record, hosts)\n      return\n    }\n\n    debug('Neither hosts nor hash has changed, skip regenerate certificate')\n  }\n\n  /**\n   * Get certificates\n   *\n   * @param hosts host collection\n   * @returns cretificates\n   */\n  public async install(hosts: string[]) {\n    if (hosts.length) {\n      await this.renew(hosts)\n    }\n\n    return await this.getCertificate()\n  }\n}\n\nexport default Mkcert\n","import Debug from 'debug'\n\nimport { PLUGIN_NAME } from './constant'\n\nexport const debug = Debug(PLUGIN_NAME)\n","import path from 'path'\n\nimport { debug } from '../lib/logger'\nimport { readFile, writeFile, prettyLog, deepMerge } from '../lib/util'\n\nexport type RecordMate = {\n  /**\n   * The hosts that have generated certificate\n   */\n  hosts: string[]\n\n  /**\n   * file hash\n   */\n  hash?: RecordHash\n}\n\nexport type RecordHash = {\n  key?: string\n  cert?: string\n}\n\nexport type ConfigOptions = {\n  savePath: string\n}\n\nconst CONFIG_FILE_NAME = 'config.json'\n\nclass Config {\n  /**\n   * The mkcert version\n   */\n  private version: string | undefined\n\n  private record: RecordMate | undefined\n\n  private configFilePath: string\n\n  constructor({ savePath }: ConfigOptions) {\n    this.configFilePath = path.resolve(savePath, CONFIG_FILE_NAME)\n  }\n\n  public async init() {\n    const str = await readFile(this.configFilePath)\n    const options = str ? JSON.parse(str) : undefined\n\n    if (options) {\n      this.version = options.version\n      this.record = options.record\n    }\n  }\n\n  private async serialize() {\n    await writeFile(this.configFilePath, prettyLog(this))\n  }\n\n  // deep merge\n  public async merge(obj: Record<string, any>) {\n    const currentStr = prettyLog(this)\n\n    deepMerge(this, obj)\n\n    const nextStr = prettyLog(this)\n\n    debug(\n      `Receive parameter\\n ${prettyLog(\n        obj\n      )}\\nUpdate config from\\n ${currentStr} \\nto\\n ${nextStr}`\n    )\n\n    await this.serialize()\n  }\n\n  public getRecord() {\n    return this.record\n  }\n\n  public getVersion() {\n    return this.version\n  }\n}\n\nexport default Config\n","import axios from 'axios'\n\nimport { debug } from './logger'\n\nconst request = axios.create()\n\nrequest.interceptors.response.use(\n  res => {\n    return res\n  },\n  error => {\n    debug('Request error: %o', error)\n    return Promise.reject(error)\n  }\n)\n\nexport default request\n","import { debug } from '../lib/logger'\nimport request from '../lib/request'\nimport { writeFile } from '../lib/util'\n\nclass Downloader {\n  public static create() {\n    return new Downloader()\n  }\n\n  private constructor() {}\n\n  public async download(downloadUrl: string, savedPath: string) {\n    debug('Downloading the mkcert executable from %s', downloadUrl)\n\n    const { data } = await request.get(downloadUrl, {\n      responseType: 'arraybuffer'\n    })\n\n    await writeFile(savedPath, data)\n\n    debug('The mkcert has been saved to %s', savedPath)\n  }\n}\n\nexport default Downloader\n","import Config, { RecordHash, RecordMate } from './config'\n\nexport type RecordProps = {\n  config: Config\n}\nclass Record {\n  private config: Config\n\n  constructor(options: RecordProps) {\n    this.config = options.config\n  }\n\n  public getHosts() {\n    return this.config.getRecord()?.hosts\n  }\n\n  public getHash() {\n    return this.config.getRecord()?.hash\n  }\n\n  public contains(hosts: string[]) {\n    const oldHosts = this.getHosts()\n\n    if (!oldHosts) {\n      return false\n    }\n\n    // require hosts is subset of oldHosts\n    for (const host of hosts) {\n      if (!oldHosts.includes(host)) {\n        return false\n      }\n    }\n\n    return true\n  }\n\n  // whether the files has been tampered with\n  public equal(hash: RecordHash) {\n    const oldHash = this.getHash()\n\n    if (!oldHash) {\n      return false\n    }\n\n    return oldHash.key === hash.key && oldHash.cert === hash.cert\n  }\n\n  public async update(record: RecordMate) {\n    await this.config.merge({ record })\n  }\n}\n\nexport default Record\n","import { Octokit } from '@octokit/rest'\n\nimport request from '../lib/request'\n\nexport type SourceInfo = {\n  version: string\n  downloadUrl: string\n}\n\nexport abstract class BaseSource {\n  abstract getSourceInfo(): Promise<SourceInfo | undefined>\n\n  protected getPlatformIdentifier() {\n    const arch = process.arch === 'x64' ? 'amd64' : process.arch\n    return process.platform === 'win32'\n      ? `windows-${arch}.exe`\n      : `${process.platform}-${arch}`\n  }\n}\n\n/**\n * Download mkcert from github.com\n */\nexport class GithubSource extends BaseSource {\n  public static create() {\n    return new GithubSource()\n  }\n\n  private constructor() {\n    super()\n  }\n\n  public async getSourceInfo(): Promise<SourceInfo | undefined> {\n    const octokit = new Octokit()\n    const { data } = await octokit.repos.getLatestRelease({\n      owner: 'FiloSottile',\n      repo: 'mkcert'\n    })\n    const platformIdentifier = this.getPlatformIdentifier()\n\n    const version = data.tag_name\n    const downloadUrl = data.assets.find(item =>\n      item.name.includes(platformIdentifier)\n    )?.browser_download_url\n\n    if (!(version && downloadUrl)) {\n      return undefined\n    }\n\n    return {\n      downloadUrl,\n      version\n    }\n  }\n}\n\n/**\n * Download mkcert from coding.net\n *\n * @see https://help.coding.net/openapi\n */\nexport class CodingSource extends BaseSource {\n  public static CODING_API = 'https://e.coding.net/open-api'\n  public static CODING_AUTHORIZATION =\n    'token 000f7831ec425079439b0f55f55c729c9280d66e'\n  public static CODING_PROJECT_ID = 8524617\n  public static REPOSITORY = 'mkcert'\n\n  public static create() {\n    return new CodingSource()\n  }\n\n  private constructor() {\n    super()\n  }\n\n  private async request(data: any) {\n    return request({\n      data,\n      method: 'POST',\n      url: CodingSource.CODING_API,\n      headers: {\n        Authorization: CodingSource.CODING_AUTHORIZATION\n      }\n    })\n  }\n\n  /**\n   * Get filename of Coding.net artifacts\n   *\n   * @see https://liuweigl.coding.net/p/github/artifacts/885241/generic/packages\n   *\n   * @returns name\n   */\n  private getPackageName() {\n    return `mkcert-${this.getPlatformIdentifier()}`\n  }\n\n  async getSourceInfo(): Promise<SourceInfo | undefined> {\n    /**\n     * @see https://help.coding.net/openapi#e2106ec64e75af66f188463b1bb7e165\n     */\n    const { data: VersionData } = await this.request({\n      Action: 'DescribeArtifactVersionList',\n      ProjectId: CodingSource.CODING_PROJECT_ID,\n      Repository: CodingSource.REPOSITORY,\n      Package: this.getPackageName(),\n      PageSize: 1\n    })\n\n    const version = VersionData.Response.Data?.InstanceSet[0]?.Version\n\n    if (!version) {\n      return undefined\n    }\n\n    /**\n     * @see https://help.coding.net/openapi#63ad6bc7469373cef575e92bb92be71e\n     */\n    const { data: FileData } = await this.request({\n      Action: 'DescribeArtifactFileDownloadUrl',\n      ProjectId: CodingSource.CODING_PROJECT_ID,\n      Repository: CodingSource.REPOSITORY,\n      Package: this.getPackageName(),\n      PackageVersion: version\n    })\n\n    const downloadUrl = FileData.Response.Url\n\n    if (!downloadUrl) {\n      return undefined\n    }\n\n    return {\n      downloadUrl,\n      version\n    }\n  }\n}\n","import { debug } from '../lib/logger'\n\nimport Config from './config'\n\nexport type VersionMangerProps = {\n  config: Config\n}\n\nconst parseVersion = (version: string) => {\n  const str = version.trim().replace(/v/i, '')\n\n  return str.split('.')\n}\n\nclass VersionManger {\n  private config: Config\n\n  public constructor(props: VersionMangerProps) {\n    this.config = props.config\n  }\n\n  public async update(version: string) {\n    try {\n      await this.config.merge({ version })\n    } catch (err) {\n      debug('Failed to record mkcert version info: %o', err)\n    }\n  }\n\n  public compare(version: string) {\n    const currentVersion = this.config.getVersion()\n\n    if (!currentVersion) {\n      return {\n        currentVersion,\n        nextVersion: version,\n        breakingChange: false,\n        shouldUpdate: true\n      }\n    }\n\n    let breakingChange = false\n    let shouldUpdate = false\n\n    const newVersion = parseVersion(version)\n    const oldVersion = parseVersion(currentVersion)\n\n    for (let i = 0; i < newVersion.length; i++) {\n      if (newVersion[i] > oldVersion[i]) {\n        shouldUpdate = true\n        breakingChange = i === 0\n        break\n      }\n    }\n    return {\n      breakingChange,\n      shouldUpdate,\n      currentVersion,\n      nextVersion: version\n    }\n  }\n}\n\nexport default VersionManger\n"]}