Ver código fonte

run bun from cached path

Masen Furer 4 meses atrás
pai
commit
6c4a4a9e79
2 arquivos alterados com 31 adições e 21 exclusões
  1. 7 21
      reflex/utils/exec.py
  2. 24 0
      reflex/utils/prerequisites.py

+ 7 - 21
reflex/utils/exec.py

@@ -18,7 +18,7 @@ from reflex import constants
 from reflex.config import environment, get_config
 from reflex.constants.base import LogLevel
 from reflex.utils import console, path_ops
-from reflex.utils.prerequisites import get_web_dir
+from reflex.utils.prerequisites import get_package_list, get_web_dir
 
 # For uvicorn windows bug fix (#2335)
 frontend_process = None
@@ -85,14 +85,7 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True):
     console.print(
         f"DETECT_PACKAGE_CHANGE init {last_hash}, {json.dumps(json.loads(json_file_path.read_text()))}"
     )
-    last_packages = (
-        processes.new_process(
-            ["bun", "pm", "ls"],
-            cwd=get_web_dir(),
-        )
-        .stdout.read()
-        .strip()
-    )
+    last_packages = get_package_list()
     console.print(
         f"DETECT_PACKAGE_CHANGE init {last_packages}",
     )
@@ -145,20 +138,13 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True):
                             f"DETECT_PACKAGE_CHANGE hit {last_hash} != {new_hash} (new), {new_content}"
                         )
                         last_hash = new_hash
-                        new_packages = (
-                            processes.new_process(
-                                ["bun", "pm", "ls"],
-                                cwd=get_web_dir(),
-                            )
-                            .stdout.read()
-                            .strip()
-                        )
-                        console.print(
-                            f"DETECT_PACKAGE_CHANGE init {new_packages}",
-                        )
+                        new_packages = get_package_list()
                         if new_packages != last_packages:
-                            last_packages = new_packages
                             console.print("Reloading app due to new content...")
+                            console.print(
+                                f"DETECT_PACKAGE_CHANGE init {new_packages}",
+                            )
+                            last_packages = new_packages
                             kill(process.pid)
                             process = None
                             break  # for line in process.stdout

+ 24 - 0
reflex/utils/prerequisites.py

@@ -267,6 +267,30 @@ def windows_npm_escape_hatch() -> bool:
     return environment.REFLEX_USE_NPM.get()
 
 
+def get_package_list() -> str:
+    """Get the list of installed packages in the current environment.
+
+    Returns:
+        The list of user and framework installed packages.
+    """
+    package_manager = get_package_manager()
+    install_package_manager = get_install_package_manager()
+    if package_manager == install_package_manager:
+        # npm
+        cmd = [install_package_manager, "list"]
+    else:
+        # bun
+        cmd = [install_package_manager, "pm", "ls"]
+    return (
+        processes.new_process(
+            cmd,
+            cwd=get_web_dir(),
+        )
+        .stdout.read()
+        .strip()
+    )
+
+
 def get_app(reload: bool = False) -> ModuleType:
     """Get the app module based on the default config.