fix: auto-detect and upgrade Node.js to >= 22.22.0 across Linux, macOS and Windows

- Add smart Node.js compatibility checking (>= 22.22.0) required by Angular CLI 22
- Upgrade portable Node.js fallback download to v22.23.2 LTS across Linux, macOS and Windows
- Add automatic upgrade paths using nvm, NodeSource 22.x (with sudo/root), and winget
- Display detected Node.js version in toolchain readiness summary
This commit is contained in:
somew1nd committed 2026-09-04 17:01:57 -07:00
1 parent 41b1b94706
commit 29622bae52
4 files changed
+313 -108

No files matched your search

+79 -30
View File
@@ -94,6 +94,27 @@ request_sudo() {
return 1
}
# Helper to check if Node.js & npm meet Angular CLI 22 requirement (>= 22.22.0, >= 24.15.0, or >= 26.0.0)
is_node_compatible() {
if ! command -v node >/dev/null 2>&1 || ! command -v npm >/dev/null 2>&1; then
return 1
fi
local node_ver
node_ver="$(node -v 2>/dev/null | tr -d 'v')"
[ -z "${node_ver}" ] && return 1
local major minor
major="$(echo "${node_ver}" | cut -d. -f1)"
minor="$(echo "${node_ver}" | cut -d. -f2)"
if [ "${major}" -ge 26 ] 2>/dev/null; then
return 0
elif [ "${major}" -ge 24 ] 2>/dev/null; then
[ "${minor}" -ge 15 ] 2>/dev/null && return 0
elif [ "${major}" -ge 22 ] 2>/dev/null; then
[ "${minor}" -ge 22 ] 2>/dev/null && return 0
fi
return 1
}
# 2. Check or install uv (Fast Python package manager)
if ! command -v uv >/dev/null 2>&1; then
echo -e "${YELLOW}⚡ uv not found. Installing Astral uv...${NC}"
@@ -226,50 +247,78 @@ if [ ! -f "${SHOWCASE_INDEX}" ] && [ ! -f "${SHOWCASE_INDEX_ALT1}" ] && [ ! -f "
export PATH="${HOME}/.local/share/node/bin:${PATH}"
fi
if ! command -v npm >/dev/null 2>&1; then
# Check if nvm already has a compatible Node version installed
if ! is_node_compatible && (command -v nvm >/dev/null 2>&1 || type nvm >/dev/null 2>&1); then
nvm use 22 >/dev/null 2>&1 || true
fi
if ! is_node_compatible; then
OS_NAME="$(uname -s)"
echo -e " ${YELLOW}⚡ npm/Node.js not found. Auto-installing Node.js for Showcase UI compilation...${NC}"
if [ "${OS_NAME}" = "Darwin" ] && command -v brew >/dev/null 2>&1; then
brew install node >/dev/null 2>&1 || true
elif [ "${OS_NAME}" = "Linux" ]; then
if request_sudo "install Node.js and npm"; then
if command -v node >/dev/null 2>&1; then
echo -e " ${YELLOW}⚡ Detected Node.js $(node -v 2>/dev/null), but Angular CLI requires Node.js >= v22.22.0. Upgrading Node.js...${NC}"
else
echo -e " ${YELLOW}⚡ Node.js/npm not found. Auto-installing Node.js 22 LTS for Showcase UI compilation...${NC}"
fi
# 1. Try installing Node 22 via nvm if available
if command -v nvm >/dev/null 2>&1 || type nvm >/dev/null 2>&1; then
echo -e " ${CYAN}📦 Installing Node.js 22 LTS via nvm...${NC}"
nvm install 22 >/dev/null 2>&1 || true
nvm use 22 >/dev/null 2>&1 || true
fi
# 2. Try brew on macOS
if ! is_node_compatible && [ "${OS_NAME}" = "Darwin" ] && command -v brew >/dev/null 2>&1; then
brew install node >/dev/null 2>&1 || brew upgrade node >/dev/null 2>&1 || true
fi
# 3. Try Linux package managers with sudo / root
if ! is_node_compatible && [ "${OS_NAME}" = "Linux" ]; then
if request_sudo "install or upgrade Node.js to >= 22.22.0"; then
SUDO_PREFIX=""
if [ "$(id -u)" -ne 0 ]; then SUDO_PREFIX="sudo"; fi
if command -v apt-get >/dev/null 2>&1; then
${SUDO_PREFIX} apt-get update -qq && ${SUDO_PREFIX} apt-get install -y -qq nodejs npm || true
echo -e " ${CYAN}📦 Configuring NodeSource Node.js 22 LTS repository...${NC}"
curl -fsSL https://deb.nodesource.com/setup_22.x | ${SUDO_PREFIX} bash - >/dev/null 2>&1 || true
${SUDO_PREFIX} apt-get install -y -qq nodejs || true
elif command -v dnf >/dev/null 2>&1; then
${SUDO_PREFIX} dnf install -y nodejs npm || true
curl -fsSL https://rpm.nodesource.com/setup_22.x | ${SUDO_PREFIX} bash - >/dev/null 2>&1 || true
${SUDO_PREFIX} dnf install -y nodejs || true
elif command -v pacman >/dev/null 2>&1; then
${SUDO_PREFIX} pacman -S --noconfirm nodejs npm || true
fi
fi
fi
# If npm still not found (e.g. no root/sudo privileges on cloud workstation):
if ! command -v npm >/dev/null 2>&1; then
ARCH="$(uname -m)"
NODE_ARCH=""
case "${ARCH}" in
x86_64|amd64) NODE_ARCH="x64" ;;
aarch64|arm64) NODE_ARCH="arm64" ;;
esac
if [ -n "${NODE_ARCH}" ]; then
NODE_VER="v20.18.3"
NODE_DIR="${HOME}/.local/share/node"
echo -e " ${CYAN}📦 Installing portable Node.js ${NODE_VER} in user space (~/.local)...${NC}"
mkdir -p "${NODE_DIR}" "${HOME}/.local/bin"
if curl -fsSL "https://nodejs.org/dist/${NODE_VER}/node-${NODE_VER}-linux-${NODE_ARCH}.tar.gz" | tar -xz -C "${NODE_DIR}" --strip-components=1 2>/dev/null; then
ln -sf "${NODE_DIR}/bin/node" "${HOME}/.local/bin/node"
ln -sf "${NODE_DIR}/bin/npm" "${HOME}/.local/bin/npm"
ln -sf "${NODE_DIR}/bin/npx" "${HOME}/.local/bin/npx"
export PATH="${NODE_DIR}/bin:${HOME}/.local/bin:${PATH}"
echo -e " ${GREEN}✓ Portable Node.js installed in user space.${NC}"
fi
# 4. Standalone portable Node.js LTS (zero-admin user space fallback, guaranteed compatible)
if ! is_node_compatible; then
ARCH="$(uname -m)"
NODE_ARCH=""
case "${ARCH}" in
x86_64|amd64) NODE_ARCH="x64" ;;
aarch64|arm64) NODE_ARCH="arm64" ;;
esac
OS_SYS="$(uname -s | tr '[:upper:]' '[:lower:]')"
if [ -n "${NODE_ARCH}" ] && { [ "${OS_SYS}" = "linux" ] || [ "${OS_SYS}" = "darwin" ]; }; then
NODE_VER="v22.23.2"
NODE_DIR="${HOME}/.local/share/node"
echo -e " ${CYAN}📦 Installing portable Node.js ${NODE_VER} in user space (~/.local)...${NC}"
rm -rf "${NODE_DIR}"
mkdir -p "${NODE_DIR}" "${HOME}/.local/bin"
if curl -fsSL "https://nodejs.org/dist/${NODE_VER}/node-${NODE_VER}-${OS_SYS}-${NODE_ARCH}.tar.gz" | tar -xz -C "${NODE_DIR}" --strip-components=1 2>/dev/null; then
ln -sf "${NODE_DIR}/bin/node" "${HOME}/.local/bin/node"
ln -sf "${NODE_DIR}/bin/npm" "${HOME}/.local/bin/npm"
ln -sf "${NODE_DIR}/bin/npx" "${HOME}/.local/bin/npx"
export PATH="${NODE_DIR}/bin:${HOME}/.local/bin:${PATH}"
hash -r 2>/dev/null || true
echo -e " ${GREEN}✓ Portable Node.js ${NODE_VER} installed in user space.${NC}"
fi
fi
fi
fi
if command -v npm >/dev/null 2>&1; then
if is_node_compatible; then
echo -e " ${GREEN}✓ Node.js $(node -v 2>/dev/null) and npm $(npm -v 2>/dev/null) ready.${NC}"
echo -e " ${YELLOW}🎨 Showcase UI build not found. Compiling Angular Showcase UI...${NC}"
(
cd "${SCRIPT_DIR}/apps/showcase_ui"
@@ -286,7 +335,7 @@ if [ ! -f "${SHOWCASE_INDEX}" ] && [ ! -f "${SHOWCASE_INDEX_ALT1}" ] && [ ! -f "
npm run build
)
else
echo -e " ${YELLOW}⚠ Could not auto-install Node.js. Showcase UI will serve fallback build notice.${NC}"
echo -e " ${YELLOW}⚠ Could not configure compatible Node.js (>= 22.22.0). Showcase UI will serve fallback build notice.${NC}"
fi
fi