aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorJosh Spicer <joshspicer@github.com>2022-07-14 21:12:11 +0300
committerGitHub <noreply@github.com>2022-07-14 21:12:11 +0300
commit01b46faa2dd7d9bd4f453b78f49457f2ffc67d3c (patch)
tree94cbf1eb77f763af807d34e168777c37dbc2668c /src/node
parent7f551f8c2f1129d6485088196bfeb28ff5ee3230 (diff)
smart auto-install multiple versions for `node` (#56)
* node * fix comment (no-ci) * Apply suggestions from code review Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com> * update test scenario * remove minor for node 18 * update scenarios to object notation * add shabang * only set default node once Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com>
Diffstat (limited to 'src/node')
-rw-r--r--src/node/devcontainer-feature.json6
-rw-r--r--src/node/install.sh25
2 files changed, 25 insertions, 6 deletions
diff --git a/src/node/devcontainer-feature.json b/src/node/devcontainer-feature.json
index ebce21b..52715fd 100644
--- a/src/node/devcontainer-feature.json
+++ b/src/node/devcontainer-feature.json
@@ -34,9 +34,5 @@
"NVM_DIR": "/usr/local/share/nvm",
"NVM_SYMLINK_CURRENT": "true",
"PATH": "${NVM_DIR}/current/bin:${PATH}"
- },
- "install": {
- "app": "",
- "file": "install.sh"
}
-} \ No newline at end of file
+}
diff --git a/src/node/install.sh b/src/node/install.sh
index b846007..7169919 100644
--- a/src/node/install.sh
+++ b/src/node/install.sh
@@ -11,6 +11,10 @@ export NODE_VERSION=${VERSION:-"lts"}
export NVM_DIR=${NVM_INSTALL_PATH:-"/usr/local/share/nvm"}
INSTALL_TOOLS_FOR_NODE_GYP="${INSTALL_TOOLS_FOR_NODE_GYP:-true}"
+# Comma-separated list of node versions to be installed (with nvm)
+# alongside NODE_VERSION, but not set as default.
+ADDITIONAL_VERSIONS=${ADDITIONAL_VERSIONS:-""}
+
USERNAME=${USERNAME:-"automatic"}
UPDATE_RC=${UPDATE_RC:-"true"}
@@ -133,7 +137,7 @@ su ${USERNAME} -c "$(cat << EOF
if [ "${NODE_VERSION}" != "" ]; then
nvm alias default ${NODE_VERSION}
fi
- nvm clear-cache
+ nvm clear-cache
EOF
)" 2>&1
# Update rc files
@@ -146,6 +150,25 @@ EOF
)"
fi
+# Additional node versions to be installed but not be set as default.
+if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
+
+ OLDIFS=$IFS
+ IFS=","
+ read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
+ for ver in "${additional_versions[@]}"; do
+ su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm install ${ver}"
+ su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm clear-cache"
+ # Reset the NODE_VERSION as the default version on the path.
+ done
+
+ # Ensure $NODE_VERSION is on the $PATH
+ if [ "${NODE_VERSION}" != "" ]; then
+ su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm use default"
+ fi
+ IFS=$OLDIFS
+fi
+
# If enabled, verify "python3", "make", "gcc", "g++" commands are available so node-gyp works - https://github.com/nodejs/node-gyp
if [ "${INSTALL_TOOLS_FOR_NODE_GYP}" = "true" ]; then
echo "Verifying node-gyp OS requirements..."