Expose Node to npm lifecycle scripts

This commit is contained in:
王鹏
2026-10-09 13:03:55 +08:00
parent a94193d684
commit e5e584eb73
3 changed files with 21 additions and 1 deletions

View File

@@ -831,12 +831,14 @@ def _run_process(
input_file = _open_utf8_sql_input(input_path, on_output) if input_path else None
try:
process_environment = _build_process_environment(command)
process = subprocess.Popen(
command,
cwd=cwd,
stdin=input_file,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=process_environment,
shell=False,
)
assert process.stdout is not None
@@ -848,6 +850,18 @@ def _run_process(
input_file.close()
def _build_process_environment(command: list[str]) -> dict[str, str]:
environment = os.environ.copy()
executable = Path(command[0]) if command else None
if executable and executable.parent != Path("."):
executable_dir = str(executable.parent)
current_path = environment.get("PATH", "")
environment["PATH"] = os.pathsep.join(
part for part in (executable_dir, current_path) if part
)
return environment
def _decode_process_output(value: bytes | str) -> str:
if isinstance(value, str):
return value