diff --git a/install.sh b/install.sh index 12f5190..e23151a 100644 --- a/install.sh +++ b/install.sh @@ -126,7 +126,7 @@ ensure_node_runtime() { if have_cmd node && have_cmd npm; then major="$(node_major)" - if [[ -n "${major}" && "${major}" -ge 18 ]]; then + if [[ -n "${major}" && "${major}" -ge 20 ]]; then return 0 fi fi @@ -137,10 +137,20 @@ ensure_node_runtime() { install_with_manager "${manager}" node ;; apt-get) - install_with_manager "${manager}" nodejs npm + log "Adding NodeSource LTS repository..." + if ! curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -; then + echo "Failed to set up NodeSource repository for Node.js." >&2 + exit 1 + fi + install_with_manager "${manager}" nodejs ;; dnf|yum) - install_with_manager "${manager}" nodejs npm + log "Adding NodeSource LTS repository..." + if ! curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo -E bash -; then + echo "Failed to set up NodeSource repository for Node.js." >&2 + exit 1 + fi + install_with_manager "${manager}" nodejs ;; *) echo "No supported package manager available to install Node.js." >&2 @@ -154,8 +164,8 @@ ensure_node_runtime() { fi major="$(node_major)" - if [[ -z "${major}" || "${major}" -lt 18 ]]; then - echo "suitup requires Node.js 18 or later. Installed version is $(node -v)." >&2 + if [[ -z "${major}" || "${major}" -lt 20 ]]; then + echo "suitup requires Node.js 20 or later. Installed version is $(node -v)." >&2 exit 1 fi } @@ -177,7 +187,7 @@ require_cmd uname PACKAGE_MANAGER="$(detect_package_manager || true)" if [[ -z "${PACKAGE_MANAGER}" ]]; then - echo "Could not detect a supported package manager. Install zsh and Node.js 18+ manually, then rerun suitup." >&2 + echo "Could not detect a supported package manager. Install zsh and Node.js 20+ manually, then rerun suitup." >&2 exit 1 fi diff --git a/tests/install-script.test.js b/tests/install-script.test.js index 35eee5c..440b72f 100644 --- a/tests/install-script.test.js +++ b/tests/install-script.test.js @@ -47,4 +47,22 @@ describe("install.sh", () => { expect(content).toContain('Unknown command: ${CLI_COMMAND}'); }); + + test("skips Node.js installation when a compatible version is already present", () => { + const content = readFileSync(INSTALL_SCRIPT, "utf-8"); + + // ensure_node_runtime returns early when node + npm are found at version >= 20 + expect(content).toContain("if have_cmd node && have_cmd npm;"); + expect(content).toMatch(/"\$\{major\}" -ge 20/); + expect(content).toContain("return 0"); + }); + + test("uses NodeSource repository for reliable Node.js installation on Linux", () => { + const content = readFileSync(INSTALL_SCRIPT, "utf-8"); + + expect(content).toContain("https://deb.nodesource.com/setup_lts.x"); + expect(content).toContain("https://rpm.nodesource.com/setup_lts.x"); + // NodeSource setup scripts are piped into bash with sudo + expect(content).toMatch(/curl.*nodesource.*\| sudo -E bash -/s); + }); });