[Refactor] `nvm install`: make `-j` and `-s` order-independent.
parent
1a6f85da46
commit
31457fec3f
32
nvm.sh
32
nvm.sh
|
@ -1554,10 +1554,8 @@ nvm() {
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"install" | "i" )
|
"install" | "i" )
|
||||||
local nobinary
|
|
||||||
local version_not_provided
|
local version_not_provided
|
||||||
version_not_provided=0
|
version_not_provided=0
|
||||||
local provided_version
|
|
||||||
local NVM_OS
|
local NVM_OS
|
||||||
NVM_OS="$(nvm_get_os)"
|
NVM_OS="$(nvm_get_os)"
|
||||||
|
|
||||||
|
@ -1577,27 +1575,35 @@ nvm() {
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
local nobinary
|
||||||
nobinary=0
|
nobinary=0
|
||||||
if [ "_$1" = "_-s" ]; then
|
while [ $# -ne 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-s)
|
||||||
|
shift # consume "-s"
|
||||||
nobinary=1
|
nobinary=1
|
||||||
shift
|
;;
|
||||||
if [ "_$1" = "_-j" ]; then
|
-j)
|
||||||
shift
|
shift # consume "-j"
|
||||||
local NVM_CPU_THREAD_VALID
|
local NVM_CPU_THREAD_VALID
|
||||||
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)
|
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)
|
||||||
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then
|
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then
|
||||||
NVM_MAKE_JOBS=$1
|
NVM_MAKE_JOBS=$1
|
||||||
echo "Set number of jobs to $MAKE_JOBS for 'make' utility"
|
echo "number of \`make\` jobs: $NVM_MAKE_JOBS"
|
||||||
else
|
else
|
||||||
unset NVM_MAKE_JOBS
|
unset NVM_MAKE_JOBS
|
||||||
echo >&2 "$1 is invalid for CPU threads, should be a natural number"
|
echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"
|
||||||
fi
|
|
||||||
shift
|
|
||||||
else
|
|
||||||
unset NVM_MAKE_JOBS
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
shift # consume job count
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break # stop parsing args
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local provided_version
|
||||||
provided_version="$1"
|
provided_version="$1"
|
||||||
|
|
||||||
if [ -z "$provided_version" ]; then
|
if [ -z "$provided_version" ]; then
|
||||||
|
|
|
@ -11,7 +11,7 @@ NVM_TEST_VERSION=v0.10.41
|
||||||
# Remove the stuff we're clobbering.
|
# Remove the stuff we're clobbering.
|
||||||
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
||||||
|
|
||||||
# Install from source with 1 CPU thread parameter
|
# Install from source with 1 make job
|
||||||
nvm install -s -j 1 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
nvm install -s -j 1 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
|
@ -25,8 +25,8 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_T
|
||||||
# Remove the stuff we're clobbering.
|
# Remove the stuff we're clobbering.
|
||||||
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
|
||||||
|
|
||||||
# Install from source with 2 CPU threads parameter
|
# Install from source with 2 make jobs (and swapped arg order)
|
||||||
nvm install -s -j 2 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
nvm install -j 2 -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
|
||||||
|
|
||||||
# Check
|
# Check
|
||||||
[ -d ../../../$NVM_TEST_VERSION ]
|
[ -d ../../../$NVM_TEST_VERSION ]
|
||||||
|
|
Loading…
Reference in New Issue