Use project-local Node.js runtime

This commit is contained in:
2026-11-18 19:30:08 +03:00
parent e01fdc475f
commit 6a9b15c217
8 changed files with 273 additions and 89 deletions
+14 -8
View File
@@ -21,6 +21,7 @@ if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from tileserver_config import load_tileserver_config
from runtime_paths import get_node_path, get_runtime_env
TILESERVER_CONFIG_DATA = load_tileserver_config(PROJECT_ROOT)
@@ -129,12 +130,12 @@ def start_tileserver():
"Чужой процесс не будет остановлен."
)
node = shutil.which("node")
if node is None:
try:
node = str(get_node_path())
except FileNotFoundError as error:
raise LifecycleError(
"Node.js не найден в PATH."
)
"Локальный Node.js не найден."
) from error
if not TILESERVER_ENTRY.is_file():
raise LifecycleError(
@@ -165,7 +166,8 @@ def start_tileserver():
process = subprocess.Popen(
command,
cwd=TILESERVER_DIR,
stdin=subprocess.DEVNULL
stdin=subprocess.DEVNULL,
env=get_runtime_env()
)
deadline = time.monotonic() + STARTUP_TIMEOUT
@@ -873,8 +875,12 @@ def install():
if shutil.which("sudo") is None:
raise LifecycleError("Не найден sudo.")
if shutil.which("node") is None:
raise LifecycleError("Не найден Node.js.")
try:
get_node_path()
except FileNotFoundError as error:
raise LifecycleError(
"Локальный Node.js не найден."
) from error
if not TILESERVER_ENTRY.is_file():
raise LifecycleError(
+42
View File
@@ -0,0 +1,42 @@
import os
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent.parent
NODE_BIN_DIR = PROJECT_ROOT / "runtime" / "node" / "bin"
def _runtime_executable(name):
executable = NODE_BIN_DIR / name
if not executable.is_file() or not os.access(executable, os.X_OK):
raise FileNotFoundError(
f"Локальный исполняемый файл {name} не найден: {executable}"
)
return executable
def get_node_path():
return _runtime_executable("node")
def get_npm_path():
return _runtime_executable("npm")
def get_npx_path():
return _runtime_executable("npx")
def get_runtime_env():
environment = os.environ.copy()
current_path = environment.get("PATH", "")
environment["PATH"] = (
f"{NODE_BIN_DIR}{os.pathsep}{current_path}"
if current_path
else str(NODE_BIN_DIR)
)
return environment