Skip to content

Commit fccf199

Browse files
authored
Merge branch 'main' into add-local-install
2 parents 33afc98 + b010f90 commit fccf199

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ jobs:
6969
repo: pkgxdev/homebrew-made
7070
ref: main
7171
token: ${{secrets.GH_TOKEN}}
72-
inputs: '{ "formula": "pkgx" }'
72+
inputs: '{ "formula": "pkgm" }'

pkgm.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
#!/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
22
import { dirname, fromFileUrl, join } from "jsr:@std/path@^1";
33
import { ensureDir, existsSync } from "jsr:@std/fs@^1";
4-
import { parse as parse_args } from "jsr:@std/flags@0.224.0";
4+
import { parseArgs } from "jsr:@std/cli@^1";
55
import * as semver from "jsr:@std/semver@^1";
66

77
function standardPath() {
8-
const basePath = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
9-
// for pkgm installed via homebrew
10-
const homebrew = `${Deno.env.get("HOMEBREW_PREFIX") || "/opt/homebrew"}/bin`;
11-
if (Deno.build.os === "darwin") {
12-
return `${homebrew}:${basePath}`;
13-
} else {
14-
return basePath;
8+
let path = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
9+
10+
// for pkgx installed via homebrew
11+
let homebrewPrefix = "";
12+
switch (Deno.build.os) {
13+
case "darwin":
14+
homebrewPrefix = "/opt/homebrew"; // /usr/local is already in the path
15+
break;
16+
case "linux":
17+
homebrewPrefix = `/home/linuxbrew/.linuxbrew:${
18+
Deno.env.get("HOME")
19+
}/.linuxbrew`;
20+
break;
1521
}
22+
if (homebrewPrefix) {
23+
homebrewPrefix = Deno.env.get("HOMEBREW_PREFIX") ?? homebrewPrefix;
24+
path = `${homebrewPrefix}/bin:${path}`;
25+
}
26+
27+
return path;
1628
}
1729

18-
const parsedArgs = parse_args(Deno.args, {
30+
const parsedArgs = parseArgs(Deno.args, {
1931
alias: {
2032
v: "version",
2133
h: "help",
@@ -140,7 +152,17 @@ async function install(args: string[], basePath: string) {
140152
basePath,
141153
...to_install,
142154
];
143-
const cmd = needs_sudo ? "/usr/bin/sudo" : args.shift()!;
155+
let cmd = "";
156+
if (needs_sudo) {
157+
cmd = "/usr/bin/sudo";
158+
args.unshift(
159+
"-E", // we already cleared the env, it's safe
160+
"env",
161+
`PATH=${env.PATH}`,
162+
);
163+
} else {
164+
cmd = args.shift()!;
165+
}
144166
status = await new Deno.Command(cmd, { args, env, clearEnv: true })
145167
.spawn().status;
146168
Deno.exit(status.code);

0 commit comments

Comments
 (0)