use npm prefer-offline flag to reduce reload time
This commit is contained in:
parent
42dbd4c959
commit
3be509975f
@ -201,6 +201,9 @@ class Config(Base):
|
|||||||
# The worker class used in production mode
|
# The worker class used in production mode
|
||||||
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
|
gunicorn_worker_class: str = "uvicorn.workers.UvicornH11Worker"
|
||||||
|
|
||||||
|
# npm prefer-offline flag to prefer local cache.
|
||||||
|
npm_prefer_offline: bool = False
|
||||||
|
|
||||||
# Attributes that were explicitly set by the user.
|
# Attributes that were explicitly set by the user.
|
||||||
_non_default_attributes: Set[str] = pydantic.PrivateAttr(set())
|
_non_default_attributes: Set[str] = pydantic.PrivateAttr(set())
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ class Config(Base):
|
|||||||
rxdeploy_url: Optional[str]
|
rxdeploy_url: Optional[str]
|
||||||
cp_backend_url: str
|
cp_backend_url: str
|
||||||
cp_web_url: str
|
cp_web_url: str
|
||||||
|
npm_prefer_offline: bool
|
||||||
username: Optional[str]
|
username: Optional[str]
|
||||||
gunicorn_worker_class: str
|
gunicorn_worker_class: str
|
||||||
|
|
||||||
@ -95,6 +96,7 @@ class Config(Base):
|
|||||||
rxdeploy_url: Optional[str] = None,
|
rxdeploy_url: Optional[str] = None,
|
||||||
cp_backend_url: Optional[str] = None,
|
cp_backend_url: Optional[str] = None,
|
||||||
cp_web_url: Optional[str] = None,
|
cp_web_url: Optional[str] = None,
|
||||||
|
npm_prefer_offline: bool=False,
|
||||||
username: Optional[str] = None,
|
username: Optional[str] = None,
|
||||||
gunicorn_worker_class: Optional[str] = None,
|
gunicorn_worker_class: Optional[str] = None,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
@ -505,22 +505,6 @@ def install_bun():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_packages_to_install(packages, npm_packages): # TODO: refactor
|
|
||||||
packages_to_install = []
|
|
||||||
for _i, package in enumerate(packages):
|
|
||||||
parts = [x for x in package.split("@") if x]
|
|
||||||
if (
|
|
||||||
len(parts) == 1
|
|
||||||
and package not in npm_packages
|
|
||||||
or len(parts) > 1
|
|
||||||
and parts[-1].startswith("^")
|
|
||||||
or len(parts) > 1
|
|
||||||
and package not in npm_packages
|
|
||||||
):
|
|
||||||
packages_to_install.append(package)
|
|
||||||
return packages_to_install
|
|
||||||
|
|
||||||
|
|
||||||
def install_frontend_packages(packages: set[str]):
|
def install_frontend_packages(packages: set[str]):
|
||||||
"""Installs the base and custom frontend packages.
|
"""Installs the base and custom frontend packages.
|
||||||
|
|
||||||
@ -530,58 +514,42 @@ def install_frontend_packages(packages: set[str]):
|
|||||||
Example:
|
Example:
|
||||||
>>> install_frontend_packages(["react", "react-dom"])
|
>>> install_frontend_packages(["react", "react-dom"])
|
||||||
"""
|
"""
|
||||||
|
config = get_config()
|
||||||
package_manager = get_install_package_manager()
|
package_manager = get_install_package_manager()
|
||||||
|
|
||||||
uses_npm = package_manager.endswith("npm")
|
uses_npm = package_manager.endswith("npm")
|
||||||
if uses_npm:
|
|
||||||
npm_packages = processes.new_process(
|
prefer_offline = (["--prefer-offline"] if config.npm_prefer_offline and uses_npm else [])
|
||||||
[package_manager, "ls"], run=True, cwd=constants.Dirs.WEB
|
|
||||||
).stdout.splitlines()
|
|
||||||
npm_packages = set(
|
|
||||||
[
|
|
||||||
package.split()[1]
|
|
||||||
for package in npm_packages[1:]
|
|
||||||
if package and "empty" not in package
|
|
||||||
]
|
|
||||||
)
|
|
||||||
# Install the base packages.
|
# Install the base packages.
|
||||||
process = processes.new_process(
|
process = processes.new_process(
|
||||||
[package_manager, "install", "--loglevel", "silly"],
|
[package_manager, "install", "--loglevel", "silly", *prefer_offline],
|
||||||
cwd=constants.Dirs.WEB,
|
cwd=constants.Dirs.WEB,
|
||||||
shell=constants.IS_WINDOWS,
|
shell=constants.IS_WINDOWS,
|
||||||
)
|
)
|
||||||
|
|
||||||
processes.show_status("Installing base frontend packages", process)
|
processes.show_status("Installing base frontend packages", process)
|
||||||
|
|
||||||
config = get_config()
|
|
||||||
if config.tailwind is not None:
|
if config.tailwind is not None:
|
||||||
tailwind_deps = (config.tailwind or {}).get("plugins", [])
|
process = processes.new_process(
|
||||||
if uses_npm:
|
[
|
||||||
tailwind_deps = get_packages_to_install(tailwind_deps, npm_packages)
|
package_manager,
|
||||||
# install tailwind and tailwind plugins as dev dependencies.
|
"add",
|
||||||
if tailwind_deps:
|
"-d",
|
||||||
process = processes.new_process(
|
*prefer_offline,
|
||||||
[
|
constants.Tailwind.VERSION,
|
||||||
package_manager,
|
*(config.tailwind or {}).get("plugins", []),
|
||||||
"add",
|
],
|
||||||
"-d",
|
cwd=constants.Dirs.WEB,
|
||||||
constants.Tailwind.VERSION,
|
shell=constants.IS_WINDOWS,
|
||||||
*tailwind_deps,
|
)
|
||||||
],
|
processes.show_status("Installing tailwind", process)
|
||||||
cwd=constants.Dirs.WEB,
|
|
||||||
shell=constants.IS_WINDOWS,
|
|
||||||
)
|
|
||||||
processes.show_status("Installing tailwind", process)
|
|
||||||
|
|
||||||
# Install custom packages defined in frontend_packages
|
|
||||||
if uses_npm:
|
|
||||||
packages = get_packages_to_install(packages, npm_packages)
|
|
||||||
|
|
||||||
if len(packages) > 0:
|
if len(packages) > 0:
|
||||||
process = processes.new_process(
|
process = processes.new_process(
|
||||||
[package_manager, "add", *packages],
|
[package_manager, "add", *packages, *prefer_offline],
|
||||||
cwd=constants.Dirs.WEB,
|
cwd=constants.Dirs.WEB,
|
||||||
shell=constants.IS_WINDOWS,
|
shell=constants.IS_WINDOWS,
|
||||||
show_logs=True,
|
|
||||||
)
|
)
|
||||||
processes.show_status(
|
processes.show_status(
|
||||||
"Installing frontend packages from config and components", process
|
"Installing frontend packages from config and components", process
|
||||||
@ -728,8 +696,8 @@ def check_schema_up_to_date():
|
|||||||
with model.Model.get_db_engine().connect() as connection:
|
with model.Model.get_db_engine().connect() as connection:
|
||||||
try:
|
try:
|
||||||
if model.Model.alembic_autogenerate(
|
if model.Model.alembic_autogenerate(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
write_migration_scripts=False,
|
write_migration_scripts=False,
|
||||||
):
|
):
|
||||||
console.error(
|
console.error(
|
||||||
"Detected database schema changes. Run [bold]reflex db makemigrations[/bold] "
|
"Detected database schema changes. Run [bold]reflex db makemigrations[/bold] "
|
||||||
|
Loading…
Reference in New Issue
Block a user