X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=_webi%2Fnormalize.js;h=fe614bd42651245a3465075fa4ee54c7b3b682a0;hb=60533161805deceeb6e6627614f358d9ccdb264f;hp=3003bb9f62de851deebfcecd950ae3c4ef72d207;hpb=84965a2207ca49c6e9413749930c6a73d6546088;p=webi-installers%2F.git diff --git a/_webi/normalize.js b/_webi/normalize.js index 3003bb9..fe614bd 100644 --- a/_webi/normalize.js +++ b/_webi/normalize.js @@ -28,25 +28,37 @@ formats.forEach(function (name) { // evaluation order matters // (i.e. otherwise x86 and x64 can cross match) var arches = [ - 'amd64', // first and most likely match + // arm 7 cannot be confused with arm64 + 'armv7l', + // amd64 is more likely than arm64 + 'amd64', + // arm6 has the same prefix as arm64 + 'armv6l', + // arm64 is more likely than arm6, and should be the default 'arm64', 'x86', 'ppc64le', 'ppc64', - 'armv7l', - 'armv6l', 's390x' ]; +// Used for detecting system arch from package download url, for example: +// +// https://git.com/org/foo/releases/v0.7.9/foo-aarch64-linux-musl.tar.gz +// https://git.com/org/foo/releases/v0.7.9/foo-arm-linux-musleabihf.tar.gz +// https://git.com/org/foo/releases/v0.7.9/foo-armv7-linux-musleabihf.tar.gz +// https://git.com/org/foo/releases/v0.7.9/foo-x86_64-linux-musl.tar.gz +// var archMap = { + armv7l: /(\b|_)(armv?7l?)/i, //amd64: /(amd.?64|x64|[_\-]64)/i, - amd64: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)64(\b|_)/i, + amd64: + /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)64([_\-]?bit)?(\b|_)/i, //x86: /(86)(\b|_)/i, - x86: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)(86|32)(\b|_)/i, + armv6l: /(\b|_)(aarch32|armv?6l?)(\b|_)/i, + arm64: /(\b|_)((aarch|arm)64|arm)/i, + x86: /(\b|_|amd|(dar)?win(dows)?|mac(os)?|linux|osx|x)(86|32)([_\-]?bit)(\b|_)/i, ppc64le: /(\b|_)(ppc64le)/i, ppc64: /(\b|_)(ppc64)(\b|_)/i, - arm64: /(\b|_)(arm64|arm)/i, - armv7l: /(\b|_)(armv?7l)/i, - armv6l: /(\b|_)(armv?6l)/i, s390x: /(\b|_)(s390x)/i }; arches.forEach(function (name) { @@ -71,6 +83,13 @@ function normalize(all) { return osMap[regKey].test(rel.name || rel.download); }) || 'unknown'; } + // Hacky-doo for musl + // TODO some sort of glibc vs musl tag? + if (!rel._musl) { + if (/(\b|\.|_|-)(musl)(\b|\.|_|-)/.test(rel.download)) { + rel._musl = true; + } + } supported.oses[rel.os] = true; if (!rel.arch) { @@ -80,10 +99,16 @@ function normalize(all) { rel.arch = arch; return true; } - })[0]; + }); + } + if (!rel.arch) { + if ('macos' === rel.os) { + rel.arch = 'amd64'; + } } supported.arches[rel.arch] = true; + var tarExt; if (!rel.ext) { // pkg-v1.0.tar.gz => ['gz', 'tar', '0', 'pkg-v1'] // pkg-v1.0.tar => ['tar', '0' ,'pkg-v1'] @@ -96,8 +121,10 @@ function normalize(all) { exts = exts.reverse().slice(0, 2); if ('tar' === exts[1]) { rel.ext = exts.reverse().join('.'); - } else if ('tgz' == exts[0]) { + tarExt = 'tar'; + } else if ('tgz' === exts[0]) { rel.ext = 'tar.gz'; + tarExt = 'tar'; } else { rel.ext = exts[0]; } @@ -106,7 +133,7 @@ function normalize(all) { rel.ext = 'exe'; } } - supported.formats[rel.ext] = true; + supported.formats[tarExt || rel.ext] = true; if (all.download) { rel.download = all.download.replace(/{{ download }}/, rel.download); @@ -127,6 +154,15 @@ function normalize(all) { } module.exports = normalize; +module.exports._debug = function (all) { + all = normalize(all); + all.releases = all.releases + .filter(function (r) { + return ['windows', 'macos', 'linux'].includes(r.os) && 'amd64' === r.arch; + }) + .slice(0, 10); + return all; +}; // NOT in order of priority (which would be tar, xz, zip, ...) module.exports.formats = formats; module.exports.arches = arches;