Skip to content

Commit fcf9c56

Browse files
authored
Merge pull request #3 from EricLLLLLL/test
v1.1.32
2 parents bb1c0aa + f516797 commit fcf9c56

22 files changed

Lines changed: 318 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Track fix_global_bin_20260126 Context
2+
3+
- [Specification](./spec.md)
4+
- [Implementation Plan](./plan.md)
5+
- [Metadata](./metadata.json)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"track_id": "fix_global_bin_20260126",
3+
"type": "bug",
4+
"status": "new",
5+
"created_at": "2026-01-26T10:00:00Z",
6+
"updated_at": "2026-01-26T10:00:00Z",
7+
"description": "修复 bun install -g 全局包在 macOS 和 Windows 上无法使用的问题"
8+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Implementation Plan: 修复 bun install -g 全局包无法使用的问题
2+
3+
修复在 macOS 和 Windows 平台上,使用 `bun install -g` 安装的全局包无法在命令行中使用的问题。
4+
5+
## Phase 1: 问题复现与测试环境搭建
6+
- [x] Task: 创建集成测试脚本复现 `command not found` 错误
7+
- [x]`test/` 目录下创建 `global_install_path.test.ts`
8+
- [x] 编写测试:模拟 `bvm use` 之后尝试运行 `bun install -g` 安装的虚构命令
9+
- [x] 验证在当前环境下 `command -v <cmd>` 失败
10+
- [x] Task: 检查现有的 PATH 注入逻辑
11+
- [x] 审计 `src/commands/setup.ts``src/rc.ts`
12+
- [x] 审计 `install.sh``install.ps1` 中的环境配置部分
13+
- [x] Task: Conductor - User Manual Verification 'Phase 1' (Protocol in workflow.md)
14+
15+
## Phase 2: Unix/macOS 路径管理修复
16+
- [x] Task: 增强 `install.sh` 以包含 Bun 全局 bin 目录
17+
- [x] 修改 `install.sh`,确保 `~/.zshrc``~/.bashrc` 中包含正确的 `BUN_INSTALL/bin` 路径
18+
- [x] Task: 修改 BVM 核心逻辑,动态管理全局 PATH (Unix)
19+
- [x]`bvm use` 执行后,如果检测到环境需要,提示用户重新加载或自动导出路径
20+
- [x] Task: 运行集成测试并验证修复 (Unix)
21+
- [x] 执行 `npx bun test test/global_install_path.test.ts`
22+
- [x] Task: Conductor - User Manual Verification 'Phase 2' (Protocol in workflow.md)
23+
24+
## Phase 3: Windows 路径管理修复
25+
- [x] Task: 增强 `install.ps1` 环境配置
26+
- [x] 修改 `install.ps1`,确保用户 PATH 环境变量中永久包含当前版本 Bun 的 bin 目录
27+
- [x] Task: 修复 BVM Windows Shim 的路径代理 (Windows)
28+
- [x] 确保 Windows 版的 `bvm.cmd` 或 shim 能够处理全局包的查找逻辑
29+
- [x] Task: Conductor - User Manual Verification 'Phase 3' (Protocol in workflow.md)
30+
31+
## Phase 4: 文档更新与回归测试
32+
- [x] Task: 更新 README 和故障排除文档
33+
- [x] 添加关于 `bun install -g` 包管理的说明
34+
- [x] Task: 执行 E2E 测试
35+
- [x] 运行 `npx bun run test` 确保无回归错误
36+
- [x] Task: Conductor - User Manual Verification 'Phase 4' (Protocol in workflow.md)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Specification: 修复 bun install -g 全局包无法使用的问题
2+
3+
## 1. 概述
4+
修复在 macOS 和 Windows 平台上,使用 `bun install -g` (如 `@anthropic-ai/claude-code`) 安装全局包后,无法在终端直接运行该命令(提示 `command not found`)的缺陷。
5+
6+
## 2. 问题分析
7+
当前 BVM 允许每个 Bun 版本拥有独立的全局包安装目录。然而,当用户通过 BVM 激活某个 Bun 版本时,该版本对应的全局 bin 目录可能未被正确添加到系统的 PATH 环境变量中,导致用户无法直接调用安装的工具。
8+
9+
## 3. 目标
10+
- 确保用户使用 `bvm use <version>` 切换版本后,该版本下已安装的全局包命令立即可用。
11+
- 确保用户在当前版本下新执行 `bun install -g <package>` 后,安装的命令立即可用。
12+
- 保持不同 Bun 版本间全局包的隔离性。
13+
14+
## 4. 解决方案 (待验证)
15+
1. **PATH 注入优化**: 确保 `bvm use` 操作会更新 Shell 的 PATH,指向 `<BUN_INSTALL>/bin`
16+
2. **动态 Shim**: BVM 的 Shim 机制可能需要扩展,以代理 `$BUN_INSTALL/bin` 下的所有可执行文件。
17+
18+
## 5. 验收标准
19+
### macOS / Unix
20+
- [ ] 安装 BVM 并安装一个 Bun 版本。
21+
- [ ] 执行 `bun install -g @anthropic-ai/claude-code`
22+
- [ ] 执行 `claude` 命令,应能正常启动。
23+
24+
### Windows
25+
- [ ] 安装 BVM 并安装一个 Bun 版本。
26+
- [ ] 执行 `bun install -g @anthropic-ai/claude-code`
27+
- [ ] 执行 `claude` 命令,应能正常启动。
28+
29+
## 6. 不在范围
30+
- 跨 Bun 版本的全局包自动迁移或共享。
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Track fix_windows_global_shim_resolution_20260126 Context
2+
3+
- [Specification](./spec.md)
4+
- [Implementation Plan](./plan.md)
5+
- [Metadata](./metadata.json)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"track_id": "fix_windows_global_shim_resolution_20260126",
3+
"type": "bug",
4+
"status": "new",
5+
"created_at": "2026-01-26T10:30:00Z",
6+
"updated_at": "2026-01-26T10:30:00Z",
7+
"description": "修复 Windows 下全局包 Shim 的相对路径解析错误"
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Implementation Plan: 修复 Windows 下全局包 Shim 的相对路径解析错误
2+
3+
## Phase 1: 调查与复现 (Investigation)
4+
- [x] Task: 分析 Bun 生成的 Shim 文件结构
5+
- [x] 在 Windows 环境(或模拟)下,检查 `bun install -g` 生成的 `.cmd``.ps1` 文件内容。
6+
- [x] 记录相对路径的层级深度,对比 BVM `current` 目录结构。
7+
- [x] Task: 创建最小复现脚本 (Reproduction Script)
8+
- [x] 编写一个 PowerShell 脚本,模拟 BVM 的目录结构(`versions/vX`, `current` junction)。
9+
- [x] 手动创建一个模拟 Bun Shim 的 `.cmd` 文件。
10+
- [x] 验证通过 Junction 调用时路径解析是否失效。
11+
- [x] Task: Conductor - User Manual Verification 'Phase 1' (Protocol in workflow.md)
12+
13+
## Phase 2: 方案原型验证 (Prototyping)
14+
- [x] Task: 验证 "Shim Patching" (绝对路径) 方案
15+
- [x] 编写脚本修改 Shim 文件,将 `..\` 替换为绝对路径。
16+
- [x] 验证修改后的 Shim 是否能通过 `current` 路径正常运行。
17+
- [x] Task: 验证 "Junction Bypass" (绕过) 方案
18+
- [x] 测试是否可以直接将 `PATH` 指向真实版本路径(而非 `current`),验证是否解决问题。
19+
- [x] Task: 选择最佳方案并撰写技术决策文档 (ADR)。
20+
- [x] Task: Conductor - User Manual Verification 'Phase 2' (Protocol in workflow.md)
21+
22+
## Phase 3: 实现修复 (Implementation)
23+
- [x] Task: 实现 Shim 修正工具 (Shim Fixer)
24+
- [x]`src/utils/windows-shim-fixer.ts` 中实现逻辑:扫描指定目录的 `.cmd` 文件,修复相对路径。
25+
- [x] Task: 集成到 BVM 核心流程
26+
- [x]`bvm install``bvm use` 成功后,自动触发 Shim Fixer(仅 Windows)。
27+
- [x] (可选) 添加 `bvm fix-shims` 命令供用户手动调用。
28+
- [x] Task: Conductor - User Manual Verification 'Phase 3' (Protocol in workflow.md)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Specification: 修复 Windows 下全局包 Shim 的相对路径解析错误
2+
3+
## 1. 概述
4+
在 Windows 平台上,用户通过 BVM 安装的 Bun 全局包(如 `claude`)在运行时可能抛出 `Module not found` 错误。初步分析显示,这是由于 Bun 生成的 Shim 脚本使用了相对路径(如 `..\..\..\node_modules\...`),而 BVM 的版本管理依赖于目录连接点(Junction,即 `.bvm\current`),导致相对路径解析时跳转到了错误的物理位置。
5+
6+
## 2. 问题分析 (Hypothesis)
7+
- **现象**: 运行 `claude` 报错,路径指向错误的位置(如 `C:\Users\Administrator\.bvm\current\..\..\..\node_modules...`)。
8+
- **原因**: Windows 的 Junction 在处理 `..` (父目录) 时,可能基于“链接所在的路径”而非“链接指向的目标真实路径”进行解析,或者反之,导致层级计算错误。
9+
- **影响**: 所有依赖 BVM `current` 机制并在 Windows 上使用 `bun install -g` 的用户。
10+
11+
## 3. 目标
12+
- **核心目标**: 确保在 Windows 上通过 BVM 安装和管理的全局包能够正常运行,不报路径错误。
13+
- **阶段性目标**:
14+
1. **复现**: 确立一个最小可复现案例 (Reproduction Case)。
15+
2. **根因确认**: 分析 Bun 生成的 `.cmd` / `.ps1` 文件内容,确认相对路径的具体计算逻辑。
16+
3. **方案验证**: 测试 "Shim Patching"(改为绝对路径)或 "Wrapper Proxy" 等修复方案的可行性。
17+
18+
## 4. 交付物
19+
- 一个包含复现步骤和根因分析的技术报告。
20+
- 修复方案的原型代码。
21+
- 如果可行,直接集成修复到 BVM 核心。
22+
23+
## 5. 验收标准
24+
- [ ] 在 Windows 测试环境中,安装 BVM 和 Bun。
25+
- [ ] 运行 `bun install -g @anthropic-ai/claude-code`
26+
- [ ] 运行 `claude` 命令,不再报错。
27+
- [ ] 确认修复方案不会破坏 Unix/macOS 的现有逻辑。
28+
29+
## 6. 不在范围
30+
- 修复 Bun 自身的 Shim 生成逻辑。
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Track release_v1_1_31_20260126 Context
2+
3+
- [Specification](./spec.md)
4+
- [Implementation Plan](./plan.md)
5+
- [Metadata](./metadata.json)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"track_id": "release_v1_1_31_20260126",
3+
"type": "chore",
4+
"status": "new",
5+
"created_at": "2026-01-26T11:00:00Z",
6+
"updated_at": "2026-01-26T11:00:00Z",
7+
"description": "Release BVM v1.1.31 (Patch Fixes)"
8+
}

0 commit comments

Comments
 (0)