From 3c6e0d95bf1dfda2e0e6a4e3354c04d14234519d Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Thu, 9 Jul 2026 16:50:05 -0400 Subject: [PATCH] fix(release): install Homebrew executable path --- scripts/update-homebrew-tap.ts | 20 ++++++++++--------- tests/update-homebrew-tap.test.ts | 33 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 tests/update-homebrew-tap.test.ts diff --git a/scripts/update-homebrew-tap.ts b/scripts/update-homebrew-tap.ts index c7c6ce26..1702b3ff 100644 --- a/scripts/update-homebrew-tap.ts +++ b/scripts/update-homebrew-tap.ts @@ -25,7 +25,7 @@ interface GithubReleaseView { readonly assets?: unknown; } -interface ReleaseAssetInfo { +export interface ReleaseAssetInfo { readonly name: string; readonly sha256: string; } @@ -56,12 +56,14 @@ const HELP_TEXT = [ " --repo GitHub repo to query (default: hack-dance/hack)", ].join("\n"); -const parsed = parseArgs({ argv: Bun.argv.slice(2) }); -if (parsed.ok) { - process.exitCode = await main({ args: parsed.args }); -} else { - process.stderr.write(`${parsed.message}\n`); - process.exitCode = 1; +if (import.meta.main) { + const parsed = parseArgs({ argv: Bun.argv.slice(2) }); + if (parsed.ok) { + process.exitCode = await main({ args: parsed.args }); + } else { + process.stderr.write(`${parsed.message}\n`); + process.exitCode = 1; + } } async function main({ args }: { readonly args: Args }): Promise { @@ -246,7 +248,7 @@ function parseAssets({ return out; } -function renderFormula({ +export function renderFormula({ repo, tag, version, @@ -287,7 +289,7 @@ function renderFormula({ ' libexec.install "hack"', ' (libexec/"assets").install Dir["assets/*"] if (buildpath/"assets").directory?', ' (libexec/"assets/binaries").install Dir["binaries/*"] if (buildpath/"binaries").directory?', - ' bin.write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"', + ' (bin/"hack").write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"', " end", "", " test do", diff --git a/tests/update-homebrew-tap.test.ts b/tests/update-homebrew-tap.test.ts new file mode 100644 index 00000000..94447d24 --- /dev/null +++ b/tests/update-homebrew-tap.test.ts @@ -0,0 +1,33 @@ +import { expect, test } from "bun:test"; + +import { renderFormula } from "../scripts/update-homebrew-tap.ts"; + +test("renderFormula installs the wrapper at bin/hack", () => { + const formula = renderFormula({ + repo: "hack-dance/hack", + tag: "v3.3.3", + version: "3.3.3", + darwinArm64: { + name: "hack-3.3.3-darwin-arm64.tar.gz", + sha256: "arm64-sha", + }, + darwinX64: { + name: "hack-3.3.3-darwin-x86_64.tar.gz", + sha256: "x64-sha", + }, + linuxX64: { + name: "hack-3.3.3-linux-x86_64.tar.gz", + sha256: "linux-sha", + }, + }); + + expect(formula).toContain( + '(bin/"hack").write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"' + ); + expect(formula).not.toContain( + 'bin.write_env_script libexec/"hack", HACK_ASSETS_DIR: libexec/"assets"' + ); + expect(formula).toContain( + 'assert_match "hack", shell_output("#{bin}/hack --help")' + ); +});