8
8
# Maintainer: The Dev Container spec maintainers
9
9
10
10
export NODE_VERSION=" ${VERSION:- " lts" } "
11
- export NVM_VERSION=" ${NVMVERSION:- " 0.39.2 " } "
11
+ export NVM_VERSION=" ${NVMVERSION:- " latest " } "
12
12
export NVM_DIR=" ${NVMINSTALLPATH:- " /usr/local/share/nvm" } "
13
13
INSTALL_TOOLS_FOR_NODE_GYP=" ${NODEGYPDEPENDENCIES:- true} "
14
14
@@ -78,6 +78,40 @@ check_packages() {
78
78
fi
79
79
}
80
80
81
+ # Figure out correct version of a three part version number is not passed
82
+ find_version_from_git_tags () {
83
+ local variable_name=$1
84
+ local requested_version=${! variable_name}
85
+ if [ " ${requested_version} " = " none" ]; then return ; fi
86
+ local repository=$2
87
+ local prefix=${3:- " tags/v" }
88
+ local separator=${4:- " ." }
89
+ local last_part_optional=${5:- " false" }
90
+ if [ " $( echo " ${requested_version} " | grep -o " ." | wc -l) " != " 2" ]; then
91
+ local escaped_separator=${separator// ./ \\ .}
92
+ local last_part
93
+ if [ " ${last_part_optional} " = " true" ]; then
94
+ last_part=" (${escaped_separator} [0-9]+)?"
95
+ else
96
+ last_part=" ${escaped_separator} [0-9]+"
97
+ fi
98
+ local regex=" ${prefix} \\ K[0-9]+${escaped_separator} [0-9]+${last_part} $"
99
+ local version_list=" $( git ls-remote --tags ${repository} | grep -oP " ${regex} " | tr -d ' ' | tr " ${separator} " " ." | sort -rV) "
100
+ if [ " ${requested_version} " = " latest" ] || [ " ${requested_version} " = " current" ] || [ " ${requested_version} " = " lts" ]; then
101
+ declare -g ${variable_name} =" $( echo " ${version_list} " | head -n 1) "
102
+ else
103
+ set +e
104
+ declare -g ${variable_name} =" $( echo " ${version_list} " | grep -E -m 1 " ^${requested_version// ./ \\ .} ([\\ .\\ s]|$)" ) "
105
+ set -e
106
+ fi
107
+ fi
108
+ if [ -z " ${! variable_name} " ] || ! echo " ${version_list} " | grep " ^${! variable_name// ./ \\ .} $" > /dev/null 2>&1 ; then
109
+ echo -e " Invalid ${variable_name} value: ${requested_version} \nValid values:\n${version_list} " >&2
110
+ exit 1
111
+ fi
112
+ echo " ${variable_name} =${! variable_name} "
113
+ }
114
+
81
115
# Ensure apt is in non-interactive to avoid prompts
82
116
export DEBIAN_FRONTEND=noninteractive
83
117
92
126
# Install dependencies
93
127
check_packages apt-transport-https curl ca-certificates tar gnupg2 dirmngr
94
128
129
+ if ! type git > /dev/null 2>&1 ; then
130
+ check_packages git
131
+ fi
132
+
95
133
# Install yarn
96
134
if type yarn > /dev/null 2>&1 ; then
97
135
echo " Yarn already installed."
@@ -112,6 +150,8 @@ elif [ "${NODE_VERSION}" = "latest" ]; then
112
150
export NODE_VERSION=" node"
113
151
fi
114
152
153
+ find_version_from_git_tags NVM_VERSION " https://github.com/nvm-sh/nvm"
154
+
115
155
# Install snipppet that we will run as the user
116
156
nvm_install_snippet=" $( cat << EOF
117
157
set -e
0 commit comments