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"): if shutil.which("node"):
node_ver = run_out(["node", "--version"], check=False).strip() node_ver = run_out(["node", "--version"], check=False).strip()
print(f"Node.js: {node_ver}")
if not shutil.which("npm"):
apt_try_install(["npm"])
if shutil.which("npm"): if shutil.which("npm"):
npm_ver = run_out(["npm", "--version"], check=False).strip() npm_ver = run_out(["npm", "--version"], check=False).strip()
print(f" Node.js: {node_ver} (from distro)") print(f"npm: {npm_ver}")
print(f" npm: {npm_ver}")
else:
print(f" Node.js: {node_ver} (from distro)")
print(f"⚠ npm not found, installing...")
apt_try_install(["npm"])
if shutil.which("npm"):
npm_ver = run_out(["npm", "--version"], check=False).strip()
print(f"✔ npm {npm_ver} installed successfully")
return True return True
return False 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: if has_nodejs and major and major >= min_version:
print(f"✓ Distribution provides Node.js v{version_str} (>= v{min_version})") print(f"✓ Distribution provides Node.js v{version_str} (>= v{min_version})")
print()
if install_nodejs_from_distro(): if install_nodejs_from_distro():
return True return True
else: else:
@@ -1393,10 +1391,12 @@ def install_node_from_nodesource(version: str):
print(f" Node.js: {node_ver}") print(f" Node.js: {node_ver}")
print(f" npm: {npm_ver}") print(f" npm: {npm_ver}")
else: else:
print(f" Node.js: {node_ver}") 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"): if not shutil.which("npm"):
run(["corepack", "enable"], check=False) run(["corepack", "enable"], check=False)