diff --git a/reflex/utils/path_ops.py b/reflex/utils/path_ops.py index b447718d2..48ccd545a 100644 --- a/reflex/utils/path_ops.py +++ b/reflex/utils/path_ops.py @@ -9,7 +9,7 @@ import shutil from pathlib import Path from reflex import constants -from reflex.config import environment +from reflex.config import environment, get_config # Shorthand for join. join = os.linesep.join @@ -187,6 +187,19 @@ def get_npm_path() -> Path | 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]): """Update the contents of a json file. diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 94d8f8fbd..f829d6c4a 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -194,10 +194,13 @@ def get_bun_version() -> version.Version | None: Returns: The version of bun. """ + bun_path = path_ops.get_bun_path() + if bun_path is None: + return None try: # Run the bun -v command and capture the output - result = processes.new_process([str(get_config().bun_path), "-v"], run=True) - return version.parse(result.stdout) # type: ignore + result = processes.new_process([str(bun_path), "-v"], run=True) + return version.parse(str(result.stdout)) except FileNotFoundError: return None except version.InvalidVersion as e: