← All writing
notes

Working with Pi in a Bun environment

  • Create a shim for Bun and place it in $HOME/.local/bin/bun-as-npm

Sidenote: make sure $HOME/.local/bin is in your path

#!/usr/bin/env sh
case "$1" in
install)
shift
# Translate "install -g <pkg>" → "add -g <pkg>"
if [ "$1" = "-g" ] && [ -n "$2" ]; then
shift
exec bun add -g "$@"
fi
exec bun install "$@"
;;
add) shift; exec bun add "$@" ;;
root)
if [ "$2" = "-g" ]; then
echo "${BUN_INSTALL:-$HOME/.bun}/install/global/node_modules"
exit 0
fi
exit 1
;;
view) shift; exec bun info "$@" ;;
uninstall|remove) shift; exec bun remove "$@" ;;
*) exec bun "$@" ;;
esac
  • Make the script executable
Terminal window
chmod +x "$HOME/.local/bin/bun-as-npm"
  • Edit pi’s settings.json file to configure the bun shim as the npm replacement
{
"npmCommand": ["bun-as-npm"]
}

Done! You can now use pi in an environment having bun and not npm