From f8169795f108794df1986d17fc0e7dd9bbf062bc Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Fri, 1 Nov 2024 15:28:11 -0700 Subject: [PATCH] handle installing frontend packages more gracefully --- reflex/utils/prerequisites.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 771245f76..0658d729e 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -930,15 +930,31 @@ def install_frontend_packages(packages: set[str], config: Config): """ # unsupported archs(arm and 32bit machines) will use npm anyway. so we dont have to run npm twice fallback_command = ( - get_package_manager() - if not constants.IS_WINDOWS - or constants.IS_WINDOWS - and is_windows_bun_supported() - and not windows_check_onedrive_in_path() + get_package_manager(on_failure_return_none=True) + if ( + not constants.IS_WINDOWS + or constants.IS_WINDOWS + and is_windows_bun_supported() + and not windows_check_onedrive_in_path() + ) else None ) + + install_package_manager = ( + get_install_package_manager(on_failure_return_none=True) or fallback_command + ) + + if install_package_manager is None: + raise FileNotFoundError( + "Could not find a package manager to install frontend packages. You may need to run `reflex init`." + ) + + fallback_command = ( + fallback_command if fallback_command is not install_package_manager else None + ) + processes.run_process_with_fallback( - [get_install_package_manager(), "install"], # type: ignore + [install_package_manager, "install"], # type: ignore fallback=fallback_command, analytics_enabled=True, show_status_message="Installing base frontend packages", @@ -949,7 +965,7 @@ def install_frontend_packages(packages: set[str], config: Config): if config.tailwind is not None: processes.run_process_with_fallback( [ - get_install_package_manager(), + install_package_manager, "add", "-d", constants.Tailwind.VERSION, @@ -965,7 +981,7 @@ def install_frontend_packages(packages: set[str], config: Config): # Install custom packages defined in frontend_packages if len(packages) > 0: processes.run_process_with_fallback( - [get_install_package_manager(), "add", *packages], + [install_package_manager, "add", *packages], fallback=fallback_command, analytics_enabled=True, show_status_message="Installing frontend packages from config and components",