11cb0ef41Sopenharmony_ci#!/usr/bin/env bash 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci# This is used by the Node.js installer, which expects the cygwin/mingw 41cb0ef41Sopenharmony_ci# shell script to already be present in the npm dependency folder. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cibasedir=`dirname "$0"` 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cicase `uname` in 111cb0ef41Sopenharmony_ci *CYGWIN*) basedir=`cygpath -w "$basedir"`;; 121cb0ef41Sopenharmony_ciesac 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciif [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then 151cb0ef41Sopenharmony_ci IS_WSL="true" 161cb0ef41Sopenharmony_cifi 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cifunction no_node_dir { 191cb0ef41Sopenharmony_ci # if this didn't work, then everything else below will fail 201cb0ef41Sopenharmony_ci echo "Could not determine Node.js install directory" >&2 211cb0ef41Sopenharmony_ci exit 1 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciNODE_EXE="$basedir/node.exe" 251cb0ef41Sopenharmony_ciif ! [ -x "$NODE_EXE" ]; then 261cb0ef41Sopenharmony_ci NODE_EXE="$basedir/node" 271cb0ef41Sopenharmony_cifi 281cb0ef41Sopenharmony_ciif ! [ -x "$NODE_EXE" ]; then 291cb0ef41Sopenharmony_ci NODE_EXE=node 301cb0ef41Sopenharmony_cifi 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci# this path is passed to node.exe, so it needs to match whatever 331cb0ef41Sopenharmony_ci# kind of paths Node.js thinks it's using, typically win32 paths. 341cb0ef41Sopenharmony_ciCLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)" 351cb0ef41Sopenharmony_ciif [ $? -ne 0 ]; then 361cb0ef41Sopenharmony_ci # this fails under WSL 1 so add an additional message. we also suppress stderr above 371cb0ef41Sopenharmony_ci # because the actual error raised is not helpful. in WSL 1 node.exe cannot handle 381cb0ef41Sopenharmony_ci # output redirection properly. See https://github.com/microsoft/WSL/issues/2370 391cb0ef41Sopenharmony_ci if [ "$IS_WSL" == "true" ]; then 401cb0ef41Sopenharmony_ci echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2 411cb0ef41Sopenharmony_ci fi 421cb0ef41Sopenharmony_ci no_node_dir 431cb0ef41Sopenharmony_cifi 441cb0ef41Sopenharmony_ciNPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js" 451cb0ef41Sopenharmony_ciNPX_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npx-cli.js" 461cb0ef41Sopenharmony_ciNPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g` 471cb0ef41Sopenharmony_ciif [ $? -ne 0 ]; then 481cb0ef41Sopenharmony_ci no_node_dir 491cb0ef41Sopenharmony_cifi 501cb0ef41Sopenharmony_ciNPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js" 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci# a path that will fail -f test on any posix bash 531cb0ef41Sopenharmony_ciNPX_WSL_PATH="/.." 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci# WSL can run Windows binaries, so we have to give it the win32 path 561cb0ef41Sopenharmony_ci# however, WSL bash tests against posix paths, so we need to construct that 571cb0ef41Sopenharmony_ci# to know if npm is installed globally. 581cb0ef41Sopenharmony_ciif [ "$IS_WSL" == "true" ]; then 591cb0ef41Sopenharmony_ci NPX_WSL_PATH=`wslpath "$NPM_PREFIX_NPX_CLI_JS"` 601cb0ef41Sopenharmony_cifi 611cb0ef41Sopenharmony_ciif [ -f "$NPM_PREFIX_NPX_CLI_JS" ] || [ -f "$NPX_WSL_PATH" ]; then 621cb0ef41Sopenharmony_ci NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS" 631cb0ef41Sopenharmony_cifi 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci"$NODE_EXE" "$NPX_CLI_JS" "$@" 66