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:HAPI_DATA = Join-Path $script:INSTALL_DIR "hapi-data"
|
||||||
$script:VERSION_FILE = Join-Path $script:INSTALL_DIR ".hapi-version"
|
$script:VERSION_FILE = Join-Path $script:INSTALL_DIR ".hapi-version"
|
||||||
$script:SOURCE_FILE = Join-Path $script:INSTALL_DIR ".hapi-source"
|
$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
|
Setup-InstallDir
|
||||||
Detect-Installed
|
Detect-Installed
|
||||||
if ($script:INSTALLED_VERSION) {
|
if ($script:INSTALLED_VERSION) {
|
||||||
$srcDisplay = $script:INSTALLED_SOURCE
|
if ($script:INSTALLED_SOURCE -eq "npm") {
|
||||||
if ($srcDisplay -like "github:*") { $srcDisplay = $srcDisplay.Substring(7) }
|
$npmRoot = & npm root -g 2>$null
|
||||||
Write-Info "检测到已安装 HAPI CLI v$($script:INSTALLED_VERSION) (来源: $srcDisplay, 路径: $((Get-Command hapi -ErrorAction SilentlyContinue).Source))"
|
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
|
Check-Prerequisites
|
||||||
Run-QuickMode
|
Run-QuickMode
|
||||||
@@ -1210,6 +1218,7 @@ Write-Host "╚═════════════════════
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
Setup-InstallDir
|
Setup-InstallDir
|
||||||
|
Write-Ok "安装目录: $($script:INSTALL_DIR)"
|
||||||
Check-Prerequisites
|
Check-Prerequisites
|
||||||
Collect-Status
|
Collect-Status
|
||||||
|
|
||||||
|
|||||||
+15
-7
@@ -261,8 +261,6 @@ setup_install_dir() {
|
|||||||
HAPI_DATA="$INSTALL_DIR/hapi-data"
|
HAPI_DATA="$INSTALL_DIR/hapi-data"
|
||||||
VERSION_FILE="$INSTALL_DIR/.hapi-version"
|
VERSION_FILE="$INSTALL_DIR/.hapi-version"
|
||||||
SOURCE_FILE="$INSTALL_DIR/.hapi-source"
|
SOURCE_FILE="$INSTALL_DIR/.hapi-source"
|
||||||
|
|
||||||
ok "安装目录: $INSTALL_DIR"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─────────────────────────────────────────
|
# ─────────────────────────────────────────
|
||||||
@@ -1396,11 +1394,20 @@ run_quick_mode() {
|
|||||||
detect_installed
|
detect_installed
|
||||||
|
|
||||||
if [[ -n "$INSTALLED_VERSION" ]]; then
|
if [[ -n "$INSTALLED_VERSION" ]]; then
|
||||||
local actual_path
|
if [[ "$INSTALLED_SOURCE" == "npm" ]]; then
|
||||||
actual_path=$(command -v hapi 2>/dev/null || true)
|
local npm_root npm_pkg_dir
|
||||||
local src_display="$INSTALLED_SOURCE"
|
npm_root=$(npm root -g 2>/dev/null || echo "/usr/lib/node_modules")
|
||||||
[[ "$src_display" == github:* ]] && src_display="${src_display#github:}"
|
npm_pkg_dir="$npm_root/$NPM_PACKAGE"
|
||||||
info "检测到已安装 HAPI CLI v$INSTALLED_VERSION (来源: $src_display, 路径: $actual_path)"
|
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
|
fi
|
||||||
|
|
||||||
check_prerequisites
|
check_prerequisites
|
||||||
@@ -1573,6 +1580,7 @@ main() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
setup_install_dir
|
setup_install_dir
|
||||||
|
ok "安装目录: $INSTALL_DIR"
|
||||||
check_prerequisites
|
check_prerequisites
|
||||||
collect_status
|
collect_status
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user