Compare commits

..

48 Commits

Author SHA1 Message Date
AJ ONeal
f0471206ec chore: update deps 2023-12-28 02:05:21 -07:00
AJ ONeal
d0c0805a1f f: update build classifier 2023-12-28 02:05:21 -07:00
AJ ONeal
edfb064075 WIPPY WIP: add todo for next test 2023-12-28 02:05:21 -07:00
AJ ONeal
22d48c12cb f: match hosts 2023-12-28 02:05:20 -07:00
AJ ONeal
3b3df248d1 f: match hosts 2023-12-28 02:05:20 -07:00
AJ ONeal
00e828645b feat: match hosts to builds 2023-12-28 02:05:20 -07:00
AJ ONeal
9b9dc6d4c9 feat: add pkg.triplets when classifying 2023-12-28 02:05:20 -07:00
AJ ONeal
5509686fba f: versions: assign 2023-12-28 02:05:20 -07:00
AJ ONeal
76e21b6e0a f: versions: unshift 2023-12-28 02:05:20 -07:00
AJ ONeal
060f9b7026 feat(builds): add pkg.versions 2023-12-28 02:05:20 -07:00
AJ ONeal
f28bd86ce8 wip: get builds for a given target 2023-12-28 02:05:19 -07:00
AJ ONeal
d4458c1076 wip: get builds for a given target 2023-12-28 02:05:19 -07:00
AJ ONeal
619d77c6fa chore(builds): remove dead comment cruft 2023-12-28 02:05:19 -07:00
AJ ONeal
0111df7bb7 fix(builds): include explicit target as part of build id 2023-12-28 02:05:19 -07:00
AJ ONeal
ce9c111fa9 WIPPY WIP: feat: create builds tree 2023-12-28 02:05:19 -07:00
AJ ONeal
48ca227feb f: update build-classifier 2023-12-28 02:05:19 -07:00
AJ ONeal
8d8f809563 wip: create build groups by os, arch+libc 2023-12-28 02:05:19 -07:00
AJ ONeal
70121fc60c WIP: todos for the next thing 2023-12-28 02:05:19 -07:00
AJ ONeal
d0d2dce17c ref: termsToTriplet => termsToTarget 2023-12-28 02:05:18 -07:00
AJ ONeal
1eb28c7d22 f: rename buildId with @ 2023-12-28 02:05:18 -07:00
AJ ONeal
c6fe0f7fb6 fix: mipsXle => mipsXel, ppcXel => ppcXle 2023-12-28 02:05:18 -07:00
AJ ONeal
fb74b98960 fix: ppc64el => ppc64le 2023-12-28 02:05:18 -07:00
AJ ONeal
867fe16f27 fix: mipsle => mipsel 2023-12-28 02:05:18 -07:00
AJ ONeal
40766bea4c feat: cold-boot caching w/ lazy warm stale refreshes 2023-12-28 02:05:18 -07:00
AJ ONeal
65c27afe49 f: make parallel requests 2023-12-28 02:05:18 -07:00
AJ ONeal
36c3de2ffc f: move cacher functions 2023-12-28 02:05:17 -07:00
AJ ONeal
1b10b18454 f: move cacher functions 2023-12-28 02:05:17 -07:00
AJ ONeal
8abff3f0b9 f: separate build linter from classifier lib 2023-12-28 02:05:17 -07:00
AJ ONeal
14bb497303 f: move state 2023-12-28 02:05:17 -07:00
AJ ONeal
2a785a86dc f: rewrite 2023-12-28 02:05:17 -07:00
AJ ONeal
1d3f733cc4 f: refactor names 2023-12-28 02:05:17 -07:00
AJ ONeal
1f1ea2b8ba f: refactor names 2023-12-28 02:05:17 -07:00
AJ ONeal
8f92da28bb f: show unused terms, make importable 2023-12-28 02:05:17 -07:00
AJ ONeal
d102f18480 f: move triplet classification to own repo 2023-12-28 02:05:16 -07:00
AJ ONeal
e85db4ecc4 f: name refactor 2023-12-28 02:05:16 -07:00
AJ ONeal
f5b1de7751 f: simplify fetch, show triplets 2023-12-28 02:05:16 -07:00
AJ ONeal
f93ca34e68 f: JSON.stringify(data, null, 2) 2023-12-28 02:05:16 -07:00
AJ ONeal
de92e02bb1 wip: update classifier submodule to latest 2023-12-28 02:05:16 -07:00
AJ ONeal
c11bc55d5b WIP: new caching releases fetcher 2023-12-28 02:05:16 -07:00
AJ ONeal
f24df1a731 feat: add target triplet classifier 2023-12-28 02:05:16 -07:00
AJ ONeal
fca66feb3e feat: list all releases across all of Webi 2023-12-28 02:05:15 -07:00
AJ ONeal
7bb8040404 fix(ollama-darwin): filter out .app, manually set arch for universal 2023-12-28 02:04:26 -07:00
AJ ONeal
3ae143e48b fix(goreleaser): handle extraneous build term '1' 2023-12-28 02:04:26 -07:00
AJ ONeal
2cd242c945 fix(watchexec): remove 'cli-' prefix from literal version 2023-12-28 02:04:26 -07:00
AJ ONeal
5b32ecdf08 ref(shellcheck): remove superfluous target matching 2023-12-28 02:04:26 -07:00
AJ ONeal
6b25145795 fix(zoxide): remove incorrect arch detection 2023-12-28 02:04:26 -07:00
AJ ONeal
9a3cfbb573 fix(zig): filter out legacy armv6kz (RPi 1) one-off 2023-12-17 03:20:48 -07:00
AJ ONeal
50069182eb fix(pwsh): arch = 'musl' should be libc = 'musl' 2023-12-17 03:20:24 -07:00
7 changed files with 446 additions and 867 deletions

View File

@@ -5,11 +5,8 @@ var BuildsCacher = module.exports;
let Fs = require('node:fs/promises');
let Path = require('node:path');
let HostTargets = require('./build-classifier/host-targets.js');
let Lexver = require('./build-classifier/lexver.js');
let Triplet = require('./build-classifier/triplet.js');
let request = require('@root/request');
let Triplet = require('./build-classifier/triplet.js');
var ALIAS_RE = /^alias: (\w+)$/m;
@@ -81,15 +78,7 @@ async function readFirstBytes(path) {
}
let promises = {};
async function getLatestBuilds(Releases, installersDir, cacheDir, name, date) {
if (!Releases) {
Releases = require(`${installersDir}/${name}/releases.js`);
}
// TODO update all releases files with module.exports.xxxx = 'foo';
if (!Releases.latest) {
Releases.latest = Releases;
}
async function getLatestBuilds(Releases, cacheDir, name, date) {
let id = `${cacheDir}/${name}`;
if (!promises[id]) {
promises[id] = Promise.resolve();
@@ -131,9 +120,6 @@ async function getLatestBuildsInner(Releases, cacheDir, name, date) {
}
BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
let installersDir = installers;
let cacheDir = caches;
if (!ALL_TERMS) {
ALL_TERMS = Triplet.TERMS_PRIMARY_MAP;
}
@@ -142,19 +128,16 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
bc.usedTerms = {};
bc.orphanTerms = Object.assign({}, ALL_TERMS);
bc.unknownTerms = {};
bc.formats = [];
bc._triplets = {};
bc._targetsByBuildIdCache = {};
bc._caches = {};
bc._staleAge = 15 * 60 * 1000;
bc._allFormats = {};
bc._allTriplets = {};
for (let term of TERMS_META) {
delete bc.orphanTerms[term];
}
bc.getProjectsByType = async function () {
bc.getPackages = async function () {
let dirs = {
hidden: {},
errors: {},
@@ -164,11 +147,66 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
valid: {},
};
let entries = await Fs.readdir(installersDir, { withFileTypes: true });
let entries = await Fs.readdir(installers, { withFileTypes: true });
for (let entry of entries) {
let meta = await bc.getProjectTypeByEntry(entry);
if (meta.type === 'not_found') {
let err = meta.detail;
// skip non-installer dirs
if (entry.isSymbolicLink()) {
dirs.alias[entry.name] = 'symlink';
continue;
}
if (!entry.isDirectory()) {
dirs.hidden[entry.name] = '!directory';
continue;
}
if (entry.name === 'node_modules') {
dirs.hidden[entry.name] = 'node_modules';
continue;
}
if (entry.name.startsWith('_')) {
dirs.hidden[entry.name] = '_*';
continue;
}
if (entry.name.startsWith('.')) {
dirs.hidden[entry.name] = '.*';
continue;
}
if (entry.name.startsWith('~')) {
dirs.hidden[entry.name] = '~*';
continue;
}
if (entry.name.endsWith('~')) {
dirs.hidden[entry.name] = '*~';
continue;
}
// skip invalid installers
let path = Path.join(installers, entry.name);
let head = await getPartialHeader(path);
if (!head) {
dirs.invalid[entry.name] = '!README.md';
continue;
}
let alias = head.match(ALIAS_RE);
if (alias) {
dirs.alias[entry.name] = true;
continue;
}
let releasesPath = Path.join(path, 'releases.js');
let releases;
try {
releases = require(releasesPath);
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
dirs.errors[entry.name] = err;
continue;
}
if (err.requireStack.length === 2) {
dirs.selfhosted[entry.name] = true;
continue;
}
// err.requireStack.length > 1
console.error('');
console.error('PROBLEM');
console.error(` ${err.message}`);
@@ -180,95 +218,27 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
'[SANITY FAIL] should never have missing modules in prod',
);
}
dirs[meta.type][entry.name] = meta.detail;
dirs.valid[entry.name] = true;
}
return dirs;
};
/**
* Get project type and detail - alias, selfhosted, valid (and the invalids)
* @param {String} name - filename
*/
bc.getProjectType = async function (name) {
let filepath = Path.join(installersDir, name);
let entry;
try {
entry = await Fs.lstat(filepath);
Object.assign(entry, { name: name });
} catch (e) {
return { type: 'errors', detail: 'not found' };
}
let info = await bc.getProjectTypeByEntry(entry);
return info;
};
/**
* Get project type and detail - alias, selfhosted, valid (and the invalids)
* @param {fs.Stats|fs.Dirent} entry
*/
bc.getProjectTypeByEntry = async function (entry) {
let path = Path.join(installersDir, entry.name);
// skip non-installer dirs
if (entry.isSymbolicLink()) {
let link = await Fs.readlink(path);
return { type: 'alias', detail: link };
}
if (!entry.isDirectory()) {
return { type: 'hidden', detail: '!directory' };
}
if (entry.name === 'node_modules') {
return { type: 'hidden', detail: 'node_modules' };
}
if (entry.name.startsWith('_')) {
return { type: 'hidden', detail: '_*' };
}
if (entry.name.startsWith('.')) {
return { type: 'hidden', detail: '.*' };
}
if (entry.name.startsWith('~')) {
return { type: 'hidden', detail: '~*' };
}
if (entry.name.endsWith('~')) {
return { type: 'hidden', detail: '*~' };
}
// skip invalid installers
let head = await getPartialHeader(path);
if (!head) {
return { type: 'invalid', detail: '!README.md' };
}
let alias = head.match(ALIAS_RE);
if (alias) {
let link = alias[1];
return { type: 'alias', detail: link };
}
let releasesPath = Path.join(path, 'releases.js');
try {
void require(releasesPath);
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
return { type: 'errors', detail: err };
}
if (err.message.includes(`Cannot find module '${releasesPath}'`)) {
return { type: 'selfhosted', detail: true };
}
return { type: 'not_found', detail: err };
}
return { type: 'valid', detail: true };
};
// Typically a package is organized by release (ex: go has 1.20, 1.21, etc),
// but we will organize by the build (ex: go1.20-darwin-arm64.tar.gz, etc).
bc.getPackages = async function ({ Releases, name, date }) {
bc.getBuilds = async function ({ Releases, name, date }) {
let cacheDir = caches;
let installerDir = installers;
if (!Releases) {
Releases = require(`${installerDir}/${name}/releases.js`);
}
// TODO update all releases files with object export
if (!Releases.latest) {
Releases.latest = Releases;
}
if (!date) {
date = new Date();
}
@@ -287,146 +257,71 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
// let age = now - seconds;
let projInfo = bc._caches[name];
let meta = {
// version info
versions: projInfo?.versions || [],
lexvers: projInfo?.lexvers || [],
lexversMap: projInfo?.lexversMap || {},
// culled release assets
packages: projInfo?.packages || [],
releasesByTriplet: projInfo?.releasesByTriplet || {},
// target info
triplets: projInfo?.triplets || [],
oses: projInfo?.oses || [],
arches: projInfo?.arches || [],
libcs: projInfo?.libcs || [],
formats: projInfo?.formats || [],
// TODO channels: projInfo?.channels || [],
};
if (!projInfo) {
let json = await Fs.readFile(dataFile, 'ascii').catch(
async function (err) {
if (err.code !== 'ENOENT') {
throw err;
}
return null;
},
);
try {
projInfo = JSON.parse(json);
} catch (e) {
console.error(`error: ${dataFile}:\n\t${e.message}`);
projInfo = null;
}
}
if (!projInfo) {
projInfo = await getLatestBuilds(Releases, installersDir, cacheDir, name);
let data = bc._caches[name];
let versions = data?.versions || [];
let triplets = [];
let now = date.valueOf();
if (data) {
process.nextTick(async function () {
let age = now - data.updated;
if (age < bc._staleAge) {
return;
}
data = await getLatestBuilds(Releases, cacheDir, name);
let updated = date.valueOf();
updateVersions(data, versions);
Object.assign(data, { name, updated, versions, triplets });
bc._caches[name] = data;
});
return data;
}
process.nextTick(async function () {
let now = date.valueOf();
let age = now - projInfo.updated;
if (age < bc._staleAge) {
return;
let json = await Fs.readFile(dataFile, 'ascii').catch(async function (err) {
if (err.code !== 'ENOENT') {
throw err;
}
projInfo = await getLatestBuilds(Releases, installersDir, cacheDir, name);
transformAndUpdate(name, projInfo, meta, date);
return null;
});
transformAndUpdate(name, projInfo, meta, date);
return projInfo;
try {
data = JSON.parse(json);
} catch (e) {
console.error(`error: ${dataFile}:\n\t${e.message}`);
data = null;
}
if (!data) {
data = await getLatestBuilds(Releases, cacheDir, name);
}
let updated = date.valueOf();
updateVersions(data, versions);
Object.assign(data, { name, updated, versions, triplets });
bc._caches[name] = data;
for (let build of data.releases) {
if (LEGACY_OS_MAP[build.os]) {
build.os = LEGACY_OS_MAP[build.os];
}
if (LEGACY_ARCH_MAP[build.arch]) {
build.arch = LEGACY_ARCH_MAP[build.arch];
}
}
return data;
};
function transformAndUpdate(name, projInfo, meta, date) {
meta.packages = [];
let updated = date.valueOf();
Object.assign(projInfo, { name, updated }, meta);
for (let build of projInfo.releases) {
let buildTarget = bc.classify(projInfo, build);
if (!buildTarget) {
// ignore known, non-package extensions
continue;
}
if (buildTarget.error) {
let err = buildTarget.error;
let code = err.code || '';
console.error(`[ERROR]: ${code} ${projInfo.name}: ${build.name}`);
console.error(`>>> ${err.message} <<<`);
console.error(projInfo);
console.error(build);
console.error(`^^^ ${err.message} ^^^`);
console.error(err.stack);
continue;
}
build.target = buildTarget;
meta.packages.push(build);
}
updateReleasesByTriplet(meta);
updateAndSortVersions(projInfo, meta);
Object.assign(projInfo, { name, updated }, meta);
bc._caches[name] = projInfo;
}
function updateReleasesByTriplet(meta) {
for (let build of meta.packages) {
let target = build.target;
let triplet = `${target.os}-${target.arch}-${target.libc}`;
if (!meta.releasesByTriplet[triplet]) {
meta.releasesByTriplet[triplet] = {};
}
let buildsByRelease = meta.releasesByTriplet[triplet];
if (!buildsByRelease[build.version]) {
buildsByRelease[build.version] = [];
}
let packages = buildsByRelease[build.version];
packages.push(build);
}
}
// TODO
// - sort version
// - tag channels
function updateAndSortVersions(projInfo, meta) {
for (let build of projInfo.packages) {
let hasVersion = meta.versions.includes(build.version);
// - @beta not install older than stable
function updateVersions(data, versions) {
for (let release of data.releases) {
let hasVersion = versions.includes(release.version);
if (!hasVersion) {
build.lexver = Lexver.parseVersion(build.version);
meta.lexversMap[build.lexver] = build.version;
versions.unshift(release.version);
}
}
meta.lexvers = Object.keys(meta.lexversMap);
meta.lexvers.sort();
meta.lexvers.reverse();
meta.versions = [];
for (let lexver of meta.lexvers) {
let version = meta.lexversMap[lexver];
meta.versions.push(version);
}
projInfo.packages.sort(function (a, b) {
if (a.lexver > b.lexver) {
return -1;
}
if (a.lexver < b.lexver) {
return 1;
}
return 0;
});
}
// Makes sure that packages are updated once an hour, on average
@@ -438,7 +333,7 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
}
if (bc._staleNames.length === 0) {
let dirs = await bc.getProjectsByType();
let dirs = await bc.getPackages();
bc._staleNames = Object.keys(dirs.valid);
bc._staleNames.sort(function () {
return 0.5 - Math.random();
@@ -446,8 +341,10 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
}
let name = bc._staleNames.pop();
void (await bc.getPackages({
//Releases: Releases,
let Releases = require(`${installers}/${name}/releases.js`);
//data = await getLatestBuilds(Releases, cacheDir, name);
void (await bc.getBuilds({
Releases: Releases,
name: name,
date: new Date(),
}));
@@ -463,32 +360,24 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
bc._freshenTimeout.unref();
};
bc.classify = function (projInfo, build) {
/* jshint maxcomplexity: 25 */
let maybeInstallable = Triplet.maybeInstallable(projInfo, build);
bc.classify = function (pkg, build) {
let maybeInstallable = Triplet.maybeInstallable(pkg, build);
if (!maybeInstallable) {
return null;
}
if (LEGACY_OS_MAP[build.os]) {
build.os = LEGACY_OS_MAP[build.os];
}
if (LEGACY_ARCH_MAP[build.arch]) {
build.arch = LEGACY_ARCH_MAP[build.arch];
}
// because some packages are shimmed to match a single download against
let preTarget = Object.assign({ os: '', arch: '', libc: '' }, build);
let targetId = `${preTarget.os}:${preTarget.arch}:${preTarget.libc}`;
let buildId = `${projInfo.name}:${targetId}@${build.download}`;
let buildId = `${pkg.name}:${targetId}@${build.download}`;
let target = bc._targetsByBuildIdCache[buildId];
if (target) {
Object.assign(build, { target: target, triplet: target.triplet });
return target;
}
let pattern = Triplet.toPattern(projInfo, build);
let pattern = Triplet.toPattern(pkg, build);
if (!pattern) {
let err = new Error(`no pattern generated for ${name}`);
err.code = 'E_BUILD_NO_PATTERN';
@@ -530,47 +419,15 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
// {NAME}.windows.x86_64v2.musl.exe
// windows-x86_64_v2-musl
target = { triplet: '' };
void Triplet.termsToTarget(target, projInfo, build, terms);
void Triplet.termsToTarget(target, pkg, build, terms);
target.triplet = `${target.arch}-${target.vendor}-${target.os}-${target.libc}`;
{
let hasTriplet = pkg.triplets.includes(target.triplet);
if (!hasTriplet) {
// TODO I don't love this hidden behavior
// perhaps classify should just happen when the package is loaded
// (and the sanity error should be removed, or thrown after the loop is complete)
let hasTriplet = projInfo.triplets.includes(target.triplet);
if (!hasTriplet) {
projInfo.triplets.push(target.triplet);
}
let hasOs = projInfo.oses.includes(target.os);
if (!hasOs) {
projInfo.oses.push(target.os);
}
let hasArch = projInfo.arches.includes(target.arch);
if (!hasArch) {
projInfo.arches.push(target.arch);
}
let hasLibc = projInfo.libcs.includes(target.libc);
if (!hasLibc) {
projInfo.libcs.push(target.libc);
}
if (!build.ext) {
build.ext = Triplet.buildToPackageType(build);
}
if (build.ext) {
if (!build.ext.startsWith('.')) {
build.ext = `.${build.ext}`;
}
}
let hasExt = projInfo.formats.includes(build.ext);
if (!hasExt) {
projInfo.formats.push(build.ext);
}
let hasGlobalExt = bc.formats.includes(build.ext);
if (!hasGlobalExt) {
bc.formats.push(build.ext);
}
pkg.triplets.push(target.triplet);
}
bc._triplets[target.triplet] = true;
@@ -580,7 +437,7 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
for (let term of triple) {
if (!ALL_TERMS[term]) {
throw new Error(
`[SANITY FAIL] '${projInfo.name}' '${target.triplet}' generated unknown term '${term}'`,
`[SANITY FAIL] '${pkg.name}' '${target.triplet}' generated unknown term '${term}'`,
);
}
@@ -591,302 +448,5 @@ BuildsCacher.create = function ({ ALL_TERMS, installers, caches }) {
return target;
};
/**
* Given a list of acceptable formats, get the sorted list of of formats.
* Actually used (as per node _webi/lint-builds.js):
* .7z
* .app.zip
* .dmg
* .exe
* .exe.xz
* .git
* .gz
* .msi
* .pkg
* .pkg.tar.zst
* .sh
* .tar.gz
* .tar.xz
* .xz
* .zip
*/
bc.getSortedFormats = function (formats) {
/* jshint maxcomplexity: 25 */
formats.sort();
let id = formats.join(',');
if (bc._allFormats[id]) {
return bc._allFormats[id];
}
// we don't know how to handle any of these yet
// let exclude = [];
// let isAndroid = false;
// if (!isAndroid) {
// exclude.push('.apk');
// }
// let isDebian = false;
// if (!isDebian) {
// exclude.push('.deb');
// }
// let isEnterpriseLinux = false;
// if (!isEnterpriseLinux) {
// exclude.push('.rpm');
// }
// let isArch = false;
// if (!isArch) {
// exclude.push('.pkg.tar.zst');
// }
let hasExe = formats.includes('exe') || formats.includes('.exe');
/** @type {Array<String>} */
let exts = [];
let hasXz = formats.includes('xz') || formats.includes('.xz');
if (hasXz) {
exts.push('.tar.xz');
if (hasExe) {
exts.push('.exe.xz');
}
exts.push('.xz');
}
let hasZst = formats.includes('zst') || formats.includes('.zst');
if (hasZst) {
exts.push('.tar.zst');
exts.push('.zst');
}
let hasZip = formats.includes('zip') || formats.includes('.zip');
if (hasZip) {
exts.push('.zip');
}
let has7z = false;
if (has7z) {
exts.push('.7z');
}
// let hasBz2 = formats.includes('bz2') || formats.includes('.bz2');
// if (hasBz2) {
// exts.push('.bz2');
// }
if (hasExe) {
if (!hasZip) {
exts.push('.zip');
}
exts.push('.tar.gz');
exts.push('.gz');
exts.push('.exe');
exts.push('.msi');
//exts.push('.msixbundle');
} else {
exts.push('.tar.gz');
exts.push('.gz');
exts.push('.sh');
}
exts.push('.git');
// Fallbacks
exts.push('.app.zip');
exts.push('.dmg');
exts.push('.pkg');
if (!hasXz) {
exts.push('.tar.xz');
if (hasExe) {
exts.push('.exe.xz');
}
exts.push('.xz');
}
if (!hasZip) {
if (!hasExe) {
exts.push('.zip');
}
}
if (!hasZst) {
exts.push('.tar.zst');
exts.push('.zst');
}
if (!has7z) {
exts.push('.7z');
}
// if (!hasRar) {
// exts.push('.rar');
// }
// exts.push('.tar.bz2');
// exts.push('.bz2');
bc._allFormats[id] = exts;
return exts;
};
bc.selectPackage = function (packages, formats) {
if (packages.length === 1) {
return packages[0];
}
let exts = bc.getSortedFormats(formats);
for (let ext of exts) {
for (let build of packages) {
if (build.ext === ext) {
return build;
}
}
}
return packages[0];
};
/**
* @param {Object} target
* @param {String} target.os - linux, darwin, windows, *bsd
* @param {String} target.arch - arm64, x86_64, ppc64le
* @param {String} target.libc - none, libc, gnu, musl, bionic, msvc
* @param {String} target.triplet - os-vendor-arch-libc
* @param {Error} target.error
*/
bc.findMatchingPackages = function (pkgInfo, hostTarget, verTarget) {
let matchInfo = bc._enumerateVersions(pkgInfo, verTarget.version);
let triplets = bc._enumerateTriplets(hostTarget);
//console.log('dbg: matchInfo', matchInfo);
if (matchInfo) {
for (let _triplet of triplets) {
let targetReleases = pkgInfo.releasesByTriplet[_triplet];
if (!targetReleases) {
continue;
}
// Make sure that these releases are the expected version
// (ex: jq1.7 => darwin-arm64-libc, jq1.6 => darwin-x86_64-libc)
for (let matchver of matchInfo.matches) {
let ver = pkgInfo.lexversMap[matchver] || matchver;
let packages = targetReleases[ver];
if (!packages) {
continue;
}
let match = {
triplet: _triplet,
packages: packages,
latest: pkgInfo.versions[0],
version: ver,
versions: matchInfo,
};
return match;
}
}
return null;
}
for (let _triplet of triplets) {
let targetReleases = pkgInfo.releasesByTriplet[_triplet];
if (!targetReleases) {
continue;
}
let versions = Object.keys(targetReleases);
//console.log('dbg: targetRelease versions', versions);
let lexvers = [];
for (let version of versions) {
let lexPrefix = Lexver.parseVersion(version);
lexvers.push(lexPrefix);
}
lexvers.sort();
lexvers.reverse();
// TODO get the other matchInfo props
// Make sure that these releases are the expected version
// (ex: jq1.7 => darwin-arm64-libc, jq1.6 => darwin-x86_64-libc)
for (let matchver of lexvers) {
let ver = pkgInfo.lexversMap[matchver] || matchver;
let packages = targetReleases[ver];
//console.log('dbg: packages', packages);
if (!packages) {
continue;
}
let pkg = packages[0];
if (verTarget.lts) {
if (!pkg.lts) {
continue;
}
let match = {
triplet: _triplet,
packages: packages,
latest: pkgInfo.versions[0],
version: ver,
versions: matchInfo,
};
return match;
}
let wantChannel = verTarget.channel || 'stable';
let isChannel = pkg.channel || 'stable';
if (wantChannel === 'stable') {
if (isChannel !== 'stable') {
continue;
}
}
// latest, beta, alpha, rc, preview
let match = {
triplet: _triplet,
packages: packages,
latest: pkgInfo.versions[0],
version: ver,
versions: matchInfo,
};
return match;
}
}
return null;
};
bc._enumerateTriplets = function (hostTarget) {
let id = [hostTarget.os, hostTarget.arch, hostTarget.libc].join(',');
let triplets = bc._allTriplets[id] || [];
if (triplets.length > 0) {
return triplets;
}
let oses = [];
if (hostTarget.os === 'windows') {
oses = ['ANYOS', 'windows'];
} else if (hostTarget.os === 'android') {
oses = ['ANYOS', 'posix_2017', 'android', 'linux'];
} else {
oses = ['ANYOS', 'posix_2017', hostTarget.os];
}
let waterfall = HostTargets.WATERFALL[hostTarget.os] || {};
let arches = waterfall[hostTarget.arch] ||
HostTargets.WATERFALL.ANYOS[hostTarget.arch] || [hostTarget.arch];
arches = ['ANYARCH'].concat(arches);
let libcs = waterfall[hostTarget.libc] ||
HostTargets.WATERFALL.ANYOS[hostTarget.libc] || [hostTarget.libc];
for (let os of oses) {
for (let arch of arches) {
for (let libc of libcs) {
let triplet = `${os}-${arch}-${libc}`;
triplets.push(triplet);
}
}
}
bc._allTriplets[id] = triplets;
return triplets;
};
bc._enumerateVersions = function (pkgInfo, ver) {
if (!ver) {
return null;
}
let lexPrefix = Lexver.parsePrefix(ver);
let matchInfo = Lexver.matchSorted(pkgInfo.lexvers, lexPrefix);
return matchInfo;
};
return bc;
};

View File

@@ -1,40 +0,0 @@
'use strict';
let Builds = module.exports;
let Path = require('node:path');
let BuildsCacher = require('./builds-cacher.js');
// let HostTargets = require('./build-classifier/host-targets.js');
let Parallel = require('./parallel.js');
var INSTALLERS_DIR = Path.join(__dirname, '..');
var CACHE_DIR = Path.join(__dirname, '../_cache');
let bc = BuildsCacher.create({
caches: CACHE_DIR,
installers: INSTALLERS_DIR,
});
bc.freshenRandomPackage(600 * 1000);
Builds.init = async function () {
bc.freshenRandomPackage(600 * 1000);
let dirs = await bc.getProjects();
let projNames = Object.keys(dirs.valid);
let parallel = 25;
await Parallel.run(parallel, projNames, getAll);
async function getAll(name) {
void (await bc.getPackages({
//Releases: Releases,
name: name,
date: new Date(),
}));
}
};
Builds.getProjectType = bc.getProjectType;
Builds.getPackage = bc.getPackages;
Builds.findMatchingPackages = bc.findMatchingPackages;
Builds.selectPackage = bc.selectPackage;

View File

@@ -16,7 +16,7 @@ var BAD_SH_RE = /[<>'"`$\\]/;
Installers.renderBash = async function (
pkgdir,
rel,
{ baseurl, pkg, tag, ver, os = '', arch = '', libc = '', formats, latest },
{ baseurl, pkg, tag, ver, os = '', arch = '', libc = '', formats },
) {
if (!Array.isArray(formats)) {
formats = [];
@@ -99,12 +99,10 @@ Installers.renderBash = async function (
['WEBI_PKG_PATHNAME', pkgFile],
['WEBI_PKG_FILE', pkgFile], // TODO replace with pathname
['PKG_NAME', pkg],
['PKG_OSES', (rel.oses || []).join(' ')],
['PKG_ARCHES', (rel.arches || []).join(' ')],
['PKG_LIBCS', (rel.libcs || []).join(' ')],
['PKG_FORMATS', (rel.formats || []).join(' ')],
['PKG_CHANNELS', (rel.channels || []).join(' ')],
['PKG_LATEST', latest],
['PKG_OSES', rel.oses],
['PKG_ARCHES', rel.arches],
['PKG_LIBCS', rel.libcs],
['PKG_FORMATS', (rel.formats || []).join(',')],
];
for (let env of envReplacements) {

View File

@@ -124,19 +124,184 @@ let bc = BuildsCacher.create({
installers: INSTALLERS_DIR,
});
async function getPackagesWithBuilds(installersDir, pkgNames, parallel = 25) {
let packages = [];
await Parallel.run(parallel, pkgNames, getAll);
async function getAll(name, i) {
let Releases = require(`${installersDir}/${name}/releases.js`);
let pkg = await bc.getBuilds({
Releases: Releases,
name: name,
date: new Date(),
});
packages[i] = pkg;
}
return packages;
}
function getBuildsByTarget(packages) {
let packagesByName = {};
for (let pkg of packages) {
let buildsByOs = getBuildsByOs(pkg);
packagesByName[pkg.name] = buildsByOs;
}
return packagesByName;
}
function getBuildsByOs(pkg) {
let buildsByOs = {};
for (let build of pkg.releases) {
// TODO check targets cache
let target = bc.classify(pkg, build);
if (!target) {
// ignore known, non-package extensions
continue;
}
if (target.error) {
let err = target.error;
let code = err.code || '';
console.error(`[ERROR]: ${code} ${pkg.name}: ${build.name}`);
console.error(`>>> ${err.message} <<<`);
console.error(pkg);
console.error(build);
console.error(`^^^ ${err.message} ^^^`);
console.error(err.stack);
continue;
}
let buildsByRelease = getBuildsByRelease(build, buildsByOs, target);
buildsByRelease.push(build);
}
return buildsByOs;
}
function getBuildsByRelease(build, buildsByOs, target) {
let archLibc = `${target.arch}-${target.libc}`;
if (!buildsByOs[target.os]) {
buildsByOs[target.os] = {};
}
let buildsByVersion = buildsByOs[target.os];
if (!buildsByVersion[build.version]) {
buildsByVersion[build.version] = {};
}
let buildsByArchLibc = buildsByVersion[build.version];
if (!buildsByArchLibc[archLibc]) {
buildsByArchLibc[archLibc] = [];
}
let buildsByRelease = buildsByArchLibc[archLibc];
return buildsByRelease;
}
function matchBuildsByTarget(pkg, buildsTree, target) {
let oses = [];
let targetOs = target.os;
if (target.os === 'windows') {
oses = ['ANYOS', 'windows'];
//buildsByOs = buildsTree.ANYOS || buildsTree[target.os];
} else if (target.os === 'android') {
oses = ['ANYOS', 'posix_2017', 'android', 'linux'];
// buildsByOs =
// buildsTree.ANYOS || buildsTree.posix_2017 || buildsTree[target.os];
// if (!buildsByOs) {
// targetOs = 'linux';
// buildsByOs = buildsTree.linux;
// }
} else {
oses = ['ANYOS', 'posix_2017', target.os];
// buildsByOs =
// buildsTree.ANYOS || buildsTree.posix_2017 || buildsTree[target.os];
}
// TODO can we move sortByOsAndArchLibc(builds, anything) down to the lib?
// and then the matcher
// and make the waterfall more optional?
let waterfall = HostTargets.WATERFALL[target.os] || {};
let arches = waterfall[target.arch] ||
HostTargets.WATERFALL.ANYOS[target.arch] || [target.arch];
arches = ['ANYARCH'].concat(arches);
let libcs = waterfall[target.libc] ||
HostTargets.WATERFALL.ANYOS[target.libc] || [target.libc];
//console.log('waterfalls', arches, libcs);
// TODO flatten earlier and precache?
let duplets = [];
for (let arch of arches) {
for (let libc of libcs) {
let duplet = `${arch}-${libc}`;
duplets.push(duplet);
}
}
let duplet;
let targetBuilds;
for (let os of oses) {
let buildsByOs = buildsTree[os];
if (!buildsByOs) {
continue;
}
// TODO
// - latest supported triplets
// - historical supported triplets
// TODO sort versions first, get channel (or 'stable' or 'latest') from user
for (let version of pkg.versions) {
let versionBuilds = buildsByOs[version];
if (!versionBuilds) {
continue;
}
for (let _duplet of duplets) {
targetBuilds = versionBuilds[_duplet];
//console.log(` duplet: ${_duplet}`, versionBuilds, targetBuilds);
if (targetBuilds?.length > 0) {
targetOs = os;
duplet = _duplet;
break;
}
}
if (targetBuilds?.length > 0) {
break;
}
}
if (targetBuilds?.length > 0) {
break;
}
}
if (!targetBuilds?.length) {
// console.log(' no builds:', buildsByOs);
targetBuilds = [];
}
let match = { triplet: `${targetOs}-${duplet}`, builds: targetBuilds };
return match;
}
async function main() {
// TODO
// node ./_webi/lint-builds.js caddy@beta 'x86_64/unknown Darwin libc'
//
//let [projName, userAgent] = process.argv.slice(2);
let projName = process.argv[2];
// create test case for zoxide, goreleaser, go, yq, caddy, rg
// let [pkgName, userAgent] = process.argv[2].slice(0);
// create test case for zoxide, caddy, rg
let dirs = await bc.getProjectsByType();
if (!projName) {
showDirs(dirs);
console.info('');
}
let dirs = await bc.getPackages();
showDirs(dirs);
console.info('');
bc.freshenRandomPackage(600 * 1000);
@@ -151,42 +316,23 @@ async function main() {
void valids.splice(index, 1);
}
if (projName) {
if (!valids.includes(projName)) {
throw new Error(`'${projName}' is not a valid installable project`);
}
valids = [projName];
}
let parallel = 25;
//valids = ['atomicparsley', 'caddy', 'macos'];
//valids = ['atomicparsley'];
let packages = await getPackagesWithBuilds(INSTALLERS_DIR, valids, parallel);
console.info('');
console.info(`Fetching project release assets`);
let parallel = 25;
let projects = [];
await Parallel.run(parallel, valids, getAll);
async function getAll(name, i) {
console.info(` ${name}`);
let projInfo = await bc.getPackages({
//Releases: Releases,
name: name,
date: new Date(),
});
projects[i] = projInfo;
}
console.info(`Fetching builds for`);
for (let pkg of packages) {
console.info(` ${pkg.name}`);
console.info(`Classifying build assets for...`);
for (let projInfo of projects) {
console.info(` ${projInfo.name}`);
let nStr = projInfo.releases.length.toString();
let nStr = pkg.releases.length.toString();
let n = nStr.padStart(5, ' ');
let row = `##### ${n}\t${projInfo.name}\tv`;
let row = `##### ${n}\t${pkg.name}\tv`;
rows.push(row);
// ignore known, non-package extensions
for (let build of projInfo.releases) {
let target = bc.classify(projInfo, build);
for (let build of pkg.releases) {
let target = bc.classify(pkg, build);
if (!target) {
// non-build file
continue;
@@ -195,7 +341,7 @@ async function main() {
let e = target.error;
if (e.code === 'E_BUILD_NO_PATTERN') {
console.warn(`>>> ${e.message} <<<`);
console.warn(projInfo);
console.warn(pkg);
console.warn(build);
console.warn(`^^^ ${e.message} ^^^`);
}
@@ -208,42 +354,41 @@ async function main() {
// }
// // For debug printing versions
// console.error(build.version);
rows.push(`${target.triplet}\t${projInfo.name}\t${build.version}`);
rows.push(`${target.triplet}\t${pkg.name}\t${build.version}`);
}
}
console.info(`Fetching builds for`);
for (let projInfo of projects) {
console.info('');
console.info('');
console.info(` ${projInfo.name}`);
let packagesTree = getBuildsByTarget(packages);
//console.log(`packagesTree`, packagesTree);
for (let pkg of packages) {
console.log('');
console.log('');
console.log('pkg', pkg.name);
let buildsTree = packagesTree[pkg.name];
console.log(buildsTree);
for (let target of uaTargets) {
let libc = target.libc || 'libc';
let hostTriplet = `${target.os}-${target.arch}-${libc}`;
console.info('');
console.info(` target: ${hostTriplet}`);
let match = bc.findMatchingPackages(projInfo, target, {
ver: '',
});
console.log('');
console.log(`target: ${hostTriplet}`);
let match = matchBuildsByTarget(pkg, buildsTree, target);
if (!match) {
console.info(
` project: ${projInfo.name}: missing build for os '${target.os}'`,
console.log(
` pkg: ${pkg.name}: missing build for os '${target.os}'`,
);
continue;
}
if (!match.releases) {
console.info(
` project: ${projInfo.name}: missing build for os '${target.os}-${target.arch}-${libc}'`,
if (match.builds.length === 0) {
console.log(
` pkg: ${pkg.name}: missing build for os '${target.os}-${target.arch}-${libc}'`,
);
} else if (match.triplet === hostTriplet) {
let releaseNames = Object.keys(match.releases);
console.info(` selected ${releaseNames.length}`);
console.log(` selected ${match.builds.length}`);
} else {
let releaseNames = Object.keys(match.releases);
console.info(
` selected ${releaseNames.length} (${match.triplet} fallback)`,
console.log(
` selected ${match.builds.length} (${match.triplet} fallback)`,
);
}
}
@@ -285,18 +430,6 @@ async function main() {
}
console.info('');
console.info('Formats:');
if (bc.formats.length) {
let formats = bc.formats.slice();
formats.sort();
if (!formats[0]) {
formats[0] = '(bin)';
}
console.warn(' ', formats.join('\n '));
} else {
console.info(' (none)');
}
// sort -u -k1 builds.tsv | rg -v '^#|^https?:' | rg -i arm
// cut -f1 builds.tsv | sort -u -k1 | rg -v '^#|^https?:' | rg -i arm
}

View File

@@ -127,7 +127,6 @@ __bootstrap_webi() {
echo ""
echo " $(t_err "Error: no '${PKG_NAME:-"Unknown Package"}@${WEBI_TAG:-"Unknown Tag"}' release for '${WEBI_OS:-"Unknown OS"}' (${WEBI_LIBC:-"Unknown Libc"}) on '${WEBI_ARCH:-"Unknown CPU"}' as one of '${WEBI_FORMATS:-"Unknown File Type"}'")"
echo ""
echo " Latest Version: ${PKG_LATEST}"
echo " CPUs: $PKG_ARCHES"
echo " OSes: $PKG_OSES"
echo " libcs: $PKG_LIBCS"

View File

@@ -2,14 +2,17 @@
var InstallerServer = module.exports;
let Fs = require('fs/promises');
let Path = require('path');
var Fs = require('fs/promises');
var path = require('path');
let HostTargets = require('./build-classifier/host-targets.js');
let Builds = require('./builds.js');
let Installers = require('./installers.js');
var uaDetect = require('./ua-detect.js');
var Projects = require('./projects.js');
var Installers = require('./installers.js');
InstallerServer.INSTALLERS_DIR = Path.join(__dirname, '..');
// handlers caching and transformation, probably should be broken down
var Releases = require('./transform-releases.js');
InstallerServer.INSTALLERS_DIR = path.join(__dirname, '..');
InstallerServer.serveInstaller = async function (
baseurl,
ua,
@@ -19,191 +22,113 @@ InstallerServer.serveInstaller = async function (
formats,
libc,
) {
let unameAgent = ua;
let projectName = pkg;
let [rel, tmplParams] = await InstallerServer.helper({
unameAgent,
projectName,
let [rel, opts] = await InstallerServer.helper({
ua,
pkg,
tag,
formats,
libc,
});
Object.assign(tmplParams, {
Object.assign(opts, {
baseurl,
});
var pkgdir = Path.join(InstallerServer.INSTALLERS_DIR, projectName);
var pkgdir = path.join(InstallerServer.INSTALLERS_DIR, pkg);
if ('ps1' === ext) {
return Installers.renderPowerShell(pkgdir, rel, tmplParams);
return Installers.renderPowerShell(pkgdir, rel, opts);
}
return Installers.renderBash(pkgdir, rel, tmplParams);
return Installers.renderBash(pkgdir, rel, opts);
};
InstallerServer.helper = async function ({ ua, pkg, tag, formats, libc }) {
// TODO put some of this in a middleware? or common function?
// TODO put some of this in a middleware? or common function?
// TODO maybe move package/version/lts/channel detection into getReleases
InstallerServer.helper = async function ({
unameAgent,
projectName,
tag,
formats,
libc,
}) {
console.log(`dbg: Installer User-Agent: ${unameAgent}`);
// TODO maybe move package/version/lts/channel detection into getReleases
var ver = tag.replace(/^v/, '');
var lts;
var channel;
let releaseTarget = toReleaseTarget(tag);
let hostFormats = formats;
let terms = unameAgent.split(/[\s\/]+/g);
let hostTarget = {};
try {
void HostTargets.termsToTarget(hostTarget, terms);
} catch (e) {
// if we can't guarantee the results...
// "in the face of ambiguity, refuse the temptation to guess"
throw e;
}
console.log(`dbg: Installer Host Target:`);
console.log(hostTarget);
if (!hostTarget.os) {
throw new Error(`OS could not be identified by User-Agent '${unameAgent}'`);
switch (ver) {
case 'latest':
ver = '';
channel = 'stable';
break;
case 'lts':
lts = true;
channel = 'stable';
ver = '';
break;
case 'stable':
channel = 'stable';
ver = '';
break;
case 'beta':
channel = 'beta';
ver = '';
break;
case 'dev':
channel = 'dev';
ver = '';
break;
}
console.log(`dbg: Get Project Installer Type for '${projectName}':`);
let proj = await Builds.getProjectType(projectName);
console.log(proj);
let validTypes = ['alias', 'selfhosted', 'valid'];
if (!validTypes.includes(proj.type)) {
throw new Error(
`'${projectName}' doesn't have an installer: '${proj.type}': '${proj.detail}'`,
);
var myOs = uaDetect.os(ua);
var myArch = uaDetect.arch(ua);
var myLibc;
if (libc) {
myLibc = uaDetect.libc(libc);
}
if (proj.type === 'alias') {
projectName = proj.detail;
if (!myLibc) {
myLibc = uaDetect.libc(ua);
}
if (!myLibc) {
myLibc = 'libc';
}
let projInfo = await Builds.getPackage({
name: projectName,
date: new Date(),
});
//console.log('projInfo', projInfo);
let buildTargetInfo = {
triplets: projInfo.triplets,
oses: projInfo.oses,
arches: projInfo.arches,
libcs: projInfo.libcs,
formats: projInfo.formats,
};
let tmplParams = {
pkg: projectName,
tag: tag,
os: hostTarget.os,
arch: hostTarget.arch,
libc: hostTarget.libc,
formats: hostFormats,
let cfg = await Projects.get(pkg);
let releaseQuery = {
pkg: cfg.alias || pkg,
ver,
os: myOs,
arch: myArch,
libc: myLibc,
lts,
channel,
// TODO use formats for sorting, not exclusion
// (it's better to install xz or report an error to install zip)
formats,
limit: 1,
};
let latest = projInfo.versions[0];
Object.assign(tmplParams, { latest });
Object.assign(tmplParams, releaseTarget);
console.log('tmplParams', tmplParams);
let errPackage = {
name: 'doesntexist.ext',
version: '0.0.0',
lts: '-',
channel: 'error',
date: '1970-01-01',
os: hostTarget.os || '-',
arch: hostTarget.arch || '-',
libc: hostTarget.libc || '-',
ext: 'err',
download: 'https://example.com/doesntexist.ext',
comment:
'No matches found. Could be bad or missing version info' +
',' +
"Check query parameters. Should be something like '/api/releases/{package}@{version}.tab?os={macos|linux|windows|-}&arch={amd64|x86|aarch64|arm64|armv7l|-}&libc={musl|gnu|msvc|libc|static}&limit=10'",
let rels = await Releases.getReleases(releaseQuery);
var rel = rels.releases[0];
var opts = {
pkg: cfg.alias || pkg,
ver,
tag,
os: myOs,
arch: myArch,
libc: myLibc,
lts,
channel,
formats,
limit: 1,
};
let hasOs = projInfo.oses.includes(hostTarget.os);
if (!hasOs) {
let pkg1 = Object.assign(buildTargetInfo, errPackage);
return [pkg1, tmplParams];
}
let targetRelease = Builds.findMatchingPackages(
projInfo,
hostTarget,
releaseTarget,
rel = Object.assign(
{
oses: rels.oses,
arches: rels.arches,
libcs: rels.libcs,
formats: rels.formats,
},
rel,
);
// { triplet: `${os}-${arch}-${libc}`, packages: targetPackages
// , latest: projInfo.versions[0], versions: matchInfo
// }
if (!targetRelease?.packages) {
let pkg1 = Object.assign(buildTargetInfo, errPackage);
return [pkg1, tmplParams];
}
if (!targetRelease.packages) {
let pkg1 = Object.assign(buildTargetInfo, errPackage);
return [pkg1, tmplParams];
}
let buildPkg = Builds.selectPackage(targetRelease.packages, hostFormats);
let ext = buildPkg.ext || '.exe';
if (ext.startsWith('.')) {
ext = ext.slice(1);
}
let version = targetRelease.version;
if (version.startsWith('v')) {
version = version.slice(1);
}
buildPkg = Object.assign(buildTargetInfo, buildPkg, { ext, version });
console.log('dbg: buildPkg', buildPkg);
console.log('dbg: tmplParams', tmplParams);
return [buildPkg, tmplParams];
return [rel, opts];
};
let channelNames = [
'stable',
// 'hotfix',
'latest',
'rc',
'preview',
'pre',
'dev',
'beta',
'alpha',
];
function toReleaseTarget(tag) {
tag = tag.replace(/^v/, '');
let releaseTarget = {
channel: '',
lts: false,
version: '',
};
if (tag === 'lts') {
releaseTarget.lts = true;
releaseTarget.channel = 'stable';
} else if (channelNames.includes(tag)) {
releaseTarget.channel = tag;
} else {
releaseTarget.version = tag;
}
return releaseTarget;
}
var CURL_PIPE_PS1_BOOT = Path.join(__dirname, 'curl-pipe-bootstrap.tpl.ps1');
var CURL_PIPE_SH_BOOT = Path.join(__dirname, 'curl-pipe-bootstrap.tpl.sh');
var CURL_PIPE_PS1_BOOT = path.join(__dirname, 'curl-pipe-bootstrap.tpl.ps1');
var CURL_PIPE_SH_BOOT = path.join(__dirname, 'curl-pipe-bootstrap.tpl.sh');
var BAD_SH_RE = /[<>'"`$\\]/;
InstallerServer.getPosixCurlPipeBootstrap = async function ({
@@ -225,6 +150,7 @@ InstallerServer.getPosixCurlPipeBootstrap = async function ({
let name = env[0];
let value = env[1];
// TODO create REs once, in higher scope
let envRe = new RegExp(
`^[ \\t]*#?[ \\t]*(export[ \\t])?[ \\t]*(${name})=.*`,
'm',
@@ -272,6 +198,9 @@ InstallerServer.getPwshCurlPipeBootstrap = async function ({
let tplRe = new RegExp(`{{ (${name}) }}`, 'g');
bootTxt = bootTxt.replace(tplRe, `${value}`);
// let envRe = new RegExp(`^[ \\t]*#?[ \\t]*($$${name})[ \\t]*=.*`, 'im');
// bootTxt = bootTxt.replace(envRe, `$$${name} = '${value}'`);
let setRe = new RegExp(
`(#[ \\t]*)?(\\$${name})[ \\t]*=[ \\t]['"].*['"][ \\t]`,
'im',