Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deno 1.45: binaries ~25% smaller, ~10% faster #978

Merged
merged 30 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
91632fe
dep on deno 1.40
mxcl Jan 28, 2024
67f53e2
Bump deno to 1.41
felipecrs Feb 22, 2024
3fbb7c5
Merge branch 'main' of https://github.com/pkgxdev/pkgx into deno-1.41
felipecrs Feb 22, 2024
2b6c851
Relax deno from 1.41.0 to 1.41
felipecrs Feb 23, 2024
f358c14
Use pkgx's denort
felipecrs Mar 8, 2024
2a2c154
Restore deno.lock
felipecrs Mar 8, 2024
a0c4792
Pin deno to 1.41.2, regenerate the lockfile
felipecrs Mar 8, 2024
813d119
Deno 1.42
felipecrs Mar 29, 2024
7f0b34f
Add benchmark
felipecrs Mar 29, 2024
f2338b6
Fix compile task when using official's deno
felipecrs Mar 29, 2024
acbcd15
Try to improve benchmark
felipecrs Mar 29, 2024
9703385
Improve bench again
felipecrs Mar 29, 2024
9313992
deno 1.42.1
felipecrs Apr 11, 2024
8c3727c
[email protected], @deno/[email protected]
felipecrs Apr 11, 2024
8f91aa5
Revert compile task after pkgxdev/pantry#5750
felipecrs Apr 11, 2024
82f8626
Delete benchmark script
felipecrs Apr 11, 2024
ea4b037
Merge branch 'main' of https://github.com/pkgxdev/pkgx into deno-1.41
felipecrs Apr 11, 2024
0aff722
Remove other bench file
felipecrs Apr 11, 2024
d3ad522
deno 1.42.3
felipecrs Apr 14, 2024
86ff86d
deno 1.42.4
felipecrs Apr 22, 2024
e32f58f
Merge branch 'main' of https://github.com/pkgxdev/pkgx into deno-1.41
felipecrs May 1, 2024
073a47e
[email protected]
felipecrs May 1, 2024
3daa0ca
Deno 1.44
felipecrs May 30, 2024
1bc922d
Merge branch 'main' of https://github.com/pkgxdev/pkgx into deno-1.41
felipecrs May 30, 2024
8ed97a4
deno 1.44.4
felipecrs Jun 25, 2024
5cd6198
Fix some flaky execve tests
felipecrs Jun 27, 2024
823ff5d
Undo formatting changes
felipecrs Sep 6, 2024
99ecc68
Merge branch 'main' of https://github.com/pkgxdev/pkgx into deno-1.41
felipecrs Sep 6, 2024
365b5bf
Update Deno from 1.44.4 to 1.46.3
felipecrs Sep 6, 2024
3044bd3
Downgrade Deno from 1.46 to 1.45
felipecrs Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.45.5
- 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.45.5
- 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.45.5
- 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.45.5
- run: deno task typecheck
16 changes: 8 additions & 8 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"
"coverage": "scripts/run-coverage.sh",
"typecheck": "deno check ./entrypoint.ts",
"compile": "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"
},
"pkgx": "deno~1.39",
"pkgx": "deno~1.45.5",
"lint": {
"exclude": ["src/**/*.test.ts"]
},
Expand All @@ -33,7 +33,7 @@
"pkgx": "https://deno.land/x/[email protected]/mod.ts",
"pkgx/": "https://deno.land/x/[email protected]/src/",
"outdent": "https://deno.land/x/[email protected]/mod.ts",
"cliffy/": "https://deno.land/x/[email protected].3/",
"deno/": "https://deno.land/std@0.196.0/" // cliffy is on 196 so we standardized on it
"cliffy/": "https://deno.land/x/[email protected].4/",
"deno/": "https://deno.land/std@0.221.0/" // cliffy is on 221 so we standardized on it
}
}
715 changes: 165 additions & 550 deletions deno.lock

Large diffs are not rendered by default.

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'
}
}
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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 @@ -135,7 +135,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
8 changes: 4 additions & 4 deletions src/modes/integrate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writeAll } from "deno/streams/write_all.ts"
import { readAll } from "deno/streams/read_all.ts"
import { writeAll } from "deno/io/write_all.ts"
import { readAll } from "deno/io/read_all.ts"
import { readLines } from "deno/io/read_lines.ts"
import { Path, PkgxError, utils } from "pkgx"
import announce from "../utils/announce.ts"
Expand Down 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/[email protected]?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.
22 changes: 16 additions & 6 deletions src/utils/execve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ export default function({cmd: args, env}: {cmd: string[], env: Record<string, st
const argv = new CStringArray(args)
const envp = new CStringArray(Object.entries(env).map(([key, value]) => `${key}=${value}`))

const errno = _internals.execve(
Deno.UnsafePointer.of(path),
Deno.UnsafePointer.of(argv),
Deno.UnsafePointer.of(envp))
const errno = (() => {
let tries = 10;
while (true) {
const errno = _internals.execve(
Deno.UnsafePointer.of(path),
Deno.UnsafePointer.of(argv),
Deno.UnsafePointer.of(envp)
);
if (!tries--) return errno;
// 11 = EAGAIN = Try again
if (errno == 11) continue;
return errno;
}
})();

switch (errno) {
case 2: //ENOENT:
case 2: //ENOENT:
case 316: //FIXME ALERT! ALERT! BUG! SOMETHING IS WRONG WITH OUR USE OR ERRNO AND THIS SOMETIMES RESULTS, USUALLY ON MACOS :/
// yes: strange behavior from execve here indeed
if (parse_Path(args[0])?.exists()) {
throw new Deno.errors.PermissionDenied()
} else {
throw new Deno.errors.NotFound()
}
case 13:
case 316: //FIXME ALERT! ALERT! BUG! SOMETHING IS WRONG WITH OUR USE OR ERRNO AND THIS SOMETIMES RESULTS :/
throw new Deno.errors.PermissionDenied()
case 63: //ENAMETOOLONG:
case 7: //E2BIG:
Expand Down