From bdf576126df485a708b020662f56a573ef8744f4 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Thu, 25 Jun 2026 23:09:21 -0700 Subject: [PATCH] [eric] apps: link node_modules on import so imported backend apps boot first time, no restart --- backend/apps/outputs/view_builder_templates.py | 4 ++-- backend/apps/swarm/entities/apps.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/apps/outputs/view_builder_templates.py b/backend/apps/outputs/view_builder_templates.py index 24363fa2..0a357a60 100644 --- a/backend/apps/outputs/view_builder_templates.py +++ b/backend/apps/outputs/view_builder_templates.py @@ -374,7 +374,7 @@ def p_try_link_dir(src: str, target: str) -> bool: return False -def p_link_node_modules(workspace_dir: str) -> None: +def link_node_modules(workspace_dir: str) -> None: """After copytree, point the workspace's frontend/node_modules at the warm-cache directory. Safe fallback; if the cache isn't ready, the workspace's run.sh will fall through to its own install path.""" @@ -570,7 +570,7 @@ def seed_webapp_template_workspace(workspace_dir: str, frontend_port: int) -> No dirs_exist_ok=True, ) # Symlink the workspace's frontend/node_modules at the warm cache so `npm install` can be skipped entirely by the workspace run.sh. - p_link_node_modules(workspace_dir) + link_node_modules(workspace_dir) env_path = os.path.join(workspace_dir, ".env") env_example_path = os.path.join(workspace_dir, ".env.example") src_example = os.path.join(WEBAPP_TEMPLATE_DIR, ".env.example") diff --git a/backend/apps/swarm/entities/apps.py b/backend/apps/swarm/entities/apps.py index 21c09357..37cbb0ad 100644 --- a/backend/apps/swarm/entities/apps.py +++ b/backend/apps/swarm/entities/apps.py @@ -146,6 +146,7 @@ def p_localize_env(folder: str) -> None: from backend.apps.outputs.view_builder_templates import ( DEBUGGER_PATH, TEMPLATE_BACKEND_PATH, + link_node_modules, patch_env_port, warm_venv_dir, ) @@ -158,3 +159,8 @@ def p_localize_env(folder: str) -> None: patch_env_port(env_path, "OPENSWARM_BACKEND_VENV_CACHE", warm_venv_dir()) except Exception: pass + # Imported apps arrive WITHOUT node_modules (export drops the warm-cache symlink), so relink it here like seed does; without it the first runtime boot npm-installs while the preview races onto a not-yet-bound port, so the app stays blank until a full restart. + try: + link_node_modules(folder) + except Exception: + pass