import type { Context } from "@earendil-works/chord"; import { getOrThrow } from "@earendil-works/pi-durable/env"; import type { Environment } from "@berry/api"; export async function userDirectory( env: Environment, variable: string, fallback: string[], context: Context, ): Promise { const value = Object.entries(env.variables).find(([name]) => env.platform === "win32" ? name.toUpperCase() === variable : name === variable )?.[1]; return getOrThrow( await (value ? env.absolutePath(value, context) : env.joinPath([env.home, ...fallback], context)), ); }