




















@@ -857,25 +857,27 @@ fix_npm_prefix_if_needed() {
857857 log "Configured npm prefix to ${target}"
858858}
859859860-expand_npm_config_path() {
861-local path="$1"
862-if [[ -z "$path" ]]; then
860+resolve_npm_config_path() {
861+local raw="$1"
862+if [[ -z "$raw" || "$raw" == "null" || "$raw" == "undefined" ]]; then
863863return 1
864864fi
865-case "$path" in
866-"\${HOME}/"*) path="${HOME:-}/${path#\$\{HOME\}/}" ;;
867-"\$HOME/"*) path="${HOME:-}/${path#\$HOME/}" ;;
868- [~]/*) path="${HOME:-}/${path#\~/}" ;;
869-esac
870-printf '%s\n' "$path"
865+if [[ "$raw" == \~/* && -n "${HOME:-}" ]]; then
866+printf '%s\n' "${HOME}/${raw#"~/"}"
867+return 0
868+fi
869+if [[ "$raw" == "\${HOME}/"* && -n "${HOME:-}" ]]; then
870+printf '%s\n' "${HOME}/${raw#"\${HOME}/"}"
871+return 0
872+fi
873+printf '%s\n' "$raw"
871874}
872875873876npm_config_file_has_key() {
874-local file
875- file="$(expand_npm_config_path "$1")" || return 1
877+local file="$1"
876878local key="$2"
877879 [[ -f "$file" ]] || return 1
878- grep -E "^[[:space:]]*${key}[[:space:]]*=" "$file" >/dev/null 2>&1
880+ grep -Eiq "^[[:space:]]*${key}[[:space:]]*=" "$file"
879881}
880882881883npm_command_path() {
@@ -899,36 +901,39 @@ npm_builtin_config_path() {
899901printf '%s\n' "${npm_root}/npmrc"
900902}
901903902-npm_raw_config_has_key() {
903-local key="$1"
904-local npm_cmd="${2:-npm}"
905-local user_config="${NPM_CONFIG_USERCONFIG:-${npm_config_userconfig:-}}"
906-local global_config="${NPM_CONFIG_GLOBALCONFIG:-${npm_config_globalconfig:-}}"
907-local prefix="${NPM_CONFIG_PREFIX:-${npm_config_prefix:-}}"
908-909- npm_config_file_has_key ".npmrc" "$key" && return 0
910-if [[ -n "$user_config" ]]; then
911- npm_config_file_has_key "$user_config" "$key" && return 0
904+npm_config_has_raw_key() {
905+local npm_cmd="$1"
906+local key="$2"
907+local raw=""
908+local file=""
909+local -a files=()
910+911+ raw="${NPM_CONFIG_USERCONFIG:-${npm_config_userconfig:-}}"
912+if [[ -n "$raw" ]]; then
913+ file="$(resolve_npm_config_path "$raw" 2>/dev/null || true)"
914+ [[ -n "$file" ]] && files+=("$file")
912915elif [[ -n "${HOME:-}" ]]; then
913- npm_config_file_has_key "${HOME}/.npmrc" "$key" && return 0
914-fi
915-if [[ -n "$global_config" ]]; then
916- npm_config_file_has_key "$global_config" "$key" && return 0
917-else
918-local resolved_global_config=""
919- resolved_global_config="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$npm_cmd" config get globalconfig 2>/dev/null || true)"
920-if [[ -n "$resolved_global_config" && "$resolved_global_config" != "null" && "$resolved_global_config" != "undefined" ]]; then
921- npm_config_file_has_key "$resolved_global_config" "$key" && return 0
922-fi
923-fi
924-if [[ -n "$prefix" ]]; then
925- npm_config_file_has_key "${prefix}/etc/npmrc" "$key" && return 0
916+ files+=("${HOME}/.npmrc")
926917fi
927-local builtin_config=""
928- builtin_config="$(npm_builtin_config_path "$npm_cmd" 2>/dev/null || true)"
929-if [[ -n "$builtin_config" ]]; then
930- npm_config_file_has_key "$builtin_config" "$key" && return 0
918+919+ raw="${NPM_CONFIG_GLOBALCONFIG:-${npm_config_globalconfig:-}}"
920+if [[ -n "$raw" ]]; then
921+ file="$(resolve_npm_config_path "$raw" 2>/dev/null || true)"
922+ [[ -n "$file" ]] && files+=("$file")
931923fi
924+925+ raw="$(env -u NPM_CONFIG_BEFORE -u npm_config_before -u NPM_CONFIG_MIN_RELEASE_AGE -u npm_config_min_release_age -u npm_config_min-release-age "$npm_cmd" config get globalconfig --global 2>/dev/null || true)"
926+ file="$(resolve_npm_config_path "$raw" 2>/dev/null || true)"
927+ [[ -n "$file" ]] && files+=("$file")
928+929+ file="$(npm_builtin_config_path "$npm_cmd" 2>/dev/null || true)"
930+ [[ -n "$file" ]] && files+=("$file")
931+932+for file in "${files[@]}"; do
933+if npm_config_file_has_key "$file" "$key"; then
934+return 0
935+fi
936+done
932937return 1
933938}
934939@@ -939,10 +944,12 @@ install_openclaw() {
939944fi
940945local freshness_flag="--min-release-age=0"
941946local min_release_age=""
942- min_release_age="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$(npm_bin)" config get min-release-age 2>/dev/null || true)"
943-if ! npm_raw_config_has_key "min-release-age" "$(npm_bin)" && [[ -z "$min_release_age" || "$min_release_age" == "null" || "$min_release_age" == "undefined" ]]; then
947+ min_release_age="$(env -u NPM_CONFIG_BEFORE -u npm_config_before "$(npm_bin)" config get min-release-age --global 2>/dev/null || true)"
948+if npm_config_has_raw_key "$(npm_bin)" "min-release-age"; then
949+ freshness_flag="--min-release-age=0"
950+elif [[ -z "$min_release_age" || "$min_release_age" == "null" || "$min_release_age" == "undefined" ]]; then
944951local before_value=""
945- 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)"
952+ 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 --global 2>/dev/null || true)"
946953if [[ -n "$before_value" && "$before_value" != "null" && "$before_value" != "undefined" ]]; then
947954 freshness_flag="--before=$(date -u '+%Y-%m-%dT%H:%M:%S.000Z')"
948955fi
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。