feat(cli): add Bun compiled binary runtime asset management

Introduce runtime path abstraction for Bun-compiled binaries that extracts
assets to ~/.happy/runtime/{version} instead of using project paths. This
enables proper distribution of CLI as a self-contained binary with embedded
tools (ripgrep, difftastic) and scripts that are extracted at runtime.
This commit is contained in:
weishu
2025-12-20 16:44:58 +08:00
parent 80725a2d34
commit f0493ce68d
11 changed files with 276 additions and 25 deletions
+20 -6
View File
@@ -1,10 +1,24 @@
import { dirname, resolve } from 'path';
import { dirname, resolve, join } from 'path';
import { fileURLToPath } from 'url';
import { configuration } from '@/configuration';
import packageJson from '../package.json';
const __dirname = dirname(fileURLToPath(import.meta.url));
const bunRuntime = (globalThis as typeof globalThis & { Bun?: { isCompiled?: boolean } }).Bun;
const isCompiled = Boolean(bunRuntime?.isCompiled);
export function projectPath() {
const path = resolve(__dirname, '..');
// console.log('path', path)
return path;
}
export function projectPath(): string {
return resolve(__dirname, '..');
}
export function runtimePath(): string {
if (!isCompiled) {
return projectPath();
}
return join(configuration.happyHomeDir, 'runtime', packageJson.version);
}
export function isBunCompiled(): boolean {
return isCompiled;
}