Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl authored Sep 6, 2024
2 parents f33e732 + 0bb7d75 commit 5b69c95
Show file tree
Hide file tree
Showing 24 changed files with 401 additions and 599 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.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
}
}
750 changes: 200 additions & 550 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deno 1.33.4

| <p>​<a href="run/anywhere/terminals.md">Terminals</a><br>Run anything in your terminal</p> | <p><a href="run/anywhere/docker.md">Docker</a><br>Run anything in Docker</p> |
| ----- | ----- |
| <p>​<a href="run/anywhere/ci-cd.md">CI/CD</a><br>Run anything in CI/CD</p> | <p>​<a href="run/anywhere/ci-cd.md">Scripting</a><br>Run anything in scripts</p> |
| <p>​<a href="run/anywhere/ci-cd.md">CI/CD</a><br>Run anything in CI/CD</p> | <p>​<a href="run/anywhere/scripts.md">Scripting</a><br>Run anything in scripts</p> |
| <p>​<a href="run/anywhere/editors.md">Editors</a><br>Run anything in Editors & IDEs</p> |


Expand Down
4 changes: 2 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ Then there are a couple platform specific cache/data directories:
### macOS

```sh
rm -rf "${XDG_CACHE_HOME:-$HOME/Library/Caches}/pkgx"`
rm -rf "${XDG_DATA_HOME:-$HOME/Library/Application Support}"/pkgx`
rm -rf "${XDG_CACHE_HOME:-$HOME/Library/Caches}/pkgx"
rm -rf "${XDG_DATA_HOME:-$HOME/Library/Application Support}"/pkgx
```

### Non macOS
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'
}
}
4 changes: 3 additions & 1 deletion fixtures/package.json/engines/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"engines": {
"node": "~16.16.1",
"npm": "~9.7.1"
"npm": "~9.7.1",
"yarn": "~1.22.10",
"pnpm": "~7.33.7"
}
}

4 changes: 4 additions & 0 deletions fixtures/package.json/packageManager/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packageManager": "[email protected]+sha256.d1581d46ed10f54ff0cbdd94a2373b1f070202b0fbff29f27c2ce01460427043"
}

9 changes: 9 additions & 0 deletions fixtures/package.json/volta/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"volta": {
"node": "16.16.1",
"npm": "9.7.1",
"yarn": "1.22.10",
"pnpm": "7.33.7"
}
}

19 changes: 16 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,20 @@ type Args = BaseArgs & { flags: { verbosity: number } }
export default async function({ flags, ...opts }: Args, logger_prefix?: string) {
if (flags.sync) {
try {
await useSync() //TODO Logger
const logger: Logger = new Logger('sync')
const printer = {
syncing() {
logger.replace('fetching')
},
caching() {
logger.replace('caching')
},
syncd() {
logger.clear()
}
}

await useSync(printer) //TODO Logger
} catch (err) {
if (!flags.keepGoing) throw err
}
Expand Down Expand Up @@ -92,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 @@ -122,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
3 changes: 2 additions & 1 deletion src/modes/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ export default async function(pkgs: PackageRequirement[], unsafe: boolean) {
exec pkgx +${pkgstr} -- ${program} "$@"
else
cd "$(dirname "$0")"
rm ${programs.join(" ")} && echo "uninstalled: ${pkgstr}" >&2
rm -f ${programs.map(p => `'${p}'`).join(' ')} && echo "uninstalled: ${pkgstr}" >&2
fi`
}

const f = dst.mkdir('p').join(program)

if (f.exists()) {
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
}
2 changes: 1 addition & 1 deletion src/modes/internal.activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default async function(dir: Path, { powder, ...opts }: { powder: PackageR
env ${off_string}
if [ "$1" != --shy ]; then
rm "${persistence}"
rm -f "${persistence}"
fi
unset -f _pkgx_dev_off _pkgx_should_deactivate_devenv
Expand Down
9 changes: 7 additions & 2 deletions src/modes/shellcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function() {
${sh} "${tmp}/shellcode/x.$$"
unset foo
fi
rm "${tmp}/shellcode/"?.$$
rm -f "${tmp}/shellcode/"?.$$
else
echo "pkgx: nothing to run" >&2
return 1
Expand Down Expand Up @@ -90,7 +90,12 @@ export default function() {
dev() {
if [ "$1" = 'off' ]; then
_pkgx_dev_off
if type _pkgx_dev_off >/dev/null 2>&1; then
_pkgx_dev_off
else
echo 'dev: environment not active' >&2
return 1
fi
elif type _pkgx_dev_off >/dev/null 2>&1; then
echo 'dev: environment already active' >&2
return 1
Expand Down
15 changes: 14 additions & 1 deletion src/modes/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import construct_env from "../prefab/construct-env.ts"
import resolve_arg0 from "../prefab/resolve-arg0.ts"
import { ProvidesError } from "../utils/error.ts"
import get_shebang from "../utils/get-shebang.ts"
import BaseLogger from "../utils/Logger.ts"
import execve from "../utils/execve.ts"
import host from "pkgx/utils/host.ts"
const { usePantry, useSync } = hooks
Expand Down Expand Up @@ -84,7 +85,19 @@ async function find_it(args: string[], dry: PackageRequirement[]) {
}

// be just works: do a sync in case this has been recently added to the pantry
await _internals.useSync()
const logger = new BaseLogger('sync')
const printer = {
syncing() {
logger.replace('fetching')
},
caching() {
logger.replace('caching')
},
syncd() {
logger.clear()
}
}
await _internals.useSync(printer)

wut = await find_arg0(args, dry)
if (wut) {
Expand Down
16 changes: 16 additions & 0 deletions src/prefab/construct-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ async fn(runner) {
await _internals.runtime_env(pkg, [])
}
})

await runner.step("multiple versions", async () => {
const tmp = Path.mktemp()

const installations = [
{ pkg: {project: "unicode.org", version: new SemVer("71.0.0")}, path: tmp.join("unicode.org/v71.0.0").mkdir('p') },
{ pkg: {project: "unicode.org", version: new SemVer("73.0.0")}, path: tmp.join("unicode.org/v73.0.0").mkdir('p') },
]
const stub3 = mock.stub(_internals, "runtime_env", async () => ({}))
try {
await _internals.mkenv({ installations })
} finally {
stub3.restore()
tmp.rm({recursive: true})
}
})
}})
5 changes: 3 additions & 2 deletions src/prefab/construct-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default async function(pkgenv: { installations: Installation[] }) {

///////////////////////// reworked from useShellEnv needs porting back to libpkgx
async function mkenv({installations}: {installations: Installation[]}) {
const projects = new Set(installations.map(x => x.pkg.project))
const projects = new Set(installations.map(x => `${x.pkg.project}@${x.pkg.version}`))
console.assert(projects.size == installations.length, "pkgx: env is being duped")

const common_vars: Record<string, OrderedSet<string>> = {}
Expand Down Expand Up @@ -160,5 +160,6 @@ class OrderedSet<T> {

////////////////////////////////////////////////////////////////////// internals
export const _internals = {
runtime_env: (pkg: Package, installations: Installation[]) => usePantry().project(pkg.project).runtime.env(pkg.version, installations)
runtime_env: (pkg: Package, installations: Installation[]) => usePantry().project(pkg.project).runtime.env(pkg.version, installations),
mkenv
}
15 changes: 14 additions & 1 deletion src/prefab/failsafe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { PackageNotFoundError, hooks } from "pkgx"
import Logger from "../utils/Logger.ts"
const { useSync } = hooks

export default async function failsafe<T>(body: () => Promise<T>): Promise<T> {
try {
return await body()
} catch (err) {
if (err instanceof PackageNotFoundError) {
await _internals.useSync()
const logger: Logger = new Logger('sync')
const printer = {
syncing() {
logger.replace('fetching')
},
caching() {
logger.replace('caching')
},
syncd() {
logger.clear()
}
}
await _internals.useSync(printer)
return body()
} else {
throw err
Expand Down
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
14 changes: 14 additions & 0 deletions src/utils/devenv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ Deno.test("devenv.ts", async runner => {
'package.json/engines/package.json',
'nodejs.org~16.16.1',
'npmjs.com~9.7.1',
'yarnpkg.com~1.22.10',
'pnpm.io~7.33.7',
],
[
'package.json/packageManager/package.json',
'[email protected]',
'nodejs.org'
],
[
'package.json/volta/package.json',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
],
[".node-version", "[email protected]"],
["python-version/std/.python-version", "python.org~3.10"],
Expand Down
Loading

0 comments on commit 5b69c95

Please sign in to comment.