Some fixes

This commit is contained in:
Reinier Criel 2026-04-14 16:02:46 -07:00
parent cdb87792df
commit bafa997a70
2 changed files with 20 additions and 6 deletions

View file

@ -93,13 +93,13 @@ derive_install_dir_from_binary() {
# Determines the installed safe-chain base directory for uninstall. # Determines the installed safe-chain base directory for uninstall.
# Prefers the binary-reported location, then infers it from PATH, then falls back to ~/.safe-chain. # Prefers the binary-reported location, then infers it from PATH, then falls back to ~/.safe-chain.
get_install_dir() { get_install_dir() {
reported_install_dir=$(get_reported_install_dir) reported_install_dir=$(get_reported_install_dir || true)
if [ -n "$reported_install_dir" ]; then if [ -n "$reported_install_dir" ]; then
printf '%s\n' "$reported_install_dir" printf '%s\n' "$reported_install_dir"
return 0 return 0
fi fi
command_path=$(get_safe_chain_command_path) command_path=$(get_safe_chain_command_path || true)
install_dir=$(derive_install_dir_from_binary "$command_path" || true) install_dir=$(derive_install_dir_from_binary "$command_path" || true)
if [ -n "$install_dir" ]; then if [ -n "$install_dir" ]; then
printf '%s\n' "$install_dir" printf '%s\n' "$install_dir"

View file

@ -39,19 +39,33 @@ export function getCertsDir() {
} }
/** /**
* @param {string} moduleUrl * Resolves the directory of the calling module.
* Falls back to __dirname when import.meta.url is unavailable (pkg CJS binary).
* @param {string | undefined} moduleUrl
* @returns {string}
*/
function resolveModuleDir(moduleUrl) {
if (moduleUrl) {
return path.dirname(fileURLToPath(moduleUrl));
}
// eslint-disable-next-line no-undef
return __dirname;
}
/**
* @param {string | undefined} moduleUrl
* @param {string} fileName * @param {string} fileName
* @returns {string} * @returns {string}
*/ */
export function getStartupScriptSourcePath(moduleUrl, fileName) { export function getStartupScriptSourcePath(moduleUrl, fileName) {
return path.join(path.dirname(fileURLToPath(moduleUrl)), "startup-scripts", fileName); return path.join(resolveModuleDir(moduleUrl), "startup-scripts", fileName);
} }
/** /**
* @param {string} moduleUrl * @param {string | undefined} moduleUrl
* @param {string} fileName * @param {string} fileName
* @returns {string} * @returns {string}
*/ */
export function getPathWrapperTemplatePath(moduleUrl, fileName) { export function getPathWrapperTemplatePath(moduleUrl, fileName) {
return path.join(path.dirname(fileURLToPath(moduleUrl)), "path-wrappers", "templates", fileName); return path.join(resolveModuleDir(moduleUrl), "path-wrappers", "templates", fileName);
} }