aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/node/devcontainer-feature.json10
-rwxr-xr-xsrc/node/install.sh42
-rwxr-xr-xtest/node/install_nvm_0.39.sh14
-rw-r--r--test/node/scenarios.json10
4 files changed, 71 insertions, 5 deletions
diff --git a/src/node/devcontainer-feature.json b/src/node/devcontainer-feature.json
index 80bd912..aee55a1 100644
--- a/src/node/devcontainer-feature.json
+++ b/src/node/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "node",
- "version": "1.2.1",
+ "version": "1.3.0",
"name": "Node.js (via nvm), yarn and pnpm",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",
@@ -30,7 +30,11 @@
},
"nvmVersion": {
"type": "string",
- "default": "0.39.2",
+ "proposals": [
+ "latest",
+ "0.39"
+ ],
+ "default": "latest",
"description": "Version of NVM to install."
}
},
@@ -49,4 +53,4 @@
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
-} \ No newline at end of file
+}
diff --git a/src/node/install.sh b/src/node/install.sh
index 1ce8fee..8091094 100755
--- a/src/node/install.sh
+++ b/src/node/install.sh
@@ -8,7 +8,7 @@
# Maintainer: The Dev Container spec maintainers
export NODE_VERSION="${VERSION:-"lts"}"
-export NVM_VERSION="${NVMVERSION:-"0.39.2"}"
+export NVM_VERSION="${NVMVERSION:-"latest"}"
export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
@@ -78,6 +78,40 @@ check_packages() {
fi
}
+# Figure out correct version of a three part version number is not passed
+find_version_from_git_tags() {
+ local variable_name=$1
+ local requested_version=${!variable_name}
+ if [ "${requested_version}" = "none" ]; then return; fi
+ local repository=$2
+ local prefix=${3:-"tags/v"}
+ local separator=${4:-"."}
+ local last_part_optional=${5:-"false"}
+ if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
+ local escaped_separator=${separator//./\\.}
+ local last_part
+ if [ "${last_part_optional}" = "true" ]; then
+ last_part="(${escaped_separator}[0-9]+)?"
+ else
+ last_part="${escaped_separator}[0-9]+"
+ fi
+ local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
+ local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
+ if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
+ declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
+ else
+ set +e
+ declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
+ set -e
+ fi
+ fi
+ if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
+ echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
+ exit 1
+ fi
+ echo "${variable_name}=${!variable_name}"
+}
+
# Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive
@@ -92,6 +126,10 @@ fi
# Install dependencies
check_packages apt-transport-https curl ca-certificates tar gnupg2 dirmngr
+if ! type git > /dev/null 2>&1; then
+ check_packages git
+fi
+
# Install yarn
if type yarn > /dev/null 2>&1; then
echo "Yarn already installed."
@@ -112,6 +150,8 @@ elif [ "${NODE_VERSION}" = "latest" ]; then
export NODE_VERSION="node"
fi
+find_version_from_git_tags NVM_VERSION "https://github.com/nvm-sh/nvm"
+
# Install snipppet that we will run as the user
nvm_install_snippet="$(cat << EOF
set -e
diff --git a/test/node/install_nvm_0.39.sh b/test/node/install_nvm_0.39.sh
new file mode 100755
index 0000000..6b96381
--- /dev/null
+++ b/test/node/install_nvm_0.39.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+
+# Optional: Import test library
+source dev-container-features-test-lib
+
+# Definition specific tests
+check "version" bash -c "node --version"
+check "pnpm" pnpm -v
+check "nvm version" bash -c ". /usr/local/share/nvm/nvm.sh && nvm --version | grep 0.39"
+
+# Report result
+reportResults
diff --git a/test/node/scenarios.json b/test/node/scenarios.json
index 5524f5c..a45620f 100644
--- a/test/node/scenarios.json
+++ b/test/node/scenarios.json
@@ -44,5 +44,13 @@
"version": "16"
}
}
+ },
+ "install_nvm_0.39": {
+ "image": "mcr.microsoft.com/devcontainers/base",
+ "features": {
+ "node": {
+ "nvmVersion": "0.39"
+ }
+ }
}
-} \ No newline at end of file
+}