mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-11 14:51:49 +00:00
fixed eclint problem; renamed some files/functions
This commit is contained in:
parent
12f75e415f
commit
7c888aa4e5
@ -18,6 +18,11 @@ indent_style = tab
|
|||||||
[test/fast/Unit tests/package_json_templates/*]
|
[test/fast/Unit tests/package_json_templates/*]
|
||||||
indent_style = unset
|
indent_style = unset
|
||||||
|
|
||||||
[test/fast/Unit tests/nvm_get_node_from_pkg_json]
|
[test/generated_semvers.sh]
|
||||||
indent_style = unset
|
indent_style = unset
|
||||||
indent_size = unset
|
indent_size = unset
|
||||||
|
|
||||||
|
[test/fast/Unit tests/nvm_trim_and_reduce_whitespace_to_one_space]
|
||||||
|
indent_style = unset
|
||||||
|
indent_size = unset
|
||||||
|
|
||||||
|
34
nvm.sh
34
nvm.sh
@ -318,14 +318,9 @@ nvm_string_contains_regexp() {
|
|||||||
# comparator_set ::= comparator ( ' ' comparator )*
|
# comparator_set ::= comparator ( ' ' comparator )*
|
||||||
# comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+
|
# comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+
|
||||||
nvm_is_valid_semver() {
|
nvm_is_valid_semver() {
|
||||||
if nvm_string_contains_regexp "${1-}" '^( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+( \|\| ( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+)*$'; then
|
nvm_string_contains_regexp "${1-}" '^( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+( \|\| ( ?(<|<=|>|>=)?[0-9]+\.[0-9]+\.[0-9]+)+)*$'
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO figure out if the commented out logic is needed anywhere
|
|
||||||
nvm_trim_and_reduce_whitespace_to_one_space() {
|
nvm_trim_and_reduce_whitespace_to_one_space() {
|
||||||
command printf "%s" "${1-}" |
|
command printf "%s" "${1-}" |
|
||||||
command tr -d '\n\r' |
|
command tr -d '\n\r' |
|
||||||
@ -334,14 +329,13 @@ nvm_trim_and_reduce_whitespace_to_one_space() {
|
|||||||
command sed 's/^ //; s/ $//; s/^ //'
|
command sed 's/^ //; s/ $//; s/^ //'
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO rename this function to 'nvm_normalize_semver'
|
# Attempts to normalize the given semver to the following grammar:
|
||||||
# Attempts to convert given semver to the following grammar:
|
|
||||||
#
|
#
|
||||||
# semver ::= comparator_set ( ' || ' comparator_set )*
|
# semver ::= comparator_set ( ' || ' comparator_set )*
|
||||||
# comparator_set ::= comparator ( ' ' comparator )*
|
# comparator_set ::= comparator ( ' ' comparator )*
|
||||||
# comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+
|
# comparator ::= ( '<' | '<=' | '>' | '>=' | '' ) [0-9]+ '.' [0-9]+ '.' [0-9]+
|
||||||
nvm_validate_semver() {
|
nvm_normalize_semver() {
|
||||||
# split the semantic version into comparator_set's
|
# split the semantic version's comparator_set's onto their own lines for iteration
|
||||||
local semver
|
local semver
|
||||||
semver=$(nvm_trim_and_reduce_whitespace_to_one_space "${1-}" | command tr '||' '\n')
|
semver=$(nvm_trim_and_reduce_whitespace_to_one_space "${1-}" | command tr '||' '\n')
|
||||||
if [ -z "$semver" ]; then
|
if [ -z "$semver" ]; then
|
||||||
@ -395,7 +389,7 @@ nvm_validate_semver() {
|
|||||||
s/ (=|v)//g;
|
s/ (=|v)//g;
|
||||||
" \
|
" \
|
||||||
| command awk '{
|
| command awk '{
|
||||||
# handle conversions of comparators with '^' or '~' or 'x' into required grammar
|
# handle conversions of comparators with ^ or ~ or x into required grammar
|
||||||
# ` ^0.0.1 ` => ` >=0.0.1 <0.0.2 `
|
# ` ^0.0.1 ` => ` >=0.0.1 <0.0.2 `
|
||||||
# ` ^0.1.2 ` => ` >=0.1.2 <0.2.0 `
|
# ` ^0.1.2 ` => ` >=0.1.2 <0.2.0 `
|
||||||
# ` ^1.2.3 ` => ` >=1.2.3 <2.0.0 `
|
# ` ^1.2.3 ` => ` >=1.2.3 <2.0.0 `
|
||||||
@ -537,7 +531,7 @@ nvm_interpret_complex_semver() {
|
|||||||
[ -n "$current_comparator" ] || continue
|
[ -n "$current_comparator" ] || continue
|
||||||
|
|
||||||
local stripped_version_from_comparator
|
local stripped_version_from_comparator
|
||||||
stripped_version_from_comparator="$(command printf "%s" "$current_comparator" | nvm_grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+$')"
|
stripped_version_from_comparator=$(command printf "%s" "$current_comparator" | nvm_grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+$')
|
||||||
if [ -z "$stripped_version_from_comparator" ]; then
|
if [ -z "$stripped_version_from_comparator" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -638,6 +632,8 @@ nvm_interpret_complex_semver() {
|
|||||||
done
|
done
|
||||||
if [ "$highest_compatible_version" != '0.0.0' ]; then
|
if [ "$highest_compatible_version" != '0.0.0' ]; then
|
||||||
command printf "%s" "$highest_compatible_version"
|
command printf "%s" "$highest_compatible_version"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,7 +647,7 @@ nvm_interpret_simple_semver() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local stripped_version_from_semver
|
local stripped_version_from_semver
|
||||||
stripped_version_from_semver="$(command printf "%s" "$semver" | nvm_grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')"
|
stripped_version_from_semver=$(command printf "%s" "$semver" | nvm_grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')
|
||||||
local newest_version_from_list
|
local newest_version_from_list
|
||||||
newest_version_from_list=$(command printf "%s" "$version_list" | tail -n 1 | nvm_grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')
|
newest_version_from_list=$(command printf "%s" "$version_list" | tail -n 1 | nvm_grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')
|
||||||
if [ -z "$stripped_version_from_semver" ] || [ -z "$newest_version_from_list" ]; then
|
if [ -z "$stripped_version_from_semver" ] || [ -z "$newest_version_from_list" ]; then
|
||||||
@ -713,7 +709,7 @@ nvm_interpret_node_semver() {
|
|||||||
|
|
||||||
# Validate incoming semver and transform it into the grammar that is expected by the following logic
|
# Validate incoming semver and transform it into the grammar that is expected by the following logic
|
||||||
local valid_transformed_semver
|
local valid_transformed_semver
|
||||||
valid_transformed_semver=$(nvm_validate_semver "$semver")
|
valid_transformed_semver=$(nvm_normalize_semver "$semver")
|
||||||
if [ -z "$valid_transformed_semver" ]; then
|
if [ -z "$valid_transformed_semver" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -797,13 +793,13 @@ nvm_get_node_from_pkg_json() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return 2
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_package_json_version() {
|
nvm_package_json_version() {
|
||||||
export RESOLVED_PKG_JSON_VERSION=''
|
export RESOLVED_PKG_JSON_VERSION=''
|
||||||
local pkg_json_path
|
local pkg_json_path
|
||||||
pkg_json_path="$(nvm_find_package_json)"
|
pkg_json_path=$(nvm_find_package_json)
|
||||||
if [ ! -e "${pkg_json_path}" ]; then
|
if [ ! -e "${pkg_json_path}" ]; then
|
||||||
nvm_err "No package.json file found"
|
nvm_err "No package.json file found"
|
||||||
return 1
|
return 1
|
||||||
@ -812,14 +808,14 @@ nvm_package_json_version() {
|
|||||||
pkg_json_semver=$(nvm_get_node_from_pkg_json "$(command cat "$pkg_json_path")" || command printf '')
|
pkg_json_semver=$(nvm_get_node_from_pkg_json "$(command cat "$pkg_json_path")" || command printf '')
|
||||||
if [ ! -n "${pkg_json_semver}" ]; then
|
if [ ! -n "${pkg_json_semver}" ]; then
|
||||||
nvm_err "Warning: could not retrieve engines.node semver expression in package.json file found at \"${pkg_json_path}\""
|
nvm_err "Warning: could not retrieve engines.node semver expression in package.json file found at \"${pkg_json_path}\""
|
||||||
return 2
|
return 1
|
||||||
else
|
else
|
||||||
nvm_echo "Found '${pkg_json_path}' with semver expression <${pkg_json_semver}>"
|
nvm_echo "Found '${pkg_json_path}' with semver expression <${pkg_json_semver}>"
|
||||||
# attempt complex semver range evaluation
|
# attempt complex semver range evaluation
|
||||||
RESOLVED_PKG_JSON_VERSION=$(nvm_interpret_node_semver "$pkg_json_semver")
|
RESOLVED_PKG_JSON_VERSION=$(nvm_interpret_node_semver "$pkg_json_semver")
|
||||||
if [ ! -n "${RESOLVED_PKG_JSON_VERSION}" ]; then
|
if [ ! -n "${RESOLVED_PKG_JSON_VERSION}" ]; then
|
||||||
nvm_err "Warning: could not interpret engines.node semver expression obtained from package.json file."
|
nvm_err "Warning: could not interpret engines.node semver expression obtained from package.json file."
|
||||||
return 2
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -4081,7 +4077,7 @@ nvm() {
|
|||||||
node_version_has_solaris_binary iojs_version_has_solaris_binary \
|
node_version_has_solaris_binary iojs_version_has_solaris_binary \
|
||||||
nvm_curl_libz_support nvm_command_info \
|
nvm_curl_libz_support nvm_command_info \
|
||||||
nvm_get_node_from_pkg_json nvm_find_package_json nvm_package_json_version \
|
nvm_get_node_from_pkg_json nvm_find_package_json nvm_package_json_version \
|
||||||
nvm_interpret_node_semver nvm_interpret_simple_semver nvm_interpret_complex_semver nvm_validate_semver \
|
nvm_interpret_node_semver nvm_interpret_simple_semver nvm_interpret_complex_semver nvm_normalize_semver \
|
||||||
nvm_is_valid_semver nvm_string_contains_regexp nvm_trim_and_reduce_whitespace_to_one_space \
|
nvm_is_valid_semver nvm_string_contains_regexp nvm_trim_and_reduce_whitespace_to_one_space \
|
||||||
> /dev/null 2>&1
|
> /dev/null 2>&1
|
||||||
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
die () { printf "$@" ; exit 1; }
|
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
\. sharedTestResources/semvers
|
\. ../../generated_semvers.sh
|
||||||
|
|
||||||
|
|
||||||
# POSITIVE TEST CASES
|
# POSITIVE TEST CASES
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
die () { printf "$@" ; exit 1; }
|
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
\. sharedTestResources/semvers
|
\. ../../generated_semvers.sh
|
||||||
|
|
||||||
# nvm_is_valid_semver validates that given semvers adhere to the following grammer
|
# nvm_is_valid_semver validates that given semvers adhere to the following grammer
|
||||||
#
|
#
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
die () { printf "$@" ; exit 1; }
|
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
|
\. ../../generated_semvers.sh
|
||||||
|
|
||||||
# TODO add more test cases here
|
# TODO add more test cases here
|
||||||
# Some test cases should just test that valid semvers from sharedTestResources/semvers just produce some result
|
# Some test cases should just test that valid semvers from 'Shared test tesources'/semvers just produce some result
|
||||||
|
|
||||||
# input:expected_output
|
# input:expected_output
|
||||||
test_cases="1.2.3:1.2.3
|
test_cases="1.2.3:1.2.3
|
||||||
1.2.3 - 1.2.4:>=1.2.3 <=1.2.4
|
1.2.3 - 1.2.4:>=1.2.3 <=1.2.4
|
||||||
@ -46,7 +46,7 @@ while [ -n "$test_cases" ]; do
|
|||||||
line=$(echo "$test_cases" | head -n1)
|
line=$(echo "$test_cases" | head -n1)
|
||||||
input=$(echo "$line" | awk -F: '{ print $1 }')
|
input=$(echo "$line" | awk -F: '{ print $1 }')
|
||||||
expected_output=$(echo "$line" | awk -F: '{ print $2 }')
|
expected_output=$(echo "$line" | awk -F: '{ print $2 }')
|
||||||
actual_output=$(nvm_validate_semver "$input")
|
actual_output=$(nvm_normalize_semver "$input")
|
||||||
if [ -z "$input" ] || [ "$actual_output" != "$expected_output" ]; then
|
if [ -z "$input" ] || [ "$actual_output" != "$expected_output" ]; then
|
||||||
die "nvm_validate_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n"
|
die "nvm_validate_semver test case failed. Expected output: '$expected_output'. Actual output: '$actual_output'. Input: '$input'.\n"
|
||||||
fi
|
fi
|
@ -1,11 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# TODO this test currently takes about 16 minutes so it should not be in the "fast" test directory and maybe is too long regardless.
|
|
||||||
|
|
||||||
die () { printf "$@" ; exit 1; }
|
die () { printf "$@" ; exit 1; }
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../nvm.sh
|
||||||
\. sharedTestResources/semvers
|
\. ../generated_semvers.sh
|
||||||
|
|
||||||
# Verify that all generated valid normalized semvers produce some result
|
# Verify that all generated valid normalized semvers produce some result
|
||||||
test_cases="$VALID_SEMVERS"
|
test_cases="$VALID_SEMVERS"
|
Loading…
Reference in New Issue
Block a user