fix stuff with bun_path

This commit is contained in:
Lendemor 2025-01-24 17:51:38 +01:00
parent abc9038580
commit 869d3545e3
2 changed files with 19 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import shutil
from pathlib import Path from pathlib import Path
from reflex import constants from reflex import constants
from reflex.config import environment from reflex.config import environment, get_config
# Shorthand for join. # Shorthand for join.
join = os.linesep.join join = os.linesep.join
@ -187,6 +187,19 @@ def get_npm_path() -> Path | None:
return npm_path.absolute() if npm_path else None return npm_path.absolute() if npm_path else None
def get_bun_path() -> Path | None:
"""Get bun binary path.
Returns:
The path to the bun binary file.
"""
bun_path = get_config().bun_path
if use_system_bun() or not bun_path.exists():
system_bun_path = which("bun")
bun_path = Path(system_bun_path) if system_bun_path else None
return bun_path.absolute() if bun_path else None
def update_json_file(file_path: str | Path, update_dict: dict[str, int | str]): def update_json_file(file_path: str | Path, update_dict: dict[str, int | str]):
"""Update the contents of a json file. """Update the contents of a json file.

View File

@ -194,10 +194,13 @@ def get_bun_version() -> version.Version | None:
Returns: Returns:
The version of bun. The version of bun.
""" """
bun_path = path_ops.get_bun_path()
if bun_path is None:
return None
try: try:
# Run the bun -v command and capture the output # Run the bun -v command and capture the output
result = processes.new_process([str(get_config().bun_path), "-v"], run=True) result = processes.new_process([str(bun_path), "-v"], run=True)
return version.parse(result.stdout) # type: ignore return version.parse(str(result.stdout))
except FileNotFoundError: except FileNotFoundError:
return None return None
except version.InvalidVersion as e: except version.InvalidVersion as e: