litellm/scripts/with_dashboard_node.sh
mateo-berri c418ea59ae fix(bootstrap): switch to the dashboard node floor via nvm or fnm
The dashboard pins engines node >=24.14.1 with engine-strict, so make
bootstrap dies with EBADENGINE on any shell whose default node is older.
Wrap the npm install in scripts/with_dashboard_node.sh: it execs the
command as-is when node already meets the floor, otherwise activates the
.nvmrc version via nvm or fnm, and fails fast with install instructions
when neither manager exists
2026-08-04 21:02:26 -07:00

52 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
set -eu
[ $# -gt 0 ] || { echo "usage: $0 <command> [args...]" >&2; exit 2; }
repo_root=$(cd "$(dirname "$0")/.." && pwd)
dashboard="$repo_root/ui/litellm-dashboard"
floor=$(sed -n 's/.*"node": *">=\([0-9][0-9.]*\)".*/\1/p' "$dashboard/package.json")
pinned=$(tr -d '[:space:]' < "$dashboard/.nvmrc")
floor="${floor:-$pinned}"
meets_floor() {
awk -v have="$1" -v need="$2" 'BEGIN {
split(have, h, "."); split(need, n, ".")
for (i = 1; i <= 3; i++) {
if (h[i] + 0 < n[i] + 0) exit 1
if (h[i] + 0 > n[i] + 0) exit 0
}
}'
}
current=$(node --version 2>/dev/null | tr -d 'v' || true)
if [ -n "$current" ] && meets_floor "$current" "$floor"; then
exec "$@"
fi
nvm_script="${NVM_DIR:-$HOME/.nvm}/nvm.sh"
if [ -r "$nvm_script" ]; then
echo "with_dashboard_node: node ${current:-missing} is below the dashboard floor $floor; switching to $pinned via nvm" >&2
set +eu
. "$nvm_script" --no-use
nvm install "$pinned" >&2
nvm use "$pinned" >&2
set -eu
exec "$@"
fi
if command -v fnm > /dev/null 2>&1; then
echo "with_dashboard_node: node ${current:-missing} is below the dashboard floor $floor; switching to $pinned via fnm" >&2
fnm install "$pinned" >&2
eval "$(fnm env)"
fnm use "$pinned" >&2
exec "$@"
fi
cat >&2 <<EOF
with_dashboard_node: node ${current:-missing} does not meet ui/litellm-dashboard's engines floor (>= $floor) and neither nvm nor fnm is available to switch automatically.
Fix it with one of:
- install nvm (https://github.com/nvm-sh/nvm) and re-run; it will pick up node $pinned for you
- or install/upgrade node yourself to >= $floor (e.g. brew install node), then re-run
EOF
exit 1