I am currently working on a node project that requires eslint as a dependency. Hence, a file named eslint and eslint.cmd was created automatically in the root_directory/node_modules/.bin folder.
The content of the eslint file is -
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../eslint/bin/eslint.js" "$#"
ret=$?
else
node "$basedir/../eslint/bin/eslint.js" "$#"
ret=$?
fi
exit $ret
Can someone give a line-to-line explaination to what exactly this code is doing?
I read the answer on What is the purpose of .bin folder in node_modules?
Still couldn't figure out how this code does all that is stated in the answers.
node version - 12.10.0
npm version - 6.10.3
Related
How I am here.
Running Command:
opt/develop/spark-3.3.1$ sudo ./dev/make-distribution.sh -pHADOOP-3 Dhadoop.version=3.2.4 -Pyarn --name custom-spark --pip --r --tgz -Psparkr -Phive -Phive-thriftserver -Pmesos -Pyarn -Pkubernetes
The script (make-distribution.sh), apparently, is not reading the value of the variable i.e., $JAVA_HOME.
Running Command:
/opt/develop/spark-3.3.1$ echo $JAVA_HOME
Shows expected result: /usr/lib/jvm/jdk-19.0.1
Attempted:
Well, added to the file /opt/develop/spark-3.3.1/sbin/spark-config.sh
export JAVA_HOME="/usr/lib/jvm/jdk-19.0.1" export PATH=$PATH:$JAVA_HOME/bin
did not seem to change the result of Running command.
Logging-out and logging back in is also of no avail.
Note-1:
My JAVA_HOME is also set in /etc/profile.d/my-envvars file as:
export JAVA_HOME="/usr/lib/jvm/jdk-19.0.1" export PATH=$PATH:$JAVA_HOME/bin
Note-2: commands java --version and javac --version appears to be working okay.
The file: /opt/develop/dev/make-distribution.sh
Reads:
`
set -o pipefail
set -e
set -x
# Figure out where the Spark framework is installed
SPARK_HOME="$(cd "`dirname "$0"`/.."; pwd)"
DISTDIR="$SPARK_HOME/dist"
MAKE_TGZ=false
MAKE_PIP=false
MAKE_R=false
NAME=none
MVN="$SPARK_HOME/build/mvn"
function exit_with_usage {
set +x
echo "make-distribution.sh - tool for making binary distributions of Spark"
echo ""
echo "usage:"
cl_options="[--name] [--tgz] [--pip] [--r] [--mvn <mvn-command>]"
echo "make-distribution.sh $cl_options <maven build options>"
echo "See Spark's \"Building Spark\" doc for correct Maven options."
echo ""
exit 1
}
# Parse arguments
while (( "$#" )); do
case $1 in
--tgz)
MAKE_TGZ=true
;;
--pip)
MAKE_PIP=true
;;
--r)
MAKE_R=true
;;
--mvn)
MVN="$2"
shift
;;
--name)
NAME="$2"
shift
;;
--help)
exit_with_usage
;;
--*)
echo "Error: $1 is not supported"
exit_with_usage
;;
-*)
break
;;
*)
echo "Error: $1 is not supported"
exit_with_usage
;;
esac
shift
done
if [ -z "$JAVA_HOME" ]; then # THIS SHOULD EVALUATE FALSE.
# Fall back on JAVA_HOME from rpm, if found
if [ $(command -v rpm) ]; then
RPM_JAVA_HOME="$(rpm -E %java_home 2>/dev/null)"
if [ "$RPM_JAVA_HOME" != "%java_home" ]; then
JAVA_HOME="$RPM_JAVA_HOME"
echo "No JAVA_HOME set, proceeding with '$JAVA_HOME' learned from rpm"
fi
fi
if [ -z "$JAVA_HOME" ]; then
if [ `command -v java` ]; then
# If java is in /usr/bin/java, we want /usr
JAVA_HOME="$(dirname $(dirname $(which java)))"
fi
fi
fi
if [ -z "$JAVA_HOME" ]; then # This SHOULD EVALUATE FALSE. APPARENTLY, IT DOES NOT
echo "Error: JAVA_HOME is not set, cannot proceed."
# I Should not be here, but I am!
exit -1
fi
`
Your problem lies within the fact that you're executing your script with sudo, which does not preserve environment variables by default.
As a small demonstration, consider the following:
someone#somewhere:~/my-path$ export SOMEVAR="testmyvar"
someone#somewhere:~/my-path$ echo $SOMEVAR
testmyvar
someone#somewhere:~/my-path$ sudo bash -c 'echo $SOMEVAR'
As you can see, when executing a command with sudo, you don't preserve all of your environment variables.
There is luckily quite an easy fix for that: use sudo -E (that does preserve environment variables, you can find that option in the man page of sudo)
So in our little example a bit higher:
someone#somewhere:~/my-path$ sudo -E bash -c 'echo $SOMEVAR'
testmyvar
You see that the -E option does what you want it to do!
Hope this fixes your problem :)
I'm trying to debug an android app which uses a gulpfile.js.
The gulpfile.js, in the app repository, is pointing to 'node_modules/.bin/cap'
And, everytime I run gulp, it ends with an error relating to "android":
[01:30:42] 'android' errored after 206 ms
[01:30:42] Error: Command failed with exit code 1: node node_modules/.bin/cap sync
C:\Users\Tombouctou\floccus\node_modules\.bin\cap:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
I tried editing the 'cap' file, with legacy code (backticks). It solves this parenthesis issue, but after I have another issue:
Unexpected token "case".
If I fix that I have again another issue anywhere else on the same file, and so on....
The developer of the app I'm trying to debug, says that it's because I am on Windows but he don't know how to rewrite this line on the gulpfile.js :
const {stdout} = await execa('node', ['node_modules/.bin/cap', 'sync'])
I don't know either.
Do you reckon I should point this line to somewhere else ?
Or do you think I should edit the .bin/cap file and change the code inside, which is :
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../#capacitor/cli/bin/capacitor" "$#"
ret=$?
else
node "$basedir/../#capacitor/cli/bin/capacitor" "$#"
ret=$?
fi
exit $ret
I'm totally lost.
Thanks
I am getting the below error while building the angular project,
CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
I have seen somewhere that configuring max-old-space-size in npm will solve the issue. But I don't know how to set it. I am using Windows OS & there are two npm files inside the nodejs installation folder (C:\Program Files\nodejs), npm & npm.cmd. First line inside the npm.cmd file is "Created by npm, please don't edit manually". So I am not supposed to edit this file & I have to configure max-old-space-size inside npm file. But I don't where in this file I have to configure it. My npm file looks like below,
#!/bin/sh
(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
basedir=`dirname "$0"`
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
NODE_EXE="$basedir/node.exe"
if ! [ -x "$NODE_EXE" ]; then
NODE_EXE=node
fi
NPM_CLI_JS="$basedir/node_modules/npm/bin/npm-cli.js"
case `uname` in
*MINGW*)
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
fi
;;
*CYGWIN*)
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
if [ -f "$NPM_PREFIX_NPM_CLI_JS" ]; then
NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
fi
;;
esac
"$NODE_EXE" "$NPM_CLI_JS" "$#"
Possibly you could try this,
> npm run start --node-flags --max-old-space-size=512 --no-warnings
> node --max-old-space-size=250 `which npm` some_npm_command
I faced similar issue but i had to increase docker memory size.
As of yesterday, whenever I npm install in IDEA, all these extra script files (the red files) get added to my project directory.
Here is what's in uuid:
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/node_modules/uuid/bin/uuid" "$#"
ret=$?
else
node "$basedir/node_modules/uuid/bin/uuid" "$#"
ret=$?
fi
exit $ret
and in uuid.cmd:
#IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\node_modules\uuid\bin\uuid" %*
) ELSE (
#SETLOCAL
#SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\node_modules\uuid\bin\uuid" %*
)
It's annoying and it really clutters up my project. This just started happening and I do not remember changing any settings in IDEA. Why is this happening and/or how can I make it stop?
Update: I think this may have something to do with node/npm global settings but I'm not sure.
I am beginner of cygwin terminal. I am trying to run *.sh file on windows 8 using command ./file_name.sh, but it gives error given below....
Using prebuilt externals
ERROR: Cannot find 'make' program. Please install Cygwin make package
or define the GNUMAKE variable to point to it.
I have installed cygwin in F drive, I google this error and set the variable path in computer properties > advance system properties > variable environment > path >edit and variable path is ;F:\cygwin\bin
But does not work. How can i solve this problem??
Here is my script
`# set params`
NDK_ROOT=/cygdrive/f/Android/android-ndk-r9b
COCOS2DX_ROOT=/cygdrive/f/Android/cocos2d-2.0-rc2-x-2.0.1
GAME_ROOT=$COCOS2DX_ROOT/molatx
GAME_ANDROID_ROOT=$GAME_ROOT/proj.android
RESOURCE_ROOT=$GAME_ROOT/Resources
buildexternalsfromsource=
usage(){
cat << EOF
usage: $0 [options]
Build C/C++ native code using Android NDK
OPTIONS:
-s Build externals from source
-h this help
EOF
}
while getopts "s" OPTION; do
case "$OPTION" in
s)
buildexternalsfromsource=1
;;
h)
usage
exit 0
;;
esac
done
`# make sure assets is exist`
if [ -d $GAME_ANDROID_ROOT/assets ]; then
rm -rf $GAME_ANDROID_ROOT/assets
fi
mkdir $GAME_ANDROID_ROOT/assets
`# copy resources`
for file in $RESOURCE_ROOT/*
do
if [ -d "$file" ]; then
cp -rf "$file" $GAME_ANDROID_ROOT/assets
fi
if [ -f "$file" ]; then
cp "$file" $GAME_ANDROID_ROOT/assets
fi
done
`# copy icons (if they exist)`
file=$GAME_ANDROID_ROOT/assets/Icon-72.png
if [ -f "$file" ]; then
cp $file $GAME_ANDROID_ROOT/res/drawable-hdpi/icon.png
fi
file=$GAME_ANDROID_ROOT/assets/Icon-48.png
if [ -f "$file" ]; then
cp $file $GAME_ANDROID_ROOT/res/drawable-mdpi/icon.png
fi
file=$GAME_ANDROID_ROOT/assets/Icon-32.png
if [ -f "$file" ]; then
cp $file $GAME_ANDROID_ROOT/res/drawable-ldpi/icon.png
fi
if [[ $buildexternalsfromsource ]]; then
echo "Building external dependencies from source"
$NDK_ROOT/ndk-build -C $GAME_ANDROID_ROOT \
NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source
else
echo "Using prebuilt externals"
$NDK_ROOT/ndk-build -C $GAME_ANDROID_ROOT \
NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt
fi
You have to install make package using cygwin "setup.exe" wizard.
Check what programming language is your script compiling because the compiler of that language will be also dependencies of your script.
Probably you will need to install some libraries too.
Your Windows system path is different to your Cygwin path. If you install the required packages using cygwin setup they will already be available in your $PATH.
Run cygwin setup an install: make , automake , gcc , gcc-c++