This commit is contained in:
Automated 2020-11-11 11:40:36 +00:00
parent e3c946d422
commit d9392a17cf

160
dist/index.js vendored
View File

@ -8,78 +8,30 @@ module.exports =
const os = __webpack_require__(2087) const os = __webpack_require__(2087)
const path = __webpack_require__(5622) const path = __webpack_require__(5622)
const semver = __webpack_require__(1383) const semver = __webpack_require__(1383)
const get = __webpack_require__(2522).concat
const actions = __webpack_require__(2186) const actions = __webpack_require__(2186)
const cache = __webpack_require__(7784) const cache = __webpack_require__(7784)
const {
extForPlatform,
resolveCommit,
resolveVersion
} = __webpack_require__(3470)
function getJSON (opts) { async function downloadZig (platform, version) {
return new Promise((resolve, reject) => { const ext = extForPlatform(platform)
get({ ...opts, json: true }, (err, req, data) => {
if (err) {
reject(err)
} else {
resolve(data)
}
})
})
}
async function downloadZig (version) { const { downloadUrl, variantName } = version.includes('+')
const host = { ? resolveCommit(platform, version)
linux: 'x86_64-linux', : await resolveVersion(platform, version)
darwin: 'x86_64-macos',
win32: 'x86_64-windows'
}[os.platform()] || os.platform()
const ext = {
linux: 'tar.xz',
darwin: 'tar.xz',
win32: 'zip'
}[os.platform()]
if (version.includes('+')) { const downloadPath = await cache.downloadTool(downloadUrl)
// use exact commit hash const zigPath = ext === 'zip'
const addrhost = { ? await cache.extractZip(downloadPath)
linux: 'linux-x86_64', : await cache.extractTar(downloadPath, undefined, 'x')
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
}[os.platform()]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
const variantName = `zig-${addrhost}-${version}`
const downloadPath = await cache.downloadTool(downloadUrl) const binPath = path.join(zigPath, variantName)
const zigPath = ext === 'zip' const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
const binPath = path.join(zigPath, variantName) return cachePath
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
return cachePath
} else {
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null
const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${version} for platform ${host}`)
}
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
const downloadPath = await cache.downloadTool(meta[host].tarball)
const zigPath = ext === 'zip'
? await cache.extractZip(downloadPath)
: await cache.extractTar(downloadPath, undefined, 'x')
const binPath = path.join(zigPath, variantName)
const cachePath = await cache.cacheDir(binPath, 'zig', variantName)
return cachePath
}
} }
async function main () { async function main () {
@ -91,7 +43,7 @@ async function main () {
let zigPath = cache.find('zig', version) let zigPath = cache.find('zig', version)
if (!zigPath) { if (!zigPath) {
zigPath = await downloadZig(version) zigPath = await downloadZig(os.platform(), version)
} }
// Add the `zig` binary to the $PATH // Add the `zig` binary to the $PATH
@ -7546,6 +7498,82 @@ function wrappy (fn, cb) {
} }
/***/ }),
/***/ 3470:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
const path = __webpack_require__(5622)
const get = __webpack_require__(2522).concat
const semver = __webpack_require__(1383)
function extForPlatform (platform) {
return {
linux: 'tar.xz',
darwin: 'tar.xz',
win32: 'zip'
}[platform]
}
function resolveCommit (platform, version) {
const ext = extForPlatform(platform)
const addrhost = {
linux: 'linux-x86_64',
darwin: 'macos-x86_64',
win32: 'windows-x86_64'
}[platform]
const downloadUrl = `https://ziglang.org/builds/zig-${addrhost}-${version}.${ext}`
const variantName = `zig-${addrhost}-${version}`
return { downloadUrl, variantName }
}
function getJSON (opts) {
return new Promise((resolve, reject) => {
get({ ...opts, json: true }, (err, req, data) => {
if (err) {
reject(err)
} else {
resolve(data)
}
})
})
}
async function resolveVersion (platform, version) {
const ext = extForPlatform(platform)
const host = {
linux: 'x86_64-linux',
darwin: 'x86_64-macos',
win32: 'x86_64-windows'
}[platform] || platform
const index = await getJSON({ url: 'https://ziglang.org/download/index.json' })
const availableVersions = Object.keys(index)
const useVersion = semver.valid(version)
? semver.maxSatisfying(availableVersions.filter((v) => semver.valid(v)), version)
: null
const meta = index[useVersion || version]
if (!meta || !meta[host]) {
throw new Error(`Could not find version ${useVersion || version} for platform ${host}`)
}
const downloadUrl = meta[host].tarball
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '')
return { downloadUrl, variantName }
}
module.exports = {
extForPlatform,
resolveCommit,
resolveVersion
}
/***/ }), /***/ }),
/***/ 2357: /***/ 2357: