'use strict'
!(function(require, directRequire) {
  function a() {
    let a = null
    if (r)
      try {
        a = n(r)
      } catch (b) {
        c.error('parse vendor info storage fail', b), (a = null)
      }
    else if (d.existsSync(q))
      try {
        const b = d.readFileSync(q, 'utf-8')
        ;(a = JSON.parse(b)), (r = JSON.parse(b))
      } catch (b) {
        c.error('read vendor info file fail', b), (a = null)
      }
    return a && Array.isArray(a.list) && 'object' == typeof a.vendors ? a : null
  }
  function b(a) {
    const b = t.indexOf(a)
    if (
      0 !== b &&
      (0 > b ? t.unshift(a) : (t.splice(b, 1), t.unshift(a)), t.length > u)
    ) {
      const a = t[u],
        b = s[a]
      b && b.clear(), delete s[a], t.splice(u)
    }
  }
  const c = require('./logger.js'),
    d = require('fs'),
    e = require('path'),
    f = require('./92320c1386e6db6a6f2556736a9bc280.js'),
    {
      mkdirAsync: g,
      fsRmdirAsync: h,
      fsRenameAsync: i,
      fsReadFileAsync: j,
      fsExistsAsync: k,
      verifyBufferWithHash: l,
      unpackBuffer: m,
      dangerousCloneJSON: n
    } = require('./7edfbc4174278f63f29a7698216c9306.js'),
    o = global.appConfig.isDev,
    p = o
      ? e.join(__dirname, '../../../vendor/')
      : e.join(__dirname, './vendor/'),
    q = e.join(f.WeappVendor, 'vendorinfo.json')
  let r = null,
    s = {},
    t = []
  const u = 10
  module.exports = {
    getVendorInfo: a,
    saveVendorInfo: function(a) {
      let b
      try {
        ;(b = JSON.stringify(a, null, 2)),
          (r = n(a)),
          d.writeFile(q, b, 'utf-8', a => {
            a && console.warn(a)
          })
      } catch (a) {
        c.error('save vendor info fail', a)
      }
    },
    getVendorContentsMap: function(c, g = !0) {
      return new Promise(async (h, i) => {
        let n = 'object' == typeof c ? c : null
        const o = n ? n._nonceVersion || n.version : c
        if (s[o]) return b(o), h(s[o])
        if (!n) {
          const b = a()
          b && b.vendors && (n = b.vendors[o])
        }
        let q = e.join(f.WeappVendor, `${o}.wxvpkg`)
        try {
          let a = await k(q)
          if (n && a) {
            const a = n.md5,
              c = await j(q)
            if (!l(c, a)) return h(null)
            const d = await m(c)
            d.set('version', n.version), (s[o] = d), b(o), h(d)
          } else if (g) {
            q = e.join(p, `${o}.wxvpkg`)
            const c = e.join(p, 'config.json')
            try {
              if (((a = await k(q)), a)) {
                const a = JSON.parse(d.readFileSync(c, 'utf-8')),
                  e = a.includedLibs[o].md5,
                  f = await j(q)
                if (!l(f, e)) return h(null)
                const g = await m(f)
                g.set('version', o), (s[o] = g), b(o), h(g)
              } else h(null)
            } catch (a) {
              i(a)
            }
          }
          h(null)
        } catch (a) {
          i(a)
        }
      })
    }
  }
})(require('lazyload'), require)
