fix bun path handling and add a test

This commit is contained in:
Lendemor 2025-02-10 15:45:01 +01:00
parent 6f4d328cde
commit 083417608b
3 changed files with 34 additions and 1 deletions

View File

@ -260,3 +260,19 @@ def find_replace(directory: str | Path, find: str, replace: str):
text = filepath.read_text(encoding="utf-8")
text = re.sub(find, replace, text)
filepath.write_text(text, encoding="utf-8")
def samefile(file1: Path, file2: Path) -> bool:
"""Check if two files are the same.
Args:
file1: The first file.
file2: The second file.
Returns:
Whether the files are the same. If either file does not exist, returns False.
"""
if file1.exists() and file2.exists():
return file1.samefile(file2)
return False

View File

@ -1293,7 +1293,13 @@ def validate_bun():
"""
bun_path = path_ops.get_bun_path()
if bun_path and not bun_path.samefile(constants.Bun.DEFAULT_PATH):
if bun_path is None:
console.error(
"Could not find bun. Make sure you have bun installed or run `reflex init` to install it."
)
raise typer.Exit(1)
if not path_ops.samefile(bun_path, constants.Bun.DEFAULT_PATH):
console.info(f"Using custom Bun path: {bun_path}")
bun_version = get_bun_version()
if not bun_version:

View File

@ -115,6 +115,17 @@ def test_typehint_issubclass(subclass, superclass, expected):
assert types.typehint_issubclass(subclass, superclass) == expected
def test_validate_none_bun_path(mocker):
"""Test that an error is thrown when a bun path is not specified.
Args:
mocker: Pytest mocker object.
"""
mocker.patch("reflex.utils.path_ops.get_bun_path", return_value=None)
with pytest.raises(typer.Exit):
prerequisites.validate_bun()
def test_validate_invalid_bun_path(mocker):
"""Test that an error is thrown when a custom specified bun path is not valid
or does not exist.