# Monorepo dev image: build context must be the repository root (see docker-compose.yml).
FROM node:22-alpine

# pnpm 9+ via Corepack (bundled with Node 22)
RUN corepack enable && corepack prepare pnpm@9.15.9 --activate

WORKDIR /app

# --- dependency layer: copy only manifests so `pnpm install` can be cached ---
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY apps/web/package.json ./apps/web/
COPY packages/shared-types/package.json ./packages/shared-types/
COPY packages/eslint-config/package.json ./packages/eslint-config/

# Workspace packages referenced by the lockfile (minimal source for install/link)
COPY packages/shared-types ./packages/shared-types/
COPY packages/eslint-config ./packages/eslint-config/

RUN pnpm install --frozen-lockfile

# App source baked into the image; at runtime bind-mount overrides for live-reload
COPY apps/web ./apps/web/

EXPOSE 5173

# Chokidar polling helps file watching on Docker Desktop (Windows/macOS bind mounts)
ENV CHOKIDAR_USEPOLLING=true
ENV WATCHPACK_POLLING=true

# `pnpm exec` runs vite directly in the web workspace (avoids `--` arg forwarding issues)
CMD ["pnpm", "--filter", "web", "exec", "vite", "--host", "0.0.0.0"]
