diff --git a/npm_install.py b/npm_install.py index 6732647..7650a85 100644 --- a/npm_install.py +++ b/npm_install.py @@ -8,8 +8,10 @@ DEBUG = False # ========== Configuration ========== -# Maximum supported Node.js version (can be updated in the future) -MAX_NODEJS_VERSION = 21 +# Minimum required Node.js version for NPM 2.12.6+ +MIN_NODEJS_VERSION = 18 +# Maximum supported Node.js version +MAX_NODEJS_VERSION = 21 # ========== UI / Spinner ========== @@ -255,6 +257,36 @@ def set_file_ownership(files: list[str | Path], owner: str, mode: int | None = N return len(failed) == 0 +def ensure_minimum_nodejs(min_version=MIN_NODEJS_VERSION): + try: + node_ver = runout(["node", "--version"], check=False).strip() + + match = re.match(r'v?(\d+)', node_ver) + if match: + current_major = int(match.group(1)) + if current_major >= min_version: + print(f"✓ Node.js {node_ver} is sufficient (>= v{min_version})") + return True + else: + print(f"✗ Node.js {node_ver} is too old (< v{min_version})") + else: + print(f"Cannot parse Node.js version: {node_ver}") + except FileNotFoundError: + print("Node.js not found") + except Exception as e: + print(f"Error checking Node.js version: {e}") + + print(f"Installing Node.js v{min_version} from NodeSource...") + install_node_from_nodesource(str(min_version)) + + try: + node_ver = runout(["node", "--version"], check=False).strip() + print(f"✓ Node.js {node_ver} installed successfully") + return True + except Exception as e: + print(f"Failed to verify Node.js installation: {e}") + return False + def download_extract_tar_gz(url: str, dest_dir: Path) -> Path: dest_dir.mkdir(parents=True, exist_ok=True) with step("Downloading and untaring"): @@ -1627,6 +1659,10 @@ def main(): setup_angie(ipv6_enabled=args.enable_ipv6) write_metrics_files() + + with step("Checking Node.js version requirements"): + ensure_minimum_nodejs() + install_node_and_yarn(node_pkg=args.nodejs_pkg, node_version=args.node_version) ensure_user_and_dirs() create_sudoers_for_npm()