1- #! /usr/ bin/env bash
1+ #! /bin/bash
22#
33# If a custom Node version is not already defined, we look
44# for a Node version semver expressing in the current tree's package.json.
1313package_json_has_precedence () {
1414 if [[ ( -z " $( nodenv local 2> /dev/null) " )
1515 && ( -z " $( nodenv sh-shell 2> /dev/null) " ) ]]; then
16- exit ;
16+ return ;
1717 else
18- exit 1;
18+ return 1;
1919 fi
2020}
2121
2222find_package_json_path () {
23- local root=" $1 "
23+ root=" $1 "
2424 while [ -n " $root " ]; do
2525 if [ -e " ${root} /package.json" ]; then
2626 echo " ${root} /package.json"
27- exit
27+ return
2828 fi
2929 root=" ${root%/* } "
3030 done
3131}
3232
3333extract_version_from_package_json () {
34- local package_json_path=" $1 "
35- local version_regex=' "node":[ \t]*"([^"]*)"'
34+ package_json_path=" $1 "
35+ version_regex=' "node":[ \t]*"([^"]*)"'
3636 [[ $( cat " $package_json_path " ) =~ $version_regex ]]
3737 echo " ${BASH_REMATCH[1]} "
3838}
3939
4040find_installed_verion_matching_expression () {
41- local version_expression=" $1 "
41+ version_expression=" $1 "
4242 local -a installed_versions
4343 while IFS= read -r v; do
4444 installed_versions+=( " $v " )
@@ -52,32 +52,30 @@ find_installed_verion_matching_expression() {
5252SEMVER=" $( plugin_root) /node_modules/sh-semver/semver.sh"
5353
5454get_version_respecting_precedence () {
55- if ! $( package_json_has_precedence) ; then
56- exit
57- fi
55+ if ! package_json_has_precedence; then return ; fi
5856
59- local package_json_path=$( find_package_json_path " $PWD " )
60- if [ ! -e " $package_json_path " ]; then exit ; fi
57+ package_json_path=$( find_package_json_path " $PWD " )
58+ if [ ! -e " $package_json_path " ]; then return ; fi
6159
62- local version_expression=$(
60+ version_expression=$(
6361 extract_version_from_package_json " $package_json_path "
6462 )
65- if [ -z " $version_expression " ]; then exit ; fi
63+ if [ -z " $version_expression " ]; then return ; fi
6664
67- local version=$(
65+ version=$(
6866 find_installed_verion_matching_expression " $version_expression "
6967 )
70- if [ -z " $version " ]; then exit 1; fi
68+ if [ -z " $version " ]; then return 1; fi
7169 echo " $version "
7270}
7371
7472get_expression_respecting_precedence () {
75- if ! $( package_json_has_precedence) ; then exit ; fi
73+ if ! package_json_has_precedence; then return ; fi
7674
77- local package_json_path=$( find_package_json_path " $PWD " )
78- if [ ! -e " $package_json_path " ]; then exit ; fi
75+ package_json_path=$( find_package_json_path " $PWD " )
76+ if [ ! -e " $package_json_path " ]; then return ; fi
7977
80- local version_expression=$(
78+ version_expression=$(
8179 extract_version_from_package_json " $package_json_path "
8280 )
8381 echo " $version_expression "
0 commit comments