fix(npm-globals): Prune stale Bun globals - #1448
Conversation
Remove packages from Bun global state when they are no longer declared in dotfiles/package.json instead of only installing missing packages. Also clean dangling shims in ~/.bun/bin and cover the stale @beads/bd case with shell specs so the local repo binary remains the only bd on PATH. Co-authored-by: Codex <noreply@openai.com>
|
You do not have enough credits to review this pull request. Please purchase more credits to continue. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Disabled knowledge base sources:
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR adds logic to remove stale Bun global packages no longer present in the dotfiles package.json file, including cleanup of corresponding entries from the Bun global package registry and removal of dangling symlink shims, while reorganizing variable assignment order in the install script. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Mesa DescriptionTL;DRFixes the What changed?
Description generated by Mesa. Update settings |
There was a problem hiding this comment.
Code Review
This pull request introduces logic to prune stale global packages and dangling shims in the Bun environment. It adds a process to compare installed global packages against the dependencies declared in the configuration's package.json, removing any that are no longer required. Additionally, it implements a cleanup step for broken symbolic links in the Bun binary directory and includes comprehensive tests for these new features. A review comment suggests improving the robustness of the shim cleanup loop by using IFS= read -r to correctly handle filenames that may contain whitespace.
| # Remove stale shims left behind by prior Bun global installs | ||
| BUN_BIN="${HOME}/.bun/bin" | ||
| if [ -d "$BUN_BIN" ]; then | ||
| find "$BUN_BIN" -mindepth 1 -maxdepth 1 -type l 2>/dev/null | while read -r shim; do |
There was a problem hiding this comment.
To robustly parse the output of the find command and avoid issues with filenames that might contain leading or trailing whitespace, you should use IFS= read -r. This aligns with the general rule for robustly parsing command output and maintains consistency with the while loop used earlier in the script (line 57).
| find "$BUN_BIN" -mindepth 1 -maxdepth 1 -type l 2>/dev/null | while read -r shim; do | |
| find "$BUN_BIN" -mindepth 1 -maxdepth 1 -type l 2>/dev/null | while IFS= read -r shim; do |
References
- To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and
readwith a matchingIFS. This is safer than splitting by spaces withcut, especially when data fields might contain spaces.
Prune stale Bun globals when syncing npm globals.
The npm-global installer only added or updated packages listed in dotfiles/package.json, so packages removed from that manifest could stay behind in ~/.bun/install/global and keep stale shims like ~/.bun/bin/bd alive. That left Bun state inconsistent and could shadow the repo-local bd binary until manually deleted.
This change prunes Bun global dependencies that are no longer declared, falls back to removing stale metadata if Bun leaves it behind, and sweeps dangling shims from ~/.bun/bin. It also adds a shell regression spec covering the stale @beads/bd case.
Summary by cubic
Prunes stale Bun globals during npm-global sync to keep the PATH clean and prevent repo binaries from being shadowed. Removes undeclared packages and dangling shims, covering the
@beads/bdcase.@beads/bd.Written for commit 257dc0a. Summary will update on new commits.