Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar-c23 authored Oct 14, 2023
2 parents 0af7124 + a2cf9f3 commit 8ad157a
Show file tree
Hide file tree
Showing 149 changed files with 5,359 additions and 634 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Node.js CI
on:
push:
branches: ['main']
pull_request:
jobs:
build:
name: "Fmt, Lint, & Test"
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 20.x
- latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: "Webi: Install 'shfmt' and 'shellcheck', and update PATH"
run: |
sh ./_scripts/install-ci-deps
echo "${HOME}/.local/bin" >> $GITHUB_PATH
- run: shfmt --version
- run: shellcheck -V
- run: node --version
- run: npm run fmt
- run: npm ci
- run: npm run lint
- run: npm run test
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETEMEnode_modules/**/*
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
jsconfig.json
package.json
package-lock.json
9 changes: 6 additions & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"trailingComma": "all",
"tabWidth": 2,
"bracketSpacing": true,
"printWidth": 80,
"proseWrap": "always",
"singleQuote": true,
"proseWrap": "always"
"tabWidth": 2,
"trailingComma": "all",
"semi": true
}
1 change: 1 addition & 0 deletions AtomicParsley
10 changes: 5 additions & 5 deletions _common/gitea.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function getAllReleases(request, owner, repo, baseurl) {
if (!baseurl) {
return Promise.reject('missing baseurl');
}
return ghRelease(request, owner, repo, baseurl + '/api/v1').then(function (
all,
) {
return all;
});
return ghRelease(request, owner, repo, baseurl + '/api/v1').then(
function (all) {
return all;
},
);
}

module.exports = getAllReleases;
Expand Down
3 changes: 0 additions & 3 deletions _npm/lib/exec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

var pkg = require('../package.json');
var spawn = require('child_process').spawn;
var os = require('os');
var path = require('path');

function spawner(args) {
return new Promise(function (resolve, reject) {
Expand Down
57 changes: 57 additions & 0 deletions _scripts/git-hooks-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node
'use strict';

var Fs = require('node:fs/promises');
var Path = require('node:path');

async function copyScripts() {
var pkgDir = Path.join(__dirname, '..');
var scriptsDir = Path.join(pkgDir, '_scripts');
var gitFile = Path.join(pkgDir, '.git');

// if this is a submodule, '.git' will be a file with a
// path to the actual git module directory
var gitDir = await Fs.readFile(gitFile, 'utf8')
.catch(function (e) {
// console.error(e);
//return 'gitdir: ../.git/modules/installers';
return 'gitdir: ./.git';
})
.then(function (str) {
var parts = str.split(': ');
str = parts[1];
str = str.trim();

return Path.resolve(pkgDir, str);
});

var gitHooksDir = Path.join(gitDir, 'hooks');

var src = Path.join(scriptsDir, 'git-hooks-pre-commit.js');
var dst = Path.join(gitHooksDir, 'pre-commit');

console.info(`[git-hooks] Checking for pre-commit hooks...`);
var relSrc = Path.relative(pkgDir, src);
var relDst = Path.relative(pkgDir, dst);
await Fs.access(dst)
.then(function () {
console.info(`[git-hooks] Found ${relDst}`);
})
.catch(async function (e) {
// ignore e
await Fs.mkdir(gitHooksDir, { recursive: true });
await Fs.copyFile(src, dst);
await Fs.chmod(dst, 0o755);
console.info(`[git-hooks] Found template ${relSrc}`);
console.info(`[git-hooks] Initialized ${relDst}`);
});
}

copyScripts()
.then(function () {
process.exit(0);
})
.catch(function (e) {
console.error(e);
process.exit(1);
});
7 changes: 7 additions & 0 deletions _scripts/git-hooks-pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
set -u

npm run fmt
npm run lint
npm run test
12 changes: 12 additions & 0 deletions _scripts/git-hooks-pre-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node
'use strict';

var Process = require('child_process');

var procOpts = { stdio: 'inherit' };
var commands = ['npm run fmt', 'npm run lint', 'npm run test'];

for (let cmd of commands) {
console.info(`[pre-commit] exec: ${cmd}`);
Process.execSync(cmd, procOpts);
}
9 changes: 9 additions & 0 deletions _scripts/install-ci-deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
set -u

# Install 'shfmt 3.7.x'
curl -fsS https://webi.sh/[email protected] | sh

# Install 'shellcheck v0.9.x'
curl -fsS https://webi.sh/[email protected] | sh
32 changes: 32 additions & 0 deletions _scripts/tooling-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node
'use strict';

var Cmd = require('node:child_process');
var Os = require('node:os');

var procOpts = { stdio: 'inherit' };
var commands = ['shfmt --version', 'shellcheck --version'];

for (let cmd of commands) {
console.info(`[tooling-init] checking for '${cmd}':`);
try {
Cmd.execSync(cmd, procOpts);
} catch (e) {
// ignore e
printInstallHelp(cmd);
process.exit(1);
}
}

function printInstallHelp(cmd) {
console.error('');
console.error('ERROR');
console.error(` could not run '${cmd}'`);
console.error('POSSIBLE FIX');
if (/^win/i.test(Os.platform())) {
console.error(` curl.exe https://webi.ms/${cmd} | powershell`);
} else {
console.error(` curl -fsS https://webi.sh/${cmd} | sh`);
}
console.error('');
}
42 changes: 23 additions & 19 deletions _webi/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,40 @@ __webi_main() {
export WEBI_WGET="\$(command -v wget)"
set -e
my_libc=''
if ldd /bin/ls 2> /dev/null | grep -q 'musl' 2> /dev/null; then
my_libc=' musl-native'
fi
export WEBI_HOST="\${WEBI_HOST:-https://webinstall.dev}"
export WEBI_UA="\$(uname -s)/\$(uname -r) \$(uname -m)/unknown"
export WEBI_UA="\$(uname -s)/\$(uname -r) \$(uname -m)/unknown\${my_libc}"
webinstall() {
my_package="\${1:-}"
if [ -z "\$my_package" ]; then
>&2 echo "Usage: webi <package>@<version> ..."
>&2 echo "Example: webi node@lts rg"
echo >&2 "Usage: webi <package>@<version> ..."
echo >&2 "Example: webi node@lts rg"
exit 1
fi
export WEBI_BOOT="\$(mktemp -d -t "\$my_package-bootstrap.\$WEBI_TIMESTAMP.XXXXXXXX")"
my_installer_url="\$WEBI_HOST/api/installers/\$my_package.sh?formats=\$my_ext"
set +e
if [ -n "\$WEBI_CURL" ]; then
curl -fsSL "\$my_installer_url" -H "User-Agent: curl \$WEBI_UA" \\
-o "\$WEBI_BOOT/\$my_package-bootstrap.sh"
if ! curl -fsSL "\$my_installer_url" -H "User-Agent: curl \$WEBI_UA" \\
-o "\$WEBI_BOOT/\$my_package-bootstrap.sh"; then
echo >&2 "error fetching '\$my_installer_url'"
exit 1
fi
else
wget -q "\$my_installer_url" --user-agent="wget \$WEBI_UA" \\
-O "\$WEBI_BOOT/\$my_package-bootstrap.sh"
fi
if ! [ \$? -eq 0 ]; then
>&2 echo "error fetching '\$my_installer_url'"
exit 1
if ! wget -q "\$my_installer_url" --user-agent="wget \$WEBI_UA" \\
-O "\$WEBI_BOOT/\$my_package-bootstrap.sh"; then
echo >&2 "error fetching '\$my_installer_url'"
exit 1
fi
fi
set -e
(
cd "\$WEBI_BOOT"
Expand All @@ -133,10 +138,10 @@ __webi_main() {
show_path_updates() {
if ! [ -n "\${_WEBI_CHILD}" ]; then
if [ -f "\$_webi_tmp/.PATH.env" ]; then
my_paths=\$(cat "\$_webi_tmp/.PATH.env" | sort -u)
if [ -n "\$my_paths" ]; then
if test -z "\${_WEBI_CHILD}"; then
if test -f "\$_webi_tmp/.PATH.env"; then
my_paths=\$(sort -u < "\$_webi_tmp/.PATH.env")
if test -n "\$my_paths"; then
printf 'PATH.env updated with:\\n'
printf "%s\\n" "\$my_paths"
printf '\\n'
Expand Down Expand Up @@ -199,8 +204,7 @@ __webi_main() {
exit 0
fi
for pkgname in "\$@"
do
for pkgname in "\$@"; do
webinstall "\$pkgname"
done
Expand Down
20 changes: 12 additions & 8 deletions _webi/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function normalize(all) {
};

all.releases.forEach(function (rel) {
/* jshint maxcomplexity:25 */
rel.version = rel.version.replace(/^v/i, '');
if (!rel.name) {
rel.name = rel.download.replace(/.*\//, '');
Expand All @@ -85,21 +86,24 @@ function normalize(all) {
}
// 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;
if (!rel._musl_native) {
if (!rel._musl) {
if (/(\b|\.|_|-)(musl)(\b|\.|_|-)/.test(rel.download)) {
rel._musl = true;
}
}
}
supported.oses[rel.os] = true;

if (!rel.arch) {
arches.some(function (regKey) {
var arch = (rel.name || rel.download).match(archMap[regKey]) && regKey;
if (arch) {
for (let arch of arches) {
let name = rel.name || rel.download;
let isArch = name.match(archMap[arch]);
if (isArch) {
rel.arch = arch;
return true;
break;
}
});
}
}
if (!rel.arch) {
if ('macos' === rel.os) {
Expand Down
2 changes: 2 additions & 0 deletions _webi/serve-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ async function serveInstaller(baseurl, ua, pkg, tag, ext, formats) {
// TODO maybe move package/version/lts/channel detection into getReleases
var myOs = uaDetect.os(ua);
var myArch = uaDetect.arch(ua);
var myLibc = uaDetect.libc(ua);
let cfg = await packages.get(pkg);
let rels = await getReleases({
pkg: cfg.alias || pkg,
ver,
os: myOs,
arch: myArch,
libc: myLibc,
lts,
channel,
formats,
Expand Down
Loading

0 comments on commit 8ad157a

Please sign in to comment.