fix: show actual npm install path instead of script working dir when hapi is from npm
This commit is contained in:
+14
-5
@@ -121,8 +121,6 @@ function Setup-InstallDir {
|
||||
$script:HAPI_DATA = Join-Path $script:INSTALL_DIR "hapi-data"
|
||||
$script:VERSION_FILE = Join-Path $script:INSTALL_DIR ".hapi-version"
|
||||
$script:SOURCE_FILE = Join-Path $script:INSTALL_DIR ".hapi-source"
|
||||
|
||||
Write-Ok "安装目录: $($script:INSTALL_DIR)"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
@@ -1193,9 +1191,19 @@ if ($Upgrade -or $Force -or $Source -or $SkipHub -or $InstallDir -or $isIexExecu
|
||||
Setup-InstallDir
|
||||
Detect-Installed
|
||||
if ($script:INSTALLED_VERSION) {
|
||||
$srcDisplay = $script:INSTALLED_SOURCE
|
||||
if ($srcDisplay -like "github:*") { $srcDisplay = $srcDisplay.Substring(7) }
|
||||
Write-Info "检测到已安装 HAPI CLI v$($script:INSTALLED_VERSION) (来源: $srcDisplay, 路径: $((Get-Command hapi -ErrorAction SilentlyContinue).Source))"
|
||||
if ($script:INSTALLED_SOURCE -eq "npm") {
|
||||
$npmRoot = & npm root -g 2>$null
|
||||
if (-not $npmRoot) { $npmRoot = if ($IsWindows) { "$env:APPDATA\npm\node_modules" } else { "/usr/lib/node_modules" } }
|
||||
$npmPkgDir = Join-Path $npmRoot $NPM_PACKAGE
|
||||
Write-Ok "HAPI CLI v$($script:INSTALLED_VERSION) (npm: $npmPkgDir)"
|
||||
} else {
|
||||
$srcDisplay = $script:INSTALLED_SOURCE
|
||||
if ($srcDisplay -like "github:*") { $srcDisplay = $srcDisplay.Substring(7) }
|
||||
$hapiPath = (Get-Command hapi -ErrorAction SilentlyContinue).Source
|
||||
Write-Ok "HAPI CLI v$($script:INSTALLED_VERSION) (来源: $srcDisplay, 目录: $($script:INSTALL_DIR))"
|
||||
}
|
||||
} else {
|
||||
Write-Ok "安装目录: $($script:INSTALL_DIR)"
|
||||
}
|
||||
Check-Prerequisites
|
||||
Run-QuickMode
|
||||
@@ -1210,6 +1218,7 @@ Write-Host "╚═════════════════════
|
||||
Write-Host ""
|
||||
|
||||
Setup-InstallDir
|
||||
Write-Ok "安装目录: $($script:INSTALL_DIR)"
|
||||
Check-Prerequisites
|
||||
Collect-Status
|
||||
|
||||
|
||||
+15
-7
@@ -261,8 +261,6 @@ setup_install_dir() {
|
||||
HAPI_DATA="$INSTALL_DIR/hapi-data"
|
||||
VERSION_FILE="$INSTALL_DIR/.hapi-version"
|
||||
SOURCE_FILE="$INSTALL_DIR/.hapi-source"
|
||||
|
||||
ok "安装目录: $INSTALL_DIR"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────
|
||||
@@ -1396,11 +1394,20 @@ run_quick_mode() {
|
||||
detect_installed
|
||||
|
||||
if [[ -n "$INSTALLED_VERSION" ]]; then
|
||||
local actual_path
|
||||
actual_path=$(command -v hapi 2>/dev/null || true)
|
||||
local src_display="$INSTALLED_SOURCE"
|
||||
[[ "$src_display" == github:* ]] && src_display="${src_display#github:}"
|
||||
info "检测到已安装 HAPI CLI v$INSTALLED_VERSION (来源: $src_display, 路径: $actual_path)"
|
||||
if [[ "$INSTALLED_SOURCE" == "npm" ]]; then
|
||||
local npm_root npm_pkg_dir
|
||||
npm_root=$(npm root -g 2>/dev/null || echo "/usr/lib/node_modules")
|
||||
npm_pkg_dir="$npm_root/$NPM_PACKAGE"
|
||||
ok "HAPI CLI v$INSTALLED_VERSION (npm: $npm_pkg_dir)"
|
||||
else
|
||||
local actual_path
|
||||
actual_path=$(command -v hapi 2>/dev/null || true)
|
||||
local src_display="$INSTALLED_SOURCE"
|
||||
[[ "$src_display" == github:* ]] && src_display="${src_display#github:}"
|
||||
ok "HAPI CLI v$INSTALLED_VERSION (来源: $src_display, 目录: $INSTALL_DIR)"
|
||||
fi
|
||||
else
|
||||
ok "安装目录: $INSTALL_DIR"
|
||||
fi
|
||||
|
||||
check_prerequisites
|
||||
@@ -1573,6 +1580,7 @@ main() {
|
||||
echo ""
|
||||
|
||||
setup_install_dir
|
||||
ok "安装目录: $INSTALL_DIR"
|
||||
check_prerequisites
|
||||
collect_status
|
||||
|
||||
|
||||
Reference in New Issue
Block a user