fix: npm install -g 后智能搜索全局 bin 路径避免命令找不到
npm install -g 成功后命令可能不在 PATH 中(尤其使用 fnm 管理的 Node.js)。 安装后通过 npm config get prefix 和 %APPDATA%\npm 查找全局 bin 目录 并自动加入当前会话 PATH。
This commit is contained in:
@@ -241,6 +241,19 @@ function Install-Tool {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 如果命令不在 PATH 中,尝试查找 npm 全局 bin 目录
|
||||||
|
if (-not (Test-Command $ToolCommand)) {
|
||||||
|
Write-Info "正在搜索 npm 全局安装位置..."
|
||||||
|
$npmPrefix = & npm config get prefix 2>$null
|
||||||
|
if ($npmPrefix -and (Test-Path $npmPrefix)) {
|
||||||
|
$env:Path = "$npmPrefix;$env:Path"
|
||||||
|
}
|
||||||
|
$appDataNpm = "$env:APPDATA\npm"
|
||||||
|
if ((Test-Path $appDataNpm) -and ($env:Path -notlike "*$appDataNpm*")) {
|
||||||
|
$env:Path = "$appDataNpm;$env:Path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Command $ToolCommand) {
|
if (Test-Command $ToolCommand) {
|
||||||
Write-Success "$ToolName 安装成功!"
|
Write-Success "$ToolName 安装成功!"
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
@@ -239,6 +239,19 @@ function Install-Tool {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 如果命令不在 PATH 中,尝试查找 npm 全局 bin 目录
|
||||||
|
if (-not (Test-Command $ToolCommand)) {
|
||||||
|
Write-Info "正在搜索 npm 全局安装位置..."
|
||||||
|
$npmPrefix = & npm config get prefix 2>$null
|
||||||
|
if ($npmPrefix -and (Test-Path $npmPrefix)) {
|
||||||
|
$env:Path = "$npmPrefix;$env:Path"
|
||||||
|
}
|
||||||
|
$appDataNpm = "$env:APPDATA\npm"
|
||||||
|
if ((Test-Path $appDataNpm) -and ($env:Path -notlike "*$appDataNpm*")) {
|
||||||
|
$env:Path = "$appDataNpm;$env:Path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Command $ToolCommand) {
|
if (Test-Command $ToolCommand) {
|
||||||
Write-Success "$ToolName 安装成功!"
|
Write-Success "$ToolName 安装成功!"
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
@@ -241,6 +241,19 @@ function Install-Tool {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 如果命令不在 PATH 中,尝试查找 npm 全局 bin 目录
|
||||||
|
if (-not (Test-Command $ToolCommand)) {
|
||||||
|
Write-Info "正在搜索 npm 全局安装位置..."
|
||||||
|
$npmPrefix = & npm config get prefix 2>$null
|
||||||
|
if ($npmPrefix -and (Test-Path $npmPrefix)) {
|
||||||
|
$env:Path = "$npmPrefix;$env:Path"
|
||||||
|
}
|
||||||
|
$appDataNpm = "$env:APPDATA\npm"
|
||||||
|
if ((Test-Path $appDataNpm) -and ($env:Path -notlike "*$appDataNpm*")) {
|
||||||
|
$env:Path = "$appDataNpm;$env:Path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Command $ToolCommand) {
|
if (Test-Command $ToolCommand) {
|
||||||
Write-Success "$ToolName 安装成功!"
|
Write-Success "$ToolName 安装成功!"
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
@@ -240,6 +240,19 @@ function Install-Tool {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 如果命令不在 PATH 中,尝试查找 npm 全局 bin 目录
|
||||||
|
if (-not (Test-Command $ToolCommand)) {
|
||||||
|
Write-Info "正在搜索 npm 全局安装位置..."
|
||||||
|
$npmPrefix = & npm config get prefix 2>$null
|
||||||
|
if ($npmPrefix -and (Test-Path $npmPrefix)) {
|
||||||
|
$env:Path = "$npmPrefix;$env:Path"
|
||||||
|
}
|
||||||
|
$appDataNpm = "$env:APPDATA\npm"
|
||||||
|
if ((Test-Path $appDataNpm) -and ($env:Path -notlike "*$appDataNpm*")) {
|
||||||
|
$env:Path = "$appDataNpm;$env:Path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Command $ToolCommand) {
|
if (Test-Command $ToolCommand) {
|
||||||
Write-Success "$ToolName 安装成功!"
|
Write-Success "$ToolName 安装成功!"
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
14
setup.ps1
14
setup.ps1
@@ -264,6 +264,20 @@ function Install-Tool {
|
|||||||
return $false
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 如果命令不在 PATH 中,尝试查找 npm 全局 bin 目录
|
||||||
|
if (-not (Test-Command $Tool.Command)) {
|
||||||
|
Write-Info "正在搜索 npm 全局安装位置..."
|
||||||
|
$npmPrefix = & npm config get prefix 2>$null
|
||||||
|
if ($npmPrefix -and (Test-Path $npmPrefix)) {
|
||||||
|
$env:Path = "$npmPrefix;$env:Path"
|
||||||
|
}
|
||||||
|
# 也检查常见的 npm 全局路径
|
||||||
|
$appDataNpm = "$env:APPDATA\npm"
|
||||||
|
if ((Test-Path $appDataNpm) -and ($env:Path -notlike "*$appDataNpm*")) {
|
||||||
|
$env:Path = "$appDataNpm;$env:Path"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Test-Command $Tool.Command) {
|
if (Test-Command $Tool.Command) {
|
||||||
Write-Success "$($Tool.Name) 安装成功!"
|
Write-Success "$($Tool.Name) 安装成功!"
|
||||||
return $true
|
return $true
|
||||||
|
|||||||
Reference in New Issue
Block a user