From 03a92bc60e2c419f81409d913f45345a2eae8a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Tue, 5 Sep 2023 22:45:18 +0200 Subject: [PATCH] remove frontend_package option (#1700) --- reflex/app.py | 20 +++++++++++++++++--- reflex/config.py | 4 ++-- reflex/utils/prerequisites.py | 17 ++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/reflex/app.py b/reflex/app.py index 8bbda6b6f..84b0227be 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -493,7 +493,7 @@ class App(Base): Example: >>> get_frontend_packages({"react": "16.14.0", "react-dom": "16.14.0"}) """ - page_imports = [ + page_imports = { i for i in imports if i not in compiler.DEFAULT_IMPORTS.keys() @@ -501,8 +501,22 @@ class App(Base): and "next" not in i and not i.startswith("/") and i != "" - ] - page_imports.extend(get_config().frontend_packages) + } + frontend_packages = get_config().frontend_packages + _frontend_packages = [] + for package in frontend_packages: + if package in get_config().tailwind.get("plugins", []): # type: ignore + console.warn( + f"Tailwind packages are inferred from 'plugins', remove `{package}` from `frontend_packages`" + ) + continue + if package in page_imports: + console.warn( + f"React packages and their dependencies are inferred from Component.library and Component.lib_dependencies, remove `{package}` from `frontend_packages`" + ) + continue + _frontend_packages.append(package) + page_imports.update(_frontend_packages) prerequisites.install_frontend_packages(page_imports) def compile(self): diff --git a/reflex/config.py b/reflex/config.py index 517557313..397dea107 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -180,10 +180,10 @@ class Config(Base): # The event namespace for ws connection event_namespace: Optional[str] = None - # Params to remove eventually. - # Additional frontend packages to install. (TODO: these can be inferred from the imports) + # Additional frontend packages to install. frontend_packages: List[str] = [] + # Params to remove eventually. # For rest are for deploy only. # The rxdeploy url. rxdeploy_url: Optional[str] = None diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index bb3e978d5..54999d84b 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -406,7 +406,7 @@ def install_bun(): ) -def install_frontend_packages(packages: list[str]): +def install_frontend_packages(packages: set[str]): """Installs the base and custom frontend packages. Args: @@ -424,14 +424,25 @@ def install_frontend_packages(packages: list[str]): processes.show_status("Installing base frontend packages", process) - # Install the custom packages, if any. + config = get_config() + if config.tailwind is not None and "plugins" in config.tailwind: + process = processes.new_process( + [get_install_package_manager(), "add", *config.tailwind["plugins"]], + cwd=constants.WEB_DIR, + shell=constants.IS_WINDOWS, + ) + processes.show_status("Installing tailwind packages", process) + + # Install custom packages defined in frontend_packages if len(packages) > 0: process = processes.new_process( [get_install_package_manager(), "add", *packages], cwd=constants.WEB_DIR, shell=constants.IS_WINDOWS, ) - processes.show_status("Installing frontend packages for components", process) + processes.show_status( + "Installing frontend packages from config and components", process + ) def check_initialized(frontend: bool = True):