diff --git a/install-scripts/uninstall-safe-chain.sh b/install-scripts/uninstall-safe-chain.sh index abe235f..d215405 100755 --- a/install-scripts/uninstall-safe-chain.sh +++ b/install-scripts/uninstall-safe-chain.sh @@ -93,13 +93,13 @@ derive_install_dir_from_binary() { # 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. get_install_dir() { - reported_install_dir=$(get_reported_install_dir) + reported_install_dir=$(get_reported_install_dir || true) if [ -n "$reported_install_dir" ]; then printf '%s\n' "$reported_install_dir" return 0 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) if [ -n "$install_dir" ]; then printf '%s\n' "$install_dir" diff --git a/packages/safe-chain/src/config/safeChainDir.js b/packages/safe-chain/src/config/safeChainDir.js index 6762d0b..4d4f013 100644 --- a/packages/safe-chain/src/config/safeChainDir.js +++ b/packages/safe-chain/src/config/safeChainDir.js @@ -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 * @returns {string} */ 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 * @returns {string} */ 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); }