Files
orca/src/cli/runtime/launch-user-data-path.ts
T
OrcaWinandOrcaWin 88b47bc7d8 [comment audit] Shorten CLI runtime and command-spec comments (#32283)
* chore: shorten process-host comments

* chore: audit CLI parsing and host-routing comments

* chore: remove stale host-selector restriction comment

* chore: shorten remaining CLI root comments

* Shorten CLI handler comments

* Shorten CLI runtime and command specification comments

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 08:54:49 -07:00

45 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { dirname, join, resolve } from 'node:path'
import { SERVE_USER_DATA_PATH_ENV } from '../../shared/serve-user-data-path'
import { getPlatformUserDataPath } from './metadata'
/** Dev builds read ORCA_DEV_USER_DATA_PATH rather than --user-data-dir. */
function launchesDevApp(env: NodeJS.ProcessEnv): boolean {
return env.ORCA_APP_EXECUTABLE_NEEDS_APP_ROOT === '1'
}
/** Resolve absolutely: the launched child runs from the app root, not the caller’s cwd. */
export function resolveLaunchUserDataPath(env: NodeJS.ProcessEnv = process.env): string {
if (env.ORCA_USER_DATA_PATH) {
return resolve(env.ORCA_USER_DATA_PATH)
}
if (launchesDevApp(env)) {
return resolve(
env.ORCA_DEV_USER_DATA_PATH || join(dirname(getPlatformUserDataPath()), 'orca-dev')
)
}
return getPlatformUserDataPath()
}
/** Pin the profile through both packaged and dev entry points. */
export function pinLaunchUserDataPath(
args: string[],
env: NodeJS.ProcessEnv,
userDataPath: string
): { args: string[]; env: NodeJS.ProcessEnv } {
const pinnedEnv: NodeJS.ProcessEnv = { ...env, ORCA_USER_DATA_PATH: userDataPath }
if (launchesDevApp(env)) {
pinnedEnv.ORCA_DEV_USER_DATA_PATH = userDataPath
}
return { args: [...args, `--user-data-dir=${userDataPath}`], env: pinnedEnv }
}
/** Serve checks this profile before acquiring its instance lock. */
export function pinServeUserDataPath(
args: string[],
env: NodeJS.ProcessEnv,
userDataPath: string
): { args: string[]; env: NodeJS.ProcessEnv } {
const pinned = pinLaunchUserDataPath(args, env, userDataPath)
return { args: pinned.args, env: { ...pinned.env, [SERVE_USER_DATA_PATH_ENV]: userDataPath } }
}