fix: check npm exists before version check; reject unmatched platform assets in Match-GithubAsset
This commit is contained in:
+4
-1
@@ -227,6 +227,7 @@ function Detect-Installed {
|
||||
# 获取远程最新版本
|
||||
# ─────────────────────────────────────────
|
||||
function Get-RemoteNpmVersion {
|
||||
if (-not (Get-Command "npm" -ErrorAction SilentlyContinue)) { return $null }
|
||||
try {
|
||||
$ver = (& npm view $script:NPM_PACKAGE version 2>$null).Trim()
|
||||
if ($ver) { return $ver }
|
||||
@@ -286,11 +287,13 @@ function Match-GithubAsset {
|
||||
if ($isExcluded) { continue }
|
||||
|
||||
$score = 0
|
||||
foreach ($k in $platformKw) { if ($name -like "*$k*") { $score += 10; break } }
|
||||
$hasPlatform = $false
|
||||
foreach ($k in $platformKw) { if ($name -like "*$k*") { $score += 10; $hasPlatform = $true; break } }
|
||||
foreach ($k in $archKw) { if ($name -like "*$k*") { $score += 10; break } }
|
||||
if (-not ($name -match '\.(tar\.gz|tgz|zip|7z)$')) { $score += 5 }
|
||||
if ($name -like "*musl*") { $score -= 3 }
|
||||
|
||||
if (-not $hasPlatform) { continue }
|
||||
if ($score -gt $bestScore) {
|
||||
$bestScore = $score
|
||||
$bestAsset = $asset
|
||||
|
||||
Reference in New Issue
Block a user