Skip to content

Commit

Permalink
Merge acbcd15 into 104affb
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Mar 29, 2024
2 parents 104affb + acbcd15 commit fd18123
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.shellcode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: denoland/setup-deno@v1
with:
deno-version: 1.39
deno-version: '1.42.0'
- uses: actions/checkout@v4
- run: deno task compile
- uses: actions/upload-artifact@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1 # using ourself to install deno could compromise the tests
with:
deno-version: 1.39
deno-version: '1.42.0'
- run: deno cache **/*.test.ts
- run: deno task test --coverage=cov_profile --no-check
- run: deno coverage cov_profile --lcov --exclude=tests/ --output=cov_profile.lcov
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1 # using ourself to install deno could compromise the tests
with:
deno-version: 1.39
deno-version: '1.42.0'
- run: deno lint

typecheck:
Expand All @@ -68,5 +68,5 @@ jobs:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: 1.39
deno-version: '1.42.0'
- run: deno task typecheck
51 changes: 51 additions & 0 deletions benchmarks/startup_bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { assert } from "deno/assert/mod.ts"

const gitVersion = "2.44.0"

function assertGitOutput(output: Deno.CommandOutput) {
assert(output.code === 0)
assert(
new TextDecoder().decode(output.stdout) === `git version ${gitVersion}\n`,
)
assert(new TextDecoder().decode(output.stderr) === "")
}

// Run the command before the benchmark to ensure git is bootstrapped
const command = new Deno.Command("./pkgx", {
args: [`git@${gitVersion}`, "--version"],
})
const output = await command.output()
assertGitOutput(output)

Deno.bench(
"git --version",
{ permissions: { run: true, env: true }, group: "startup", baseline: true },
async (b) => {
const gitBin = `${
Deno.env.get(
"HOME",
)
}/.pkgx/git-scm.org/v${gitVersion}/bin/git`
const command = new Deno.Command(gitBin, {
args: ["--version"],
})
b.start()
const output = await command.output()
b.end()
assertGitOutput(output)
},
)

Deno.bench(
"pkgx git --version",
{ permissions: { run: true }, group: "startup" },
async (b) => {
const command = new Deno.Command("./pkgx", {
args: [`git@${gitVersion}`, "--version"],
})
b.start()
const output = await command.output()
b.end()
assertGitOutput(output)
},
)
10 changes: 5 additions & 5 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
},
"tasks": {
// runs this source checkout, args will be passed
"run": "deno run --unstable -A ./entrypoint.ts",
"run": "deno run --unstable-fs --unstable-ffi -A ./entrypoint.ts",

// you can specify paths to specific tests if you need
// follows is the ideal permissions lines, unfortunately deno considers making symlinks to require full read/write permissions for fuck knows why reasons
//"test": "deno test --allow-read=$PWD,$TMPDIR,$HOME,/ --allow-env --allow-write=$TMPDIR --allow-ffi --unstable",
"test": "deno test --allow-read --allow-env --allow-write --allow-ffi --unstable",
"test": "deno test --unstable-ffi --allow-ffi --allow-read --allow-env --allow-write",
// ^^ ffi & unstable needed for execve.ts

// installs to /usr/local/bin/pkgx
"install": "deno task compile && ./pkgx +gnu.org/coreutils /usr/bin/sudo install -D ./pkgx /usr/local/bin/pkgx",

//--------------------------------------- ci/cd/admin
"coverage" : "scripts/run-coverage.sh",
"typecheck": "deno check --unstable ./entrypoint.ts",
"compile": "deno compile --lock=deno.lock --allow-read --allow-write --allow-net --allow-run --allow-env --allow-ffi --unstable --output $INIT_CWD/pkgx ./entrypoint.ts"
"typecheck": "deno check ./entrypoint.ts",
"compile": "scripts/compile.sh"
},
"pkgx": "deno~1.39",
"pkgx": "deno~1.42.0",
"lint": {
"exclude": ["src/**/*.test.ts"]
},
Expand Down
35 changes: 35 additions & 0 deletions deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,41 @@
"https://deno.land/x/libpkgx@v0.18.0/vendor/sqlite3@0.10.0/src/ffi.ts": "a3ba0fb636301d6d2c6b6998ce82239b66be59fae7cb1a9859e2e3aaf0582159",
"https://deno.land/x/libpkgx@v0.18.0/vendor/sqlite3@0.10.0/src/statement.ts": "65d01d6824dac78c44a795657cb0fc3d3ddcd5f32c64e0a3284fcadaa5b092b2",
"https://deno.land/x/libpkgx@v0.18.0/vendor/sqlite3@0.10.0/src/util.ts": "49a936fd7c0483c4baca9d7d7442351931888010af2f4b8de6e95eee29788f98",
"https://deno.land/x/libpkgx@v0.18.1/mod.ts": "14a69905ffad8064444c02d146008efeb6a0ddf0fe543483839af18e01684f5a",
"https://deno.land/x/libpkgx@v0.18.1/src/deps.ts": "4315cdd8b0c9eef84e30f73080b8838fb5fcece1ef28f0cc3ae2b6d7ad21eb43",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useCache.ts": "9f3cc576fabae2caa6aedbf00ab12a59c732be1315471e5a475fef496c1e35ae",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useCellar.ts": "c1e264fcb732423734f8c113fc7cb80c97befe8f13ed9d24906328bc5526c72d",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useConfig.ts": "2ace9d5ac8b6018a0a21c249f737a0708e271409f70b00bb9da24b81d163bcd0",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useDownload.ts": "62b2043fcbc06a0925eb06fc5ed5f2f2ef3779e8ce10bc44b0163e9bd9b8cbc0",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useFetch.ts": "ecf29342210b8eceed216e3bb73fcc7ea5b3ea5059686cf344ed190ca42ff682",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useInventory.ts": "0f47a71f51f752e53e2e32786e68375a314f6fc6bb225cd626a412a83086ebbd",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useMoustaches.ts": "e9166ddace759315782be0f570a4cd63c78e3b85592d59b75ddd33a0e401aa6b",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useOffLicense.ts": "9a7a35bd83a8dbb5a25d532e2ab885b5fb77101cc38fad10c5f3ea6a49a24e02",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/usePantry.ts": "0796cde2c4fca6d3790303af5299a1ac4d83478c0e28465f0820e0e47a703836",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useShellEnv.ts": "14d29f23b8e256590318cfd5fb840955038429c4cac8f71dfbf8deb46b7d88ec",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useSync.ts": "591fd302dc3b8bf04a835ea2b8ed5e4558c4ba50a1f52df714e9f84a66acaf27",
"https://deno.land/x/libpkgx@v0.18.1/src/hooks/useSyncCache.ts": "d8cb23f2d9cd6a1baba46a94633be41d3559bdff7f3232e791b752f701ad4257",
"https://deno.land/x/libpkgx@v0.18.1/src/plumbing/hydrate.ts": "c75f151ed307532ce9c2bf62c61e6478bb1132f95a11b848e02ea2dec08c2ff3",
"https://deno.land/x/libpkgx@v0.18.1/src/plumbing/install.ts": "19244fb150e80a0bbbed90e4a3f47e2c5aa3e0919ff060cec1db0b789730b560",
"https://deno.land/x/libpkgx@v0.18.1/src/plumbing/link.ts": "acb98bf014414208f14c5f57fa36e2aa66ae9bee69d763120c3ddb656e244063",
"https://deno.land/x/libpkgx@v0.18.1/src/plumbing/resolve.ts": "9425e0d201ee440a8dc011940046f0bb6d94aa29cd738e1a8c39ca86e55aad41",
"https://deno.land/x/libpkgx@v0.18.1/src/plumbing/which.ts": "f918211e561e56aabf6909e06fa10fa3be06ffebd9e7cc28ce57efef4faff27d",
"https://deno.land/x/libpkgx@v0.18.1/src/porcelain/install.ts": "6e41d94226b8eb33a9fbb591e5ddd95e2c5e0c2449cc617ac5f365746d1e4592",
"https://deno.land/x/libpkgx@v0.18.1/src/porcelain/run.ts": "20c60bebeca51daf12d9e5baefe8670844162308734f8a189a1f484c4155d671",
"https://deno.land/x/libpkgx@v0.18.1/src/types.ts": "dc1a4e6458d11454282f832909838c56f786a26eed54fb8ab5675d6691ebf534",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/Path.ts": "72bbb8afa6a40e3cfbf01d4d9069e0818e7abaf0021703a20b0677f06c01e883",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/error.ts": "b0d3130f5cdfc0cc8ea10f93fea0e7e97d4473ddc9bc527156b0fcf24c7b939c",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/flock.deno.ts": "c57b32f656d06140e58886973beec20661f1d0809bf652376acc64969b85942a",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/host.ts": "3b9e0d4cb05f9bde0ee8bcb0f8557b0a339f6ef56dfb1f08b2cfa63b44db91ee",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/misc.ts": "a4d7944da07066e5dd2ef289af436dc7f1032aed4272811e9b19ceeed60b8491",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/pkg.ts": "e737cc9a98cd6a2797668c6ef856128692290256a521cc3906bd538410925451",
"https://deno.land/x/libpkgx@v0.18.1/src/utils/semver.ts": "eec31f4345ea483eac7e0fbfdcc0061499077df03c4b6ec7666cd0d29c6cab98",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/mod.ts": "7ce0a19f9cea3475cc94750ece61c20d857f1c3a279ad38cd029a3f8d9b7b03e",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/src/constants.ts": "85fd27aa6e199093f25f5f437052e16fd0e0870b96ca9b24a98e04ddc8b7d006",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/src/database.ts": "902fe762776cacf049ac0d175a15f6fecf2e93be464f31e3bca4ff302a7a5aee",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/src/ffi.ts": "a3ba0fb636301d6d2c6b6998ce82239b66be59fae7cb1a9859e2e3aaf0582159",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/src/statement.ts": "65d01d6824dac78c44a795657cb0fc3d3ddcd5f32c64e0a3284fcadaa5b092b2",
"https://deno.land/x/libpkgx@v0.18.1/vendor/sqlite3@0.10.0/src/util.ts": "49a936fd7c0483c4baca9d7d7442351931888010af2f4b8de6e95eee29788f98",
"https://deno.land/x/outdent@v0.8.0/mod.ts": "72630e680dcc36d5ae556fbff6900b12706c81a6fd592345fc98bcc0878fb3ca",
"https://deno.land/x/outdent@v0.8.0/src/index.ts": "6dc3df4108d5d6fedcdb974844d321037ca81eaaa16be6073235ff3268841a22",
"https://deno.land/x/plug@1.0.1/deps.ts": "35ea2acd5e3e11846817a429b7ef4bec47b80f2d988f5d63797147134cbd35c2",
Expand Down
4 changes: 2 additions & 2 deletions entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { render as perror } from "./src/err-handler.ts"
import { setColorEnabled } from "deno/fmt/colors.ts"
import clicolor from "./src/utils/clicolor.ts"

setColorEnabled(clicolor(Deno.stderr.rid))
setColorEnabled(clicolor(Deno.stderr))

///////////////////////////////////////////////////////// backwards compatability
const argstr = Deno.args.join(' ')
Expand Down Expand Up @@ -71,7 +71,7 @@ try {

/////////////////////////////////////////////////////////////////////////// utils
function logger_prefix() {
if (Deno.env.get("CI") || !Deno.isatty(Deno.stdin.rid)) {
if (Deno.env.get("CI") || !Deno.stdin.isTerminal()) {
return 'pkgx'
}
}
14 changes: 14 additions & 0 deletions scripts/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# This script needs to be executed with dev off

set -e

for deno_version in 1.40 1.41 1.42; do
echo "Compiling with deno@${deno_version}..."
pkgx "deno@${deno_version}" task compile

echo "Benchmarking compiled binary..."
# Use the same deno version for running the benchmark itself
pkgx "deno@1.42" bench --allow-run --allow-env --seed=250 benchmarks
done
14 changes: 14 additions & 0 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# this is only available when using pkgx's deno
DENORT_BIN="$(dirname "$(which deno)")/denort"

if [[ -f "$DENORT_BIN" ]]; then
export DENORT_BIN
else
unset DENORT_BIN
fi

exec deno compile --lock=deno.lock --allow-read --allow-write --allow-net \
--allow-run --allow-env --allow-ffi --unstable-ffi --unstable-fs \
--output "$INIT_CWD/pkgx" ./entrypoint.ts
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default async function({ flags, ...opts }: Args, logger_prefix?: string)
console.log(shellcode())
break
case 'help':
setColorEnabled(clicolor(Deno.stdout.rid))
setColorEnabled(clicolor(Deno.stdout))
console.log(help(flags.verbosity))
break
case 'env': {
Expand Down Expand Up @@ -122,7 +122,7 @@ async function ensure_pantry() {

function make_logger(verbosity: number, logger_prefix?: string): IInstallLogger {
const logger = new Logger(logger_prefix)
if (verbosity <= -2 || !Deno.isatty(Deno.stderr.rid)) {
if (verbosity <= -2 || !Deno.stderr.isTerminal()) {
return {
replace: () => {},
clear: () => {},
Expand Down
4 changes: 2 additions & 2 deletions src/modes/integrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default async function(op: 'install' | 'uninstall', { dryrun }: { dryrun:
}
break
case 'install':
if (!_internals.isatty(Deno.stdout.rid)) {
if (!_internals.isatty(Deno.stdout)) {
// we're being sourced, output the hook
_internals.stdout(shellcode())
} else if (opd_at_least_once) {
Expand Down Expand Up @@ -125,7 +125,7 @@ function shells(): [Path, string][] {
export const _internals = {
home: Path.home,
host,
isatty: Deno.isatty,
isatty: (x: {isTerminal: () => boolean}) => x.isTerminal(),
stdout: console.log,
stderr: console.error
}
6 changes: 3 additions & 3 deletions src/utils/clicolor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

export default function(dst = Deno.stdout.rid, env = Deno.env.toObject()) {
export default function(dst = Deno.stdout, env = Deno.env.toObject()) {
// interprets https://no-color.org
// see: https://deno.land/api@v1.37.1?s=Deno.noColor
if (Deno.noColor) {
Expand All @@ -8,9 +8,9 @@ export default function(dst = Deno.stdout.rid, env = Deno.env.toObject()) {

//https://bixense.com/clicolors/

//NOTE we (mostly) only output colors to stderr hence the isatty check for that
//NOTE we (mostly) only output colors to stderr hence the isTerminal() check for that
//FIXME not true for --help tho
if (env.CLICOLOR !== '0' && Deno.isatty(dst)) {
if (env.CLICOLOR !== '0' && dst.isTerminal()) {
return true
}
if ((env.CLICOLOR_FORCE ?? '0') != '0') {
Expand Down
File renamed without changes.

0 comments on commit fd18123

Please sign in to comment.