From bb74d0f72079a4df5b7642820115946b39da29f9 Mon Sep 17 00:00:00 2001 From: sususu Date: Fri, 20 Mar 2026 23:47:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20npm=20install=20-g=20=E5=90=8E=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E6=90=9C=E7=B4=A2=E5=85=A8=E5=B1=80=20bin=20=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=81=BF=E5=85=8D=E5=91=BD=E4=BB=A4=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit npm install -g 成功后命令可能不在 PATH 中(尤其使用 fnm 管理的 Node.js)。 安装后通过 npm config get prefix 和 %APPDATA%\npm 查找全局 bin 目录 并自动加入当前会话 PATH。 --- ClaudeCode/setup-claude-code.ps1 | 13 +++++++++++++ GeminiCLI/setup-gemini.ps1 | 13 +++++++++++++ codex/setup-codex.ps1 | 13 +++++++++++++ setup-claude-code.ps1 | 13 +++++++++++++ setup.ps1 | 14 ++++++++++++++ 5 files changed, 66 insertions(+) diff --git a/ClaudeCode/setup-claude-code.ps1 b/ClaudeCode/setup-claude-code.ps1 index 3c35c97..f115c98 100644 --- a/ClaudeCode/setup-claude-code.ps1 +++ b/ClaudeCode/setup-claude-code.ps1 @@ -241,6 +241,19 @@ function Install-Tool { 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) { Write-Success "$ToolName 安装成功!" return $true diff --git a/GeminiCLI/setup-gemini.ps1 b/GeminiCLI/setup-gemini.ps1 index 4e2b6fe..9e85e22 100644 --- a/GeminiCLI/setup-gemini.ps1 +++ b/GeminiCLI/setup-gemini.ps1 @@ -239,6 +239,19 @@ function Install-Tool { 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) { Write-Success "$ToolName 安装成功!" return $true diff --git a/codex/setup-codex.ps1 b/codex/setup-codex.ps1 index fec769c..59baa1e 100644 --- a/codex/setup-codex.ps1 +++ b/codex/setup-codex.ps1 @@ -241,6 +241,19 @@ function Install-Tool { 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) { Write-Success "$ToolName 安装成功!" return $true diff --git a/setup-claude-code.ps1 b/setup-claude-code.ps1 index 0fffdff..b5a54e2 100644 --- a/setup-claude-code.ps1 +++ b/setup-claude-code.ps1 @@ -240,6 +240,19 @@ function Install-Tool { 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) { Write-Success "$ToolName 安装成功!" return $true diff --git a/setup.ps1 b/setup.ps1 index 813002e..31f3ef2 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -264,6 +264,20 @@ function Install-Tool { 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) { Write-Success "$($Tool.Name) 安装成功!" return $true