Unverified Commit 9e75db9a authored by Shikanime Deva's avatar Shikanime Deva Committed by GitHub

Avoid unexpected shell expansion (#645)

* Avoid unexpected shell expansion

* Add install Node with ZSH as default test

* Fix LTS only work on >bionic

* Bump Node feature version

* Remove huge universal image on scenarios
parent f2594c5c
{ {
"id": "node", "id": "node",
"version": "1.2.0", "version": "1.2.1",
"name": "Node.js (via nvm), yarn and pnpm", "name": "Node.js (via nvm), yarn and pnpm",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.", "description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
export NODE_VERSION="${VERSION:-"lts"}" export NODE_VERSION="${VERSION:-"lts"}"
export NVM_VERSION="${NVMVERSION:-"0.39.2"}" export NVM_VERSION="${NVMVERSION:-"0.39.2"}"
export NVM_DIR=${NVMINSTALLPATH:-"/usr/local/share/nvm"} export NVM_DIR="${NVMINSTALLPATH:-"/usr/local/share/nvm"}"
INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}" INSTALL_TOOLS_FOR_NODE_GYP="${NODEGYPDEPENDENCIES:-true}"
# Comma-separated list of node versions to be installed (with nvm) # Comma-separated list of node versions to be installed (with nvm)
...@@ -118,10 +118,10 @@ set -e ...@@ -118,10 +118,10 @@ set -e
umask 0002 umask 0002
# Do not update profile - we'll do this manually # Do not update profile - we'll do this manually
export PROFILE=/dev/null export PROFILE=/dev/null
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash
source ${NVM_DIR}/nvm.sh source "${NVM_DIR}/nvm.sh"
if [ "${NODE_VERSION}" != "" ]; then if [ "${NODE_VERSION}" != "" ]; then
nvm alias default ${NODE_VERSION} nvm alias default "${NODE_VERSION}"
fi fi
EOF EOF
)" )"
...@@ -149,9 +149,9 @@ usermod -a -G nvm ${USERNAME} ...@@ -149,9 +149,9 @@ usermod -a -G nvm ${USERNAME}
umask 0002 umask 0002
if [ ! -d "${NVM_DIR}" ]; then if [ ! -d "${NVM_DIR}" ]; then
# Create nvm dir, and set sticky bit # Create nvm dir, and set sticky bit
mkdir -p ${NVM_DIR} mkdir -p "${NVM_DIR}"
chown "${USERNAME}:nvm" ${NVM_DIR} chown "${USERNAME}:nvm" "${NVM_DIR}"
chmod g+rws ${NVM_DIR} chmod g+rws "${NVM_DIR}"
su ${USERNAME} -c "${nvm_install_snippet}" 2>&1 su ${USERNAME} -c "${nvm_install_snippet}" 2>&1
# Update rc files # Update rc files
if [ "${UPDATE_RC}" = "true" ]; then if [ "${UPDATE_RC}" = "true" ]; then
...@@ -160,7 +160,7 @@ if [ ! -d "${NVM_DIR}" ]; then ...@@ -160,7 +160,7 @@ if [ ! -d "${NVM_DIR}" ]; then
else else
echo "NVM already installed." echo "NVM already installed."
if [ "${NODE_VERSION}" != "" ]; then if [ "${NODE_VERSION}" != "" ]; then
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm install ${NODE_VERSION} && nvm alias default ${NODE_VERSION}" su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${NODE_VERSION}' && nvm alias default '${NODE_VERSION}'"
fi fi
fi fi
...@@ -173,12 +173,12 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then ...@@ -173,12 +173,12 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then
IFS="," IFS=","
read -a additional_versions <<< "$ADDITIONAL_VERSIONS" read -a additional_versions <<< "$ADDITIONAL_VERSIONS"
for ver in "${additional_versions[@]}"; do for ver in "${additional_versions[@]}"; do
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm install ${ver}" su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm install '${ver}'"
done done
# Ensure $NODE_VERSION is on the $PATH # Ensure $NODE_VERSION is on the $PATH
if [ "${NODE_VERSION}" != "" ]; then if [ "${NODE_VERSION}" != "" ]; then
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm use default" su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm use default"
fi fi
IFS=$OLDIFS IFS=$OLDIFS
fi fi
...@@ -218,7 +218,7 @@ fi ...@@ -218,7 +218,7 @@ fi
# Clean up # Clean up
su ${USERNAME} -c "umask 0002 && . $NVM_DIR/nvm.sh && nvm clear-cache" su ${USERNAME} -c "umask 0002 && . '$NVM_DIR/nvm.sh' && nvm clear-cache"
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
# Ensure privs are correct for installed node versions. Unfortunately the # Ensure privs are correct for installed node versions. Unfortunately the
......
...@@ -17,21 +17,23 @@ ...@@ -17,21 +17,23 @@
} }
} }
}, },
"version_none": { "zsh_default": {
"image": "mcr.microsoft.com/devcontainers/base", "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"remoteUser": "vscode",
"features": { "features": {
"node": { "node": {
"version": "none" "version": "lts"
},
"common-utils": {
"configureZshAsDefaultShell": true
} }
} }
}, },
"install_node_on_universal_image": { "version_none": {
"image": "mcr.microsoft.com/devcontainers/universal", "image": "mcr.microsoft.com/devcontainers/base",
"remoteUser": "codespace", "remoteUser": "vscode",
"features": { "features": {
"node": { "node": {
"version": "19.1.0" "version": "none"
} }
} }
}, },
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "nvm" bash -c ". /usr/local/share/nvm/nvm.sh && nvm install 10"
# Report result
reportResults
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment