Skip to content

Commit

Permalink
Merge pull request #310 from Automattic/install-node-if-necessary
Browse files Browse the repository at this point in the history
fix(vip-cli): install Node.js only if necessary
  • Loading branch information
sjinks authored Aug 8, 2024
2 parents 392c623 + 58991e2 commit e7ece92
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion features/src/vip-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "vip-cli",
"name": "VIP-CLI",
"version": "1.4.4",
"version": "1.4.5",
"description": "Installs VIP-CLI into the Dev Environment",
"options": {
"enabled": {
Expand Down
52 changes: 27 additions & 25 deletions features/src/vip-cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ if [ "$(id -u || true)" -ne 0 ]; then
fi

: "${ENABLED:=}"
: "${VERSION:=latest}"
VIP_CLI_VERSION="${VERSION:-latest}"

if [ "${ENABLED}" = "true" ]; then
echo '(*) Installing VIP CLI...'

# /etc/os-release may overwrite VERSION
VIP_CLI_VERSION="${VERSION}"

if ! hash node >/dev/null 2>&1 || ! hash npm >/dev/null 2>&1; then
# shellcheck source=/dev/null
. /etc/os-release
Expand All @@ -28,32 +25,37 @@ if [ "${ENABLED}" = "true" ]; then
case "${ID_LIKE}" in
"debian")
export DEBIAN_FRONTEND=noninteractive
PACKAGES=""

if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash update-ca-certificates >/dev/null 2>&1; then
PACKAGES="${PACKAGES} ca-certificates"
fi

if [ -n "${PACKAGES}" ]; then
apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}
if ! hash node >/dev/null 2>&1 || ! hash npm >/dev/null 2>&1 || ! hash npx >/dev/null 2>&1; then
PACKAGES=""
if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash update-ca-certificates >/dev/null 2>&1; then
PACKAGES="${PACKAGES} ca-certificates"
fi

if [ -n "${PACKAGES}" ]; then
apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}
fi

curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
chmod +x nodesource_setup.sh
./nodesource_setup.sh
apt-get install -y nodejs

apt-get clean
rm -rf /var/lib/apt/lists/*
fi

curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh && chmod +x nodesource_setup.sh
./nodesource_setup.sh
apt-get install -y nodejs

apt-get clean
rm -rf /var/lib/apt/lists/*
;;

"alpine")
apk add --no-cache nodejs npm
if ! hash node >/dev/null 2>&1 || ! hash npm >/dev/null 2>&1; then
apk add --no-cache nodejs npm
fi
;;

*)
Expand Down

0 comments on commit e7ece92

Please sign in to comment.