Skip to content

Instantly share code, notes, and snippets.

@nimone
Last active August 20, 2026 15:32
Show Gist options
  • Select an option

  • Save nimone/230897ff2e038504740c4561e854bcf1 to your computer and use it in GitHub Desktop.

Select an option

Save nimone/230897ff2e038504740c4561e854bcf1 to your computer and use it in GitHub Desktop.
Migrate all projects in a directory to Bun global virtual store (install once, link everywhere)
#!/usr/bin/env bash
# Enable Bun global virtual store for all projects in a directory.
# Usage: bun-globalstore [dir] (defaults to current directory)
set -euo pipefail
ROOT="${1:-.}"
ROOT="$(realpath "$ROOT")"
BUNFIG_BLOCK='[install]
linker = "isolated"
globalStore = true'
echo "Scanning: $ROOT"
echo ""
found=0
skipped=0
for pkg in "$ROOT"/*/package.json; do
[ -f "$pkg" ] || continue
dir="$(dirname "$pkg")"
name="$(basename "$dir")"
bunfig="$dir/bunfig.toml"
# Skip if already has globalStore = true
if grep -q "globalStore = true" "$bunfig" 2>/dev/null; then
echo " skip $name (already configured)"
((skipped++)) || true
continue
fi
# Append or create bunfig.toml
if [ -f "$bunfig" ]; then
# Merge: add missing keys under existing [install] section, avoid duplicates
grep -q "linker" "$bunfig" || echo 'linker = "isolated"' >> "$bunfig"
grep -q "globalStore" "$bunfig" || echo 'globalStore = true' >> "$bunfig"
echo " patch $name (updated existing bunfig.toml)"
else
printf '%s\n' "$BUNFIG_BLOCK" > "$bunfig"
echo " write $name (created bunfig.toml)"
fi
echo " install $name..."
(cd "$dir" && rm -rf node_modules && bun install 2>&1 | tail -3)
echo ""
((found++)) || true
done
echo "Done. Configured: $found Skipped: $skipped"
echo "Shared store: ~/.bun/install/cache/links"
du -sh ~/.bun/install/cache/links 2>/dev/null || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment