




















@@ -666,6 +666,81 @@ fix_npm_prefix_if_needed() {
666666 log "Configured npm prefix to ${target}"
667667}
668668669+expand_npm_config_path() {
670+local path="$1"
671+if [[ -z "$path" ]]; then
672+return 1
673+fi
674+case "$path" in
675+"\${HOME}/"*) path="${HOME:-}/${path#\$\{HOME\}/}" ;;
676+"\$HOME/"*) path="${HOME:-}/${path#\$HOME/}" ;;
677+ [~]/*) path="${HOME:-}/${path#\~/}" ;;
678+esac
679+printf '%s\n' "$path"
680+}
681+682+npm_config_file_has_key() {
683+local file
684+ file="$(expand_npm_config_path "$1")" || return 1
685+local key="$2"
686+ [[ -f "$file" ]] || return 1
687+ grep -E "^[[:space:]]*${key}[[:space:]]*=" "$file" >/dev/null 2>&1
688+}
689+690+npm_command_path() {
691+local npm_cmd="$1"
692+local npm_path="$npm_cmd"
693+if [[ "$npm_path" != */* ]]; then
694+ npm_path="$(command -v "$npm_cmd" 2>/dev/null)" || return 1
695+fi
696+if command -v node >/dev/null 2>&1; then
697+ node -e 'const fs = require("node:fs"); console.log(fs.realpathSync(process.argv[1]));' "$npm_path" 2>/dev/null && return 0
698+fi
699+printf '%s\n' "$npm_path"
700+}
701+702+npm_builtin_config_path() {
703+local npm_cmd="$1"
704+local npm_path
705+ npm_path="$(npm_command_path "$npm_cmd")" || return 1
706+local npm_root
707+ npm_root="$(cd "$(dirname "$npm_path")/.." >/dev/null 2>&1 && pwd -P)" || return 1
708+printf '%s\n' "${npm_root}/npmrc"
709+}
710+711+npm_raw_config_has_key() {
712+local key="$1"
713+local npm_cmd="${2:-npm}"
714+local user_config="${NPM_CONFIG_USERCONFIG:-${npm_config_userconfig:-}}"
715+local global_config="${NPM_CONFIG_GLOBALCONFIG:-${npm_config_globalconfig:-}}"
716+local prefix="${NPM_CONFIG_PREFIX:-${npm_config_prefix:-}}"
717+718+ npm_config_file_has_key ".npmrc" "$key" && return 0
719+if [[ -n "$user_config" ]]; then
720+ npm_config_file_has_key "$user_config" "$key" && return 0
721+elif [[ -n "${HOME:-}" ]]; then
722+ npm_config_file_has_key "${HOME}/.npmrc" "$key" && return 0
723+fi
724+if [[ -n "$global_config" ]]; then
725+ npm_config_file_has_key "$global_config" "$key" && return 0
726+else
727+local resolved_global_config=""
728+ resolved_global_config="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$npm_cmd" config get globalconfig 2>/dev/null || true)"
729+if [[ -n "$resolved_global_config" && "$resolved_global_config" != "null" && "$resolved_global_config" != "undefined" ]]; then
730+ npm_config_file_has_key "$resolved_global_config" "$key" && return 0
731+fi
732+fi
733+if [[ -n "$prefix" ]]; then
734+ npm_config_file_has_key "${prefix}/etc/npmrc" "$key" && return 0
735+fi
736+local builtin_config=""
737+ builtin_config="$(npm_builtin_config_path "$npm_cmd" 2>/dev/null || true)"
738+if [[ -n "$builtin_config" ]]; then
739+ npm_config_file_has_key "$builtin_config" "$key" && return 0
740+fi
741+return 1
742+}
743+669744install_openclaw() {
670745local requested="${OPENCLAW_VERSION:-latest}"
671746if is_openclaw_source_package_install_spec "$requested"; then
@@ -674,7 +749,7 @@ install_openclaw() {
674749local freshness_flag="--min-release-age=0"
675750local min_release_age=""
676751 min_release_age="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$(npm_bin)" config get min-release-age 2>/dev/null || true)"
677-if [[ -z "$min_release_age" || "$min_release_age" == "null" || "$min_release_age" == "undefined" ]]; then
752+if ! npm_raw_config_has_key "min-release-age" "$(npm_bin)" && [[ -z "$min_release_age" || "$min_release_age" == "null" || "$min_release_age" == "undefined" ]]; then
678753local before_value=""
679754 before_value="$(env -u NPM_CONFIG_MIN_RELEASE_AGE -u npm_config_min_release_age -u npm_config_min-release-age "$(npm_bin)" config get before 2>/dev/null || true)"
680755if [[ -n "$before_value" && "$before_value" != "null" && "$before_value" != "undefined" ]]; then
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。