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

Find pkgx PATH before trying to execute it #32

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
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
19 changes: 15 additions & 4 deletions pkgm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/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
#!/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
import { SemVer, semver } from "https://deno.land/x/[email protected]/mod.ts";
import { dirname, fromFileUrl, join } from "jsr:@std/path@^1";
import { ensureDir, existsSync } from "jsr:@std/fs@^1";
Expand Down 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`");
}
Loading