Add env var support for home dir

This commit is contained in:
Reinier Criel 2026-04-10 08:57:08 -07:00
parent 698a12082d
commit a0fb8d6b3d
4 changed files with 125 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import * as os from "os";
import fs from "fs";
import path from "path";
import { ECOSYSTEM_JS, ECOSYSTEM_PY } from "../config/settings.js";
import { getSafeChainDir } from "../config/environmentVariables.js";
import { safeSpawn } from "../utils/safeSpawn.js";
import { ui } from "../environment/userInteraction.js";
@ -121,18 +122,34 @@ export function getPackageManagerList() {
return `${tools.join(", ")}, and ${lastTool} commands`;
}
/**
* Returns the safe-chain base directory.
* Uses SAFE_CHAIN_DIR environment variable when set, otherwise defaults to ~/.safe-chain.
* @returns {string}
*/
export function getSafeChainBaseDir() {
return getSafeChainDir() ?? path.join(os.homedir(), ".safe-chain");
}
/**
* @returns {string}
*/
export function getBinDir() {
return path.join(getSafeChainBaseDir(), "bin");
}
/**
* @returns {string}
*/
export function getShimsDir() {
return path.join(os.homedir(), ".safe-chain", "shims");
return path.join(getSafeChainBaseDir(), "shims");
}
/**
* @returns {string}
*/
export function getScriptsDir() {
return path.join(os.homedir(), ".safe-chain", "scripts");
return path.join(getSafeChainBaseDir(), "scripts");
}
/**