Skip to content

Commit

Permalink
Find pkgx PATH before trying to execute it
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Feb 24, 2025
1 parent a92750f commit a6c450c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkgm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ async function install(args: string[], basePath: string) {
const env: Record<string, string> = {
"PATH": standardPath(),
};
const pkgx = get_pkgx();
const set = (key: string) => {
const x = Deno.env.get(key);
if (x) env[key] = x;
};
set("HOME");
set("PKGX_DIR");

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

args = [
"pkgx",
pkgx,
"deno^2.1",
"run",
"--ext=ts",
Expand Down Expand Up @@ -257,7 +258,7 @@ async function symlink(src: string, dst: string) {
"libexec",
"var",
"etc",
"ssl",
"ssl", // FIXME for ca-certs
]
) {
const foo = join(src, base);
Expand Down Expand Up @@ -368,3 +369,13 @@ function symlink_with_overwrite(src: string, dst: string) {
}
Deno.symlinkSync(src, dst);
}

function get_pkgx() {
for (const path of Deno.env.get("PATH")!.split(":")) {
const pkgx = join(path, "pkgx");
if (existsSync(pkgx)) {
return pkgx;
}
}
throw new Error("no `pkgx` found in `$PATH`");
}

0 comments on commit a6c450c

Please sign in to comment.