node version logic

This commit is contained in:
Mateusz Gruszczyński
2025-10-26 18:54:52 +01:00
parent e30d54dd92
commit 47439874ac

View File

@@ -381,17 +381,14 @@ def install_nodejs_from_distro():
if shutil.which("node"):
node_ver = run_out(["node", "--version"], check=False).strip()
if shutil.which("npm"):
npm_ver = run_out(["npm", "--version"], check=False).strip()
print(f" Node.js: {node_ver} (from distro)")
print(f" npm: {npm_ver}")
else:
print(f" Node.js: {node_ver} (from distro)")
print(f"⚠ npm not found, installing...")
print(f"Node.js: {node_ver}")
if not shutil.which("npm"):
apt_try_install(["npm"])
if shutil.which("npm"):
npm_ver = run_out(["npm", "--version"], check=False).strip()
print(f"npm {npm_ver} installed successfully")
print(f"npm: {npm_ver}")
return True
return False
@@ -463,6 +460,7 @@ def ensure_minimum_nodejs(min_version=MIN_NODEJS_VERSION, user_requested_version
if has_nodejs and major and major >= min_version:
print(f"✓ Distribution provides Node.js v{version_str} (>= v{min_version})")
print()
if install_nodejs_from_distro():
return True
else:
@@ -1394,9 +1392,11 @@ def install_node_from_nodesource(version: str):
print(f" npm: {npm_ver}")
else:
print(f"Node.js: {node_ver}")
print(f"npm not found, installing...")
apt_try_install(["npm"])
run(["apt-get", "install", "-y", "npm"], check=False)
if shutil.which("npm"):
npm_ver = run_out(["npm", "--version"], check=False).strip()
print(f"npm: {npm_ver}")
if not shutil.which("npm"):
run(["corepack", "enable"], check=False)