File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ extract_version_from_package_json() {
3939 package_json_path=" $1 "
4040 version_regex=' \["engines","node"\][[:space:]]*"([^"]*)"'
4141 # -b -n gives minimal output - see https://github.com/dominictarr/JSON.sh#options
42- [[ $( " $JSON_SH " -b -n < " $package_json_path " ) =~ $version_regex ]]
42+ [[ $( " $JSON_SH " -b -n < " $package_json_path " 2> /dev/null ) =~ $version_regex ]]
4343 echo " ${BASH_REMATCH[1]} "
4444}
4545
Original file line number Diff line number Diff line change @@ -90,3 +90,22 @@ load test_helper
9090
9191 assert_success ' system'
9292}
93+
94+ @test ' Does not fail with empty or malformed package.json' {
95+ in_example_package
96+
97+ # empty
98+ touch package.json
99+ run nodenv version-name
100+ assert_success ' system'
101+
102+ # non json
103+ echo " foo" > package.json
104+ run nodenv version-name
105+ assert_success ' system'
106+
107+ # malformed
108+ echo " {" > package.json
109+ run nodenv version-name
110+ assert_success ' system'
111+ }
You can’t perform that action at this time.
0 commit comments