fix: inherit install source from detected INSTALLED_SOURCE instead of always defaulting to npm

This commit is contained in:
i
2026-06-02 00:42:26 +08:00
parent cd5b581908
commit 4a8944fb9e
2 changed files with 16 additions and 4 deletions
+9 -1
View File
@@ -1039,7 +1039,15 @@ function Check-Prerequisites {
# 快速模式:向后兼容的命令行参数
# ─────────────────────────────────────────
function Run-QuickMode {
$script:SELECTED_SOURCE = if ($Source) { $Source } else { "npm" }
if ($Source) {
$script:SELECTED_SOURCE = $Source
} else {
$script:SELECTED_SOURCE = switch ($script:INSTALLED_SOURCE) {
"npm" { "npm" }
{ $_ -like "github:*" } { $_.Substring(7) }
default { "npm" }
}
}
$script:REMOTE_VERSION = Get-RemoteVersion -source $script:SELECTED_SOURCE
+7 -3
View File
@@ -1413,7 +1413,13 @@ run_quick_mode() {
github-fork|gh-fork|fork|self) SELECTED_SOURCE="github-fork" ;;
esac
fi
[[ -z "$SELECTED_SOURCE" ]] && SELECTED_SOURCE="npm"
if [[ -z "$SELECTED_SOURCE" ]]; then
case "$INSTALLED_SOURCE" in
npm) SELECTED_SOURCE="npm" ;;
github:*) SELECTED_SOURCE="${INSTALLED_SOURCE#github:}" ;;
*) SELECTED_SOURCE="npm" ;;
esac
fi
while ! get_remote_version "$SELECTED_SOURCE"; do
warn "无法从 $SELECTED_SOURCE 获取远程版本"
@@ -1458,8 +1464,6 @@ run_quick_mode() {
echo ""
done
detect_installed
if [[ "$UPGRADE_ONLY" == true ]]; then
if [[ -z "$INSTALLED_VERSION" || "$INSTALLED_VERSION" == "unknown" ]]; then
err "未检测到已安装的 HAPI CLI,无法升级"