Skip to content

Commit 3c6e0d9

Browse files
committed
fix(release): install Homebrew executable path
1 parent 2efa5ae commit 3c6e0d9

2 files changed

Lines changed: 44 additions & 9 deletions

File tree

scripts/update-homebrew-tap.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface GithubReleaseView {
2525
readonly assets?: unknown;
2626
}
2727

28-
interface ReleaseAssetInfo {
28+
export interface ReleaseAssetInfo {
2929
readonly name: string;
3030
readonly sha256: string;
3131
}
@@ -56,12 +56,14 @@ const HELP_TEXT = [
5656
" --repo <owner/name> GitHub repo to query (default: hack-dance/hack)",
5757
].join("\n");
5858

59-
const parsed = parseArgs({ argv: Bun.argv.slice(2) });
60-
if (parsed.ok) {
61-
process.exitCode = await main({ args: parsed.args });
62-
} else {
63-
process.stderr.write(`${parsed.message}\n`);
64-
process.exitCode = 1;
59+
if (import.meta.main) {
60+
const parsed = parseArgs({ argv: Bun.argv.slice(2) });
61+
if (parsed.ok) {
62+
process.exitCode = await main({ args: parsed.args });
63+
} else {
64+
process.stderr.write(`${parsed.message}\n`);
65+
process.exitCode = 1;
66+
}
6567
}
6668

6769
async function main({ args }: { readonly args: Args }): Promise<number> {
@@ -246,7 +248,7 @@ function parseAssets({
246248
return out;
247249
}
248250

249-
function renderFormula({
251+
export function renderFormula({
250252
repo,
251253
tag,
252254
version,
@@ -287,7 +289,7 @@ function renderFormula({
287289
' libexec.install "hack"',
288290
' (libexec/"assets").install Dir["assets/*"] if (buildpath/"assets").directory?',
289291
' (libexec/"assets/binaries").install Dir["binaries/*"] if (buildpath/"binaries").directory?',
290-
' bin.write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"',
292+
' (bin/"hack").write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"',
291293
" end",
292294
"",
293295
" test do",

tests/update-homebrew-tap.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect, test } from "bun:test";
2+
3+
import { renderFormula } from "../scripts/update-homebrew-tap.ts";
4+
5+
test("renderFormula installs the wrapper at bin/hack", () => {
6+
const formula = renderFormula({
7+
repo: "hack-dance/hack",
8+
tag: "v3.3.3",
9+
version: "3.3.3",
10+
darwinArm64: {
11+
name: "hack-3.3.3-darwin-arm64.tar.gz",
12+
sha256: "arm64-sha",
13+
},
14+
darwinX64: {
15+
name: "hack-3.3.3-darwin-x86_64.tar.gz",
16+
sha256: "x64-sha",
17+
},
18+
linuxX64: {
19+
name: "hack-3.3.3-linux-x86_64.tar.gz",
20+
sha256: "linux-sha",
21+
},
22+
});
23+
24+
expect(formula).toContain(
25+
'(bin/"hack").write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"'
26+
);
27+
expect(formula).not.toContain(
28+
'bin.write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"'
29+
);
30+
expect(formula).toContain(
31+
'assert_match "hack", shell_output("#{bin}/hack --help")'
32+
);
33+
});

0 commit comments

Comments
 (0)