mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 10:43:30 +00:00
Skip empty home environment values while preserving nonempty caller selections and platform precedence. Setup, doctor, and uninstall now use the same fallback home instead of writing relative paths in the current directory. Validation: focused home tests and the public setup/doctor/uninstall lifecycle under Node 24.18. Package verification and pack dry run are included in the integrated gate. Fixes #2325
30 lines
956 B
TypeScript
30 lines
956 B
TypeScript
import { userInfo } from "node:os";
|
|
|
|
const firstNonempty = (...values: readonly (string | undefined)[]) =>
|
|
values.find(
|
|
(value): value is string => value !== undefined && value.length > 0,
|
|
);
|
|
|
|
/** Resolve the caller's selected home before consulting the host account. */
|
|
export const homeDirectoryFromEnvironment = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
platform: NodeJS.Platform,
|
|
): string => {
|
|
const windowsDriveHome =
|
|
environment.HOMEDRIVE !== undefined &&
|
|
environment.HOMEDRIVE.length > 0 &&
|
|
environment.HOMEPATH !== undefined &&
|
|
environment.HOMEPATH.length > 0
|
|
? `${environment.HOMEDRIVE}${environment.HOMEPATH}`
|
|
: undefined;
|
|
const selected =
|
|
platform === "win32"
|
|
? firstNonempty(
|
|
environment.USERPROFILE,
|
|
windowsDriveHome,
|
|
environment.HOME,
|
|
)
|
|
: firstNonempty(environment.HOME, environment.USERPROFILE);
|
|
return selected ?? userInfo().homedir;
|
|
};
|