#!/usr/bin/env sh # Runs npm with the given arguments (e.g. `scripts/npm.sh test`), from the # repo root, so commands stay within this directory. # # Uses the npm already on PATH. If there is none (e.g. a non-interactive # shell that never loaded nvm), falls back to the newest nvm-installed node # and says so on stderr - it never installs or downloads anything. set -eu cd "$(dirname "$0")/.." if ! command -v npm >/dev/null 2>&1; then nvm_versions="${NVM_DIR:-$HOME/.nvm}/versions/node" newest=$(ls -1 "$nvm_versions" 2>/dev/null | sort -V | tail -n 1 || true) if [ -z "$newest" ]; then echo "scripts/npm.sh: npm is not on PATH and no nvm node was found in $nvm_versions" >&2 exit 127 fi echo "scripts/npm.sh: npm not on PATH; using nvm node $newest" >&2 PATH="$nvm_versions/$newest/bin:$PATH" export PATH fi exec npm "$@"