(args: string[])
| 93 | } |
| 94 | |
| 95 | export function getHappyCliCommand(args: string[]): HappyCliCommand { |
| 96 | // Compiled binary mode: just use the executable directly |
| 97 | if (isBunCompiled()) { |
| 98 | return { |
| 99 | command: resolveHappyCliExecutable(), |
| 100 | args |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | // Development mode: spawn with TypeScript entrypoint |
| 105 | const projectRoot = projectPath(); |
| 106 | const entrypoint = resolveEntrypoint(projectRoot); |
| 107 | const isBunRuntime = Boolean((process.versions as Record<string, string | undefined>).bun); |
| 108 | |
| 109 | if (isBunRuntime) { |
| 110 | // Bun can run TypeScript directly. |
| 111 | // Force Bun's cwd to the CLI project root so alias resolution via bunfig.toml |
| 112 | // keeps working even when external tools launch HAPI from another workspace. |
| 113 | return { |
| 114 | command: process.execPath, |
| 115 | args: ['--cwd', projectRoot, entrypoint, ...args] |
| 116 | }; |
| 117 | } |
| 118 | |
| 119 | // When vitest runs under Node.js, HAPI_BUN_EXEC can point to the bun binary so that |
| 120 | // spawned CLI child processes still run under bun (which is required for TypeScript entrypoints). |
| 121 | const bunExecOverride = process.env['HAPI_BUN_EXEC']?.trim(); |
| 122 | if (bunExecOverride && isCrossPlatformAbsolutePath(bunExecOverride) && existsSync(bunExecOverride)) { |
| 123 | return { |
| 124 | command: bunExecOverride, |
| 125 | args: ['--cwd', projectRoot, entrypoint, ...args] |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | // Node.js fallback: preserve execArgv (for compatibility) |
| 130 | return { |
| 131 | command: process.execPath, |
| 132 | args: [...process.execArgv, entrypoint, ...args] |
| 133 | }; |
| 134 | } |
| 135 | |
| 136 | export function spawnHappyCLI(args: string[], options: SpawnOptions = {}): ChildProcess { |
| 137 |
no test coverage detected