From 1ece01ccbb56331eeca4de7b1bea542a53f772fd Mon Sep 17 00:00:00 2001 From: Aliou Diallo Date: Sun, 22 Mar 2026 14:59:11 +0100 Subject: [PATCH] fix: correct argv slice index for compiled Bun binary In a compiled Bun binary, process.argv has no script path at argv[1], so slice(2) was dropping the first real argument (the command). Detect compiled vs interpreted context and slice from index 1 or 2 accordingly. --- src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index faea1a8..cb50b4f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,15 @@ import { urlCommand } from "./commands/url"; import { getConfigPath } from "./config"; async function main(): Promise { - const args = process.argv.slice(2); + // Bun compiled binary: process.argv = ["/path/to/binary", "arg1", "arg2", ...] + // bun run script.ts: process.argv = ["/path/to/bun", "/path/to/script.ts", "arg1", ...] + // The compiled binary path won't end in .ts or .js + const scriptPath = process.argv[1] ?? ""; + const isCompiledBinary = + !scriptPath.endsWith(".ts") && + !scriptPath.endsWith(".js") && + !scriptPath.includes("bun"); + const args = process.argv.slice(isCompiledBinary ? 1 : 2); const options = parseArgs(args); if (options.version) { -- 2.51.2