fix: set default TUNWG_PATH and support ~ in HAPI_HOME

Extract getHapiHome() helper to properly expand ~ prefix in HAPI_HOME
env var. Set TUNWG_PATH default to $HAPI_HOME/tunwg when not specified.
This commit is contained in:
weishu
2026-01-14 12:26:00 +08:00
parent 860124a772
commit 0163eb372d
+11 -1
View File
@@ -17,6 +17,12 @@ function isBunCompiled(): boolean {
return typeof process.execPath === 'string' && !process.execPath.includes('bun')
}
function getHapiHome(): string {
return process.env.HAPI_HOME
? process.env.HAPI_HOME.replace(/^~/, homedir())
: join(homedir(), '.hapi')
}
function getPlatformDir(): string {
const platformName = platform()
const archName = arch()
@@ -39,7 +45,7 @@ function getTunwgPath(): string {
const tunwgBinary = isWin ? 'tunwg.exe' : 'tunwg'
if (isBunCompiled()) {
const hapiHome = process.env.HAPI_HOME || join(homedir(), '.hapi')
const hapiHome = getHapiHome()
const packageJson = require('../../../cli/package.json')
const runtimePath = join(hapiHome, 'runtime', packageJson.version)
return join(runtimePath, 'tools', 'tunwg', tunwgBinary)
@@ -106,6 +112,10 @@ export class TunnelManager {
const env: Record<string, string> = { ...process.env as Record<string, string> }
if (!env.TUNWG_PATH) {
env.TUNWG_PATH = join(getHapiHome(), 'tunwg')
}
if (this.config.apiDomain) {
env.TUNWG_API = this.config.apiDomain
}