1 | #!/usr/bin/env bash
|
2 |
|
3 | # This is used by the Node.js installer, which expects the cygwin/mingw
|
4 | # shell script to already be present in the npm dependency folder.
|
5 |
|
6 | (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
|
7 |
|
8 | basedir=`dirname "$0"`
|
9 |
|
10 | case `uname` in
|
11 | *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
12 | esac
|
13 |
|
14 | if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
|
15 | IS_WSL="true"
|
16 | fi
|
17 |
|
18 | function no_node_dir {
|
19 | # if this didn't work, then everything else below will fail
|
20 | echo "Could not determine Node.js install directory" >&2
|
21 | exit 1
|
22 | }
|
23 |
|
24 | NODE_EXE="$basedir/node.exe"
|
25 | if ! [ -x "$NODE_EXE" ]; then
|
26 | NODE_EXE="$basedir/node"
|
27 | fi
|
28 | if ! [ -x "$NODE_EXE" ]; then
|
29 | NODE_EXE=node
|
30 | fi
|
31 |
|
32 | # this path is passed to node.exe, so it needs to match whatever
|
33 | # kind of paths Node.js thinks it's using, typically win32 paths.
|
34 | CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
|
35 | if [ $? -ne 0 ]; then
|
36 | # this fails under WSL 1 so add an additional message. we also suppress stderr above
|
37 | # because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
|
38 | # output redirection properly. See https://github.com/microsoft/WSL/issues/2370
|
39 | if [ "$IS_WSL" == "true" ]; then
|
40 | echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
|
41 | fi
|
42 | no_node_dir
|
43 | fi
|
44 | NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
|
45 | NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
|
46 | NPM_PREFIX=`"$NODE_EXE" "$NPM_PREFIX_JS"`
|
47 | if [ $? -ne 0 ]; then
|
48 | no_node_dir
|
49 | fi
|
50 | NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
|
51 |
|
52 | # a path that will fail -f test on any posix bash
|
53 | NPM_WSL_PATH="/.."
|
54 |
|
55 | # WSL can run Windows binaries, so we have to give it the win32 path
|
56 | # however, WSL bash tests against posix paths, so we need to construct that
|
57 | # to know if npm is installed globally.
|
58 | if [ "$IS_WSL" == "true" ]; then
|
59 | NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
|
60 | fi
|
61 | if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
|
62 | NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
|
63 | fi
|
64 |
|
65 | "$NODE_EXE" "$NPM_CLI_JS" "$@"
|