From 1f075a932b814bccc6b6cefdcfd62a76cc73d471 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 18 Mar 2026 05:14:37 +0000 Subject: [PATCH] Cache frontend build across setup runs Skip the frontend npm install + build if frontend/dist already exists. Previously setup.ps1 nuked node_modules and package-lock.json on every run, and both scripts always rebuilt even when dist/ was already present. On a git clone editable install, the first setup run still builds the frontend as before. Subsequent runs skip it, saving several minutes. To force a rebuild, delete frontend/dist and re-run setup. --- studio/setup.ps1 | 6 +++--- studio/setup.sh | 11 ++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/studio/setup.ps1 b/studio/setup.ps1 index 2420448deb..9f152aa477 100644 --- a/studio/setup.ps1 +++ b/studio/setup.ps1 @@ -748,8 +748,11 @@ Write-Host "" # ========================================================================== # PHASE 2: Frontend build (skip if pip-installed -- already bundled) # ========================================================================== +$DistDir = Join-Path $FrontendDir "dist" if ($IsPipInstall) { Write-Host "[OK] Running from pip install - frontend already bundled, skipping build" -ForegroundColor Green +} elseif (Test-Path $DistDir) { + Write-Host "[OK] Frontend already built (frontend/dist exists). To rebuild, delete frontend/dist and re-run setup." -ForegroundColor Green } else { Write-Host "" Write-Host "Building frontend..." -ForegroundColor Cyan @@ -758,9 +761,6 @@ if ($IsPipInstall) { $prevEAP_npm = $ErrorActionPreference $ErrorActionPreference = "Continue" Push-Location $FrontendDir - # Remove stale node_modules and package-lock.json to avoid version conflicts - if (Test-Path "node_modules") { Remove-Item -Recurse -Force "node_modules" } - if (Test-Path "package-lock.json") { Remove-Item -Force "package-lock.json" } npm install 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Pop-Location diff --git a/studio/setup.sh b/studio/setup.sh index 4c8a6c7dde..7070b8a089 100755 --- a/studio/setup.sh +++ b/studio/setup.sh @@ -41,13 +41,10 @@ if [[ "$keynames" == *$'\nCOLAB_'* ]]; then fi # ── Detect whether frontend needs building ── -# Only skip when BOTH conditions are true: -# 1. We're inside site-packages (PyPI / pip install, not editable) -# 2. dist/ already exists (pre-built in the wheel) -# Otherwise always (re)build — handles upgrades, editable installs, and -# pip-from-source where dist/ was never built. -if [[ "$SCRIPT_DIR" == */site-packages/* ]] && [ -d "$SCRIPT_DIR/frontend/dist" ]; then - echo "✅ Frontend pre-built (PyPI) — skipping Node/npm check." +# Skip frontend build if dist/ already exists (PyPI wheel, previous build, etc.) +# To force a rebuild, delete frontend/dist and re-run setup. +if [ -d "$SCRIPT_DIR/frontend/dist" ]; then + echo "✅ Frontend already built (frontend/dist exists) -- skipping Node/npm check." else NEED_NODE=true if command -v node &>/dev/null && command -v npm &>/dev/null; then