fix: remove npm version/source file writes, infer from path instead

npm installs to global node_modules, so writing .hapi-version and
.hapi-source under /opt/hapi (or C:\hapi) is unnecessary and fails
when that directory doesn't exist yet.

- Stop writing VERSION_FILE and SOURCE_FILE in install_from_npm
- Infer "npm" source from hapi path in print_result when files absent
- Sync both install.sh and install.ps1

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
i
2026-06-01 23:18:11 +08:00
co-authored by HAPI
parent 8cb35598af
commit 65c6e960a9
2 changed files with 32 additions and 5 deletions
+13 -4
View File
@@ -413,9 +413,6 @@ function Install-FromNpm {
$installedVer = ((& hapi --version 2>$null) | Select-String -Pattern '\d+\.\d+\.\d+' | ForEach-Object { $_.Matches.Value } | Select-Object -First 1)
if (-not $installedVer) { $installedVer = "unknown" }
$installedVer | Set-Content $script:VERSION_FILE -Encoding UTF8
"npm" | Set-Content $script:SOURCE_FILE -Encoding UTF8
Write-Ok "HAPI CLI v$installedVer 安装成功 (来源: npm, 路径: $($hapi.Source))"
return $true
}
@@ -855,7 +852,19 @@ function Print-Result {
} else {
(Get-Content $VERSION_FILE -Raw).Trim()
}
$hapiSource = if (Test-Path $SOURCE_FILE) { (Get-Content $SOURCE_FILE -Raw).Trim() } else { "unknown" }
$hapiSource = if (Test-Path $SOURCE_FILE) {
(Get-Content $SOURCE_FILE -Raw).Trim()
} elseif ($script:INSTALLED_SOURCE) {
$script:INSTALLED_SOURCE
} else {
$currentHapi = (Get-Command hapi -ErrorAction SilentlyContinue).Source
if ($currentHapi -and $currentHapi -notlike "$script:HAPI_BIN_DIR*") {
$npmPrefix = (& npm config get prefix 2>$null).Trim()
if ($currentHapi -like "$npmPrefix*") { "npm" } else { "unknown" }
} else {
"unknown"
}
}
Write-Host ""
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor Green