Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/install-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Loading