npm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
  3. basedir=`dirname "$0"`
  4. case `uname` in
  5. *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
  6. esac
  7. NODE_EXE="$basedir/node.exe"
  8. if ! [ -x "$NODE_EXE" ]; then
  9. NODE_EXE="$basedir/node"
  10. fi
  11. if ! [ -x "$NODE_EXE" ]; then
  12. NODE_EXE=node
  13. fi
  14. # this path is passed to node.exe, so it needs to match whatever
  15. # kind of paths Node.js thinks it's using, typically win32 paths.
  16. CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
  17. NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
  18. NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
  19. if [ $? -ne 0 ]; then
  20. # if this didn't work, then everything else below will fail
  21. echo "Could not determine Node.js install directory" >&2
  22. exit 1
  23. fi
  24. NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
  25. # a path that will fail -f test on any posix bash
  26. NPM_WSL_PATH="/.."
  27. # WSL can run Windows binaries, so we have to give it the win32 path
  28. # however, WSL bash tests against posix paths, so we need to construct that
  29. # to know if npm is installed globally.
  30. if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
  31. NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
  32. fi
  33. if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
  34. NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
  35. fi
  36. "$NODE_EXE" "$NPM_CLI_JS" "$@"