fix(codexlens): 添加 Yarn PnP 支持以改进环境检测

问题分析:
- Yarn PnP 不使用 node_modules 目录
- 原有逻辑仅检测 node_modules 会错误识别为开发环境
- 导致在 Yarn PnP 项目中尝试使用本地路径安装失败

修复内容:
- 在 isDevEnvironment() 中添加 Yarn PnP 检测
- 检查 process.versions.pnp 属性判断是否为 Yarn PnP 环境
- Yarn PnP 环境被视为生产环境,使用 PyPI 安装

改进影响:
- npm/pnpm: 使用 node_modules 检测(原有逻辑)
- Yarn PnP: 使用 pnp 版本检测(新增逻辑)
- 开发环境: 两项检测均不满足时识别为开发环境

Based on Gemini code review suggestion (ID: 1768794060352-gemini)
This commit is contained in:
catlog22
2026-01-19 11:43:12 +08:00
parent a8367bd4d7
commit 6716772e0a

View File

@@ -41,8 +41,13 @@ function isInsideNodeModules(pathToCheck: string): boolean {
/**
* Check if we're running in a development environment (not from node_modules)
* Also detects Yarn PnP (Plug'n'Play) which doesn't use node_modules.
*/
function isDevEnvironment(): boolean {
// Yarn PnP detection: if pnp version exists, it's a managed production environment
if ((process.versions as any).pnp) {
return false;
}
return !isInsideNodeModules(__dirname);
}