Skip to content

Commit 31457fe

Browse files
committed
[Refactor] nvm install: make -j and -s order-independent.
1 parent 1a6f85d commit 31457fe

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

nvm.sh

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,10 +1554,8 @@ nvm() {
15541554
;;
15551555

15561556
"install" | "i" )
1557-
local nobinary
15581557
local version_not_provided
15591558
version_not_provided=0
1560-
local provided_version
15611559
local NVM_OS
15621560
NVM_OS="$(nvm_get_os)"
15631561

@@ -1577,27 +1575,35 @@ nvm() {
15771575

15781576
shift
15791577

1578+
local nobinary
15801579
nobinary=0
1581-
if [ "_$1" = "_-s" ]; then
1582-
nobinary=1
1583-
shift
1584-
if [ "_$1" = "_-j" ]; then
1585-
shift
1586-
local NVM_CPU_THREAD_VALID
1587-
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)
1588-
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then
1589-
NVM_MAKE_JOBS=$1
1590-
echo "Set number of jobs to $MAKE_JOBS for 'make' utility"
1591-
else
1592-
unset NVM_MAKE_JOBS
1593-
echo >&2 "$1 is invalid for CPU threads, should be a natural number"
1594-
fi
1595-
shift
1596-
else
1597-
unset NVM_MAKE_JOBS
1598-
fi
1599-
fi
1580+
while [ $# -ne 0 ]
1581+
do
1582+
case "$1" in
1583+
-s)
1584+
shift # consume "-s"
1585+
nobinary=1
1586+
;;
1587+
-j)
1588+
shift # consume "-j"
1589+
local NVM_CPU_THREAD_VALID
1590+
NVM_CPU_THREAD_VALID=$(nvm_is_natural_num $1)
1591+
if [ "$NVM_CPU_THREAD_VALID" = "true" ]; then
1592+
NVM_MAKE_JOBS=$1
1593+
echo "number of \`make\` jobs: $NVM_MAKE_JOBS"
1594+
else
1595+
unset NVM_MAKE_JOBS
1596+
echo >&2 "$1 is invalid for number of \`make\` jobs, must be a natural number"
1597+
fi
1598+
shift # consume job count
1599+
;;
1600+
*)
1601+
break # stop parsing args
1602+
;;
1603+
esac
1604+
done
16001605

1606+
local provided_version
16011607
provided_version="$1"
16021608

16031609
if [ -z "$provided_version" ]; then

test/installation/node/install from source with thread parameter

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NVM_TEST_VERSION=v0.10.41
1111
# Remove the stuff we're clobbering.
1212
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
1313

14-
# Install from source with 1 CPU thread parameter
14+
# Install from source with 1 make job
1515
nvm install -s -j 1 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
1616

1717
# Check
@@ -25,8 +25,8 @@ nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_T
2525
# Remove the stuff we're clobbering.
2626
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
2727

28-
# Install from source with 2 CPU threads parameter
29-
nvm install -s -j 2 $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
28+
# Install from source with 2 make jobs (and swapped arg order)
29+
nvm install -j 2 -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
3030

3131
# Check
3232
[ -d ../../../$NVM_TEST_VERSION ]

0 commit comments

Comments
 (0)