Skip to content

Commit ef0bc64

Browse files
committed
Find pkgx PATH before trying to execute it
1 parent a92750f commit ef0bc64

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

pkgm.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S pkgx --quiet deno^2.1 run --ext=ts --allow-sys=uid --allow-run --allow-env=PKGX_DIR,HOMEBREW_PREFIX,HOME --allow-read=/usr/local/pkgs,${HOME}/.local/pkgs
1+
#!/usr/bin/env -S pkgx --quiet deno^2.1 run --ext=ts --allow-sys=uid --allow-run --allow-env=PKGX_DIR,HOMEBREW_PREFIX,HOME,PATH --allow-read
22
import { SemVer, semver } from "https://deno.land/x/libpkgx@v0.20.3/mod.ts";
33
import { dirname, fromFileUrl, join } from "jsr:@std/path@^1";
44
import { ensureDir, existsSync } from "jsr:@std/fs@^1";
@@ -100,14 +100,15 @@ async function install(args: string[], basePath: string) {
100100
const env: Record<string, string> = {
101101
"PATH": standardPath(),
102102
};
103+
const pkgx = get_pkgx();
103104
const set = (key: string) => {
104105
const x = Deno.env.get(key);
105106
if (x) env[key] = x;
106107
};
107108
set("HOME");
108109
set("PKGX_DIR");
109110

110-
const proc = new Deno.Command("pkgx", {
111+
const proc = new Deno.Command(pkgx, {
111112
args: [...args, "--json=v1"],
112113
stdout: "piped",
113114
env,
@@ -133,7 +134,7 @@ async function install(args: string[], basePath: string) {
133134
const runtime_env = expand_runtime_env(json, basePath);
134135

135136
args = [
136-
"pkgx",
137+
pkgx,
137138
"deno^2.1",
138139
"run",
139140
"--ext=ts",
@@ -257,7 +258,7 @@ async function symlink(src: string, dst: string) {
257258
"libexec",
258259
"var",
259260
"etc",
260-
"ssl",
261+
"ssl", // FIXME for ca-certs
261262
]
262263
) {
263264
const foo = join(src, base);
@@ -368,3 +369,13 @@ function symlink_with_overwrite(src: string, dst: string) {
368369
}
369370
Deno.symlinkSync(src, dst);
370371
}
372+
373+
function get_pkgx() {
374+
for (const path of Deno.env.get("PATH")!.split(":")) {
375+
const pkgx = join(path, "pkgx");
376+
if (existsSync(pkgx)) {
377+
return pkgx;
378+
}
379+
}
380+
throw new Error("no `pkgx` found in `$PATH`");
381+
}

0 commit comments

Comments
 (0)