[Fix] `install`: improved arg parsing around `--reinstall-packages-from`
Fixes #1762
parent
33fa27dabe
commit
6575b6b052
64
nvm.sh
64
nvm.sh
|
@ -2572,6 +2572,12 @@ nvm() {
|
||||||
local LTS
|
local LTS
|
||||||
local NVM_UPGRADE_NPM
|
local NVM_UPGRADE_NPM
|
||||||
NVM_UPGRADE_NPM=0
|
NVM_UPGRADE_NPM=0
|
||||||
|
|
||||||
|
local PROVIDED_REINSTALL_PACKAGES_FROM
|
||||||
|
local REINSTALL_PACKAGES_FROM
|
||||||
|
local SKIP_DEFAULT_PACKAGES
|
||||||
|
local DEFAULT_PACKAGES
|
||||||
|
|
||||||
while [ $# -ne 0 ]; do
|
while [ $# -ne 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
---*)
|
---*)
|
||||||
|
@ -2603,6 +2609,40 @@ nvm() {
|
||||||
NVM_UPGRADE_NPM=1
|
NVM_UPGRADE_NPM=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--reinstall-packages-from=*)
|
||||||
|
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
|
||||||
|
nvm_err '--reinstall-packages-from may not be provided more than once'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
|
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
|
||||||
|
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
|
||||||
|
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
|
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--copy-packages-from=*)
|
||||||
|
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
|
||||||
|
nvm_err '--reinstall-packages-from may not be provided more than once, or combined with `--copy-packages-from`'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
|
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
|
||||||
|
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
|
||||||
|
nvm_err 'If --copy-packages-from is provided, it must point to an installed version of node.'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
|
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--reinstall-packages-from | --copy-packages-from)
|
||||||
|
nvm_err "If ${1} is provided, it must point to an installed version of node using \`=\`."
|
||||||
|
return 6
|
||||||
|
;;
|
||||||
|
--skip-default-packages)
|
||||||
|
SKIP_DEFAULT_PACKAGES=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
break # stop parsing args
|
break # stop parsing args
|
||||||
;;
|
;;
|
||||||
|
@ -2667,14 +2707,14 @@ nvm() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ADDITIONAL_PARAMETERS=''
|
ADDITIONAL_PARAMETERS=''
|
||||||
local PROVIDED_REINSTALL_PACKAGES_FROM
|
|
||||||
local REINSTALL_PACKAGES_FROM
|
|
||||||
local SKIP_DEFAULT_PACKAGES
|
|
||||||
local DEFAULT_PACKAGES
|
|
||||||
|
|
||||||
while [ $# -ne 0 ]; do
|
while [ $# -ne 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--reinstall-packages-from=*)
|
--reinstall-packages-from=*)
|
||||||
|
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
|
||||||
|
nvm_err '--reinstall-packages-from may not be provided more than once'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
|
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
|
||||||
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
|
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
|
||||||
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
|
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
|
||||||
|
@ -2682,14 +2722,22 @@ nvm() {
|
||||||
fi
|
fi
|
||||||
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
||||||
;;
|
;;
|
||||||
--reinstall-packages-from)
|
|
||||||
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node using `=`.'
|
|
||||||
return 6
|
|
||||||
;;
|
|
||||||
--copy-packages-from=*)
|
--copy-packages-from=*)
|
||||||
|
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
|
||||||
|
nvm_err '--reinstall-packages-from may not be provided more than once, or combined with `--copy-packages-from`'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
|
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
|
||||||
|
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
|
||||||
|
nvm_err 'If --copy-packages-from is provided, it must point to an installed version of node.'
|
||||||
|
return 6
|
||||||
|
fi
|
||||||
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
|
||||||
;;
|
;;
|
||||||
|
--reinstall-packages-from | --copy-packages-from)
|
||||||
|
nvm_err "If ${1} is provided, it must point to an installed version of node using \`=\`."
|
||||||
|
return 6
|
||||||
|
;;
|
||||||
--skip-default-packages)
|
--skip-default-packages)
|
||||||
SKIP_DEFAULT_PACKAGES=true
|
SKIP_DEFAULT_PACKAGES=true
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -7,6 +7,7 @@ die () { echo "$@" ; exit 1; }
|
||||||
# Remove the stuff we're clobbering.
|
# Remove the stuff we're clobbering.
|
||||||
[ -e "${NVM_DIR}/versions/node/v9.7.0" ] && rm -R "${NVM_DIR}/versions/node/v9.7.0"
|
[ -e "${NVM_DIR}/versions/node/v9.7.0" ] && rm -R "${NVM_DIR}/versions/node/v9.7.0"
|
||||||
[ -e "${NVM_DIR}/versions/node/v9.10.0" ] && rm -R "${NVM_DIR}/versions/node/v9.10.0"
|
[ -e "${NVM_DIR}/versions/node/v9.10.0" ] && rm -R "${NVM_DIR}/versions/node/v9.10.0"
|
||||||
|
[ -e "${NVM_DIR}/versions/node/v4.9.1" ] && rm -R "${NVM_DIR}/versions/node/v4.9.1"
|
||||||
|
|
||||||
# Install from binary
|
# Install from binary
|
||||||
nvm install 9.7.0
|
nvm install 9.7.0
|
||||||
|
@ -31,3 +32,15 @@ nvm use 9
|
||||||
node --version | grep v9.10.0 > /dev/null || die "nvm ls 9 didn't use v9.10.0"
|
node --version | grep v9.10.0 > /dev/null || die "nvm ls 9 didn't use v9.10.0"
|
||||||
|
|
||||||
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
|
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
|
||||||
|
|
||||||
|
|
||||||
|
# LTS
|
||||||
|
|
||||||
|
nvm install --lts=argon --reinstall-packages-from=9 || die "nvm install 9.10.0 --reinstall-packages-from=9 failed"
|
||||||
|
|
||||||
|
[ -d "${NVM_DIR}/versions/node/v4.9.1" ] || die "nvm install 4.9.1 didn't install"
|
||||||
|
|
||||||
|
nvm use --lts=argon
|
||||||
|
node --version | grep v4.9.1 > /dev/null || die "nvm ls --lts=argon didn't use v4.9.1"
|
||||||
|
|
||||||
|
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
|
||||||
|
|
Loading…
Reference in New Issue