@@ -7,15 +7,28 @@ import {
77
88 /**
99 * Resolve the command to invoke a new `mc` subprocess.
10- * - Dev: process.argv[1] ends with ".ts" → [bun, script]
11- * - Prod: compiled binary → [process.execPath]
10+ * - Dev / installed JS: Bun runs a script entrypoint → [bun, script]
11+ * - Compiled binary: no script entrypoint is available → [process.execPath]
1212 */
13-function getMcCommand(): string[] {
14- const script = process.argv[1];
15- if (script?.endsWith(".ts")) {
16- return [process.execPath, script];
13+export function resolveMcCommand(
14+ execPath: string,
15+ mainModule: string | undefined,
16+ argv1: string | undefined,
17+): string[] {
18+ const script =
19+ mainModule &&
20+ !mainModule.endsWith("/[eval]") &&
21+ !mainModule.endsWith("\\[eval]")
22+ ? mainModule
23+ : argv1;
24+ if (script && /\.(?:[cm]?[jt]s)$/.test(script)) {
25+ return [execPath, script];
1726 }
18- return [process.execPath];
27+ return [execPath];
28+}
29+
30+function getMcCommand(): string[] {
31+ return resolveMcCommand(process.execPath, Bun.main, process.argv[1]);
1932 }
2033
2134 // Loose recursion cap passed via environment so subprocess chains are bounded