# If HOME is not writable (e.g. OrbStack containers where HOME is overridden to a
# root-owned path), point pnpm to the user's actual writable home directory.
# Also skip the build check — Next.js needs platform-specific SWC binaries that
# aren't installed in the container; CI catches build failures anyway.
if [ ! -w "$HOME" ]; then
  export PNPM_HOME="/home/$(id -un)/.local/share/pnpm"
  mkdir -p "$PNPM_HOME"
  echo "ℹ OrbStack detected — skipping pre-push build (CI will verify)"
  exit 0
fi

# Bring node_modules in sync with the lockfile before building. This is a no-op
# (<1s) when already consistent, and auto-heals stale installs after a branch
# switch or rebase — without that, the build fails on missing platform-specific
# native binaries (e.g. lightningcss-darwin-arm64) that the lockfile requires.
CI=true pnpm install --frozen-lockfile
pnpm build
