Skip to content

Commit f8a81d0

Browse files
authored
Merge pull request #171 from mi-examples/pp-3449-nextjs-dev-panel
feat(next): dev panel and template sync for Next.js apps
2 parents b00915c + 4c78f13 commit f8a81d0

25 files changed

Lines changed: 10264 additions & 9981 deletions

.claude/commands/audit.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Run the full repo-wide npm audit and fix all vulnerabilities.
2+
3+
## Steps
4+
5+
1. Run `npm run audit:all` from the repo root to see the current state across all packages (root + every `tests/*` fixture).
6+
2. For each package with vulnerabilities:
7+
a. Run `npm audit fix` in that package directory.
8+
b. If issues remain ("No fix available"), add or update `overrides` in that package's `package.json` to force the patched version, then run `npm install` there.
9+
3. Run `npm run audit:all` again to confirm all packages report 0 vulnerabilities.
10+
4. If root `package-lock.json` changed, commit it: `chore(deps): fix npm audit vulnerabilities`.
11+
5. If test-fixture `package.json` or `package-lock.json` changed:
12+
- Run `npm run build` in the root to rebuild the `.tgz`.
13+
- Run `npm run reinstall` in each affected fixture.
14+
- Run `npm run audit:all` one final time.
15+
- Commit: `chore(deps): fix audit vulnerabilities in test fixtures`.
16+
17+
## Key rule
18+
19+
Never use bare `npm audit`. Always `npm run audit:all` — it covers root AND all `tests/*` packages.

.claude/commands/reinstall.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Rebuild the pp-dev package and reinstall it in all test fixtures.
2+
3+
## When to use
4+
5+
After changing source files in the root package that test fixtures depend on, or after bumping the root package version.
6+
7+
## Steps
8+
9+
1. From the repo root, run:
10+
```bash
11+
npm run reinstall:all
12+
```
13+
This runs `npm run build` first (via `prereinstall:all`) and then reinstalls the fresh `.tgz` in all test fixtures.
14+
2. Run `npm run audit:all` to confirm 0 vulnerabilities across all packages.
15+
3. Run `npm run test` to confirm nothing broke.

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# pp-dev — Claude Code Instructions
2+
3+
## What this project is
4+
5+
`@metricinsights/pp-dev` is a Vite/Next.js-based **local development framework and build tool** for Metric Insights' Portal Pages. It:
6+
- Proxies API requests to a live MI instance
7+
- Injects a **dev panel** (minimize, template sync) into the served page
8+
- Synchronizes the built template back to MI via WebSocket-triggered `next build` / Vite build
9+
10+
## Essential commands
11+
12+
```bash
13+
npm run build # Build node + client bundles; also packs a .tgz
14+
npm run test # Unit + integration (vitest)
15+
npm run test:unit # Unit tests only
16+
npm run test:integration # Integration tests (forked processes)
17+
npm run audit:all # npm audit in root AND every tests/* package — always use this, never bare npm audit
18+
```
19+
20+
## After any dependency change
21+
22+
Always verify with the **repo-wide audit**, not just root:
23+
```bash
24+
npm run audit:all
25+
```
26+
This runs `npm audit` in root + `tests/test-commonjs`, `tests/test-nextjs`, `tests/test-nextjs-cjs`. All must exit 0.
27+
28+
If test-fixture lockfiles need patching, add/update `overrides` in their `package.json` and run `npm install` there.
29+
30+
## After changing root package source
31+
32+
```bash
33+
npm run reinstall:all # builds dist/ + .tgz, then reinstalls in all test fixtures
34+
```
35+
36+
## Architecture overview
37+
38+
```
39+
src/cli.ts — 8 CLI commands: serve (default), next, build, changelog, …
40+
src/index.ts — withPPDev() Vite config builder; loads pp-dev.config.*
41+
src/plugin.ts — Vite plugin interface (re-exported)
42+
src/lib/
43+
client.service.ts — WebSocket event handler (info-data, template:sync, …)
44+
dist.service.ts — Build artifact manager: backups, VERSION, BUILD-MANIFEST, zip
45+
dev-panel.ts — EJS panel injection + static asset middleware
46+
pp-ws-server.ts — Raw ws server for Next.js (Vite-WS-compatible facade)
47+
version-manifest.ts — VERSION file + BUILD-MANIFEST generation (shared)
48+
middleware/ — Request pipeline: redirect → proxy cache → load-pp-data → proxy-pass → rewrite-response
49+
src/plugins/
50+
client-injection-plugin.ts — Vite transformIndexHtml: injects panel markup
51+
version-plugin.ts — Vite build hook: writes VERSION into dist
52+
src/client/
53+
index.ts — Browser-side dev panel (sync button, minimize)
54+
hot-context.ts — import.meta.hot shim for Next.js WS transport
55+
```
56+
57+
**WebSocket transport:** Vite dev server uses Vite HMR WS. Next.js uses `PPDevHotServer` (raw `ws`, path `/@pp-dev-hmr`). The client picks whichever is available: `import.meta.hot ?? createPPDevHotContext()`.
58+
59+
## Test structure
60+
61+
| Suite | Config | Pool | Timeout | Location |
62+
|---|---|---|---|---|
63+
| Unit | `vitest.config.ts` | threads | 10 s | `tests/unit/**/*.spec.ts` |
64+
| Integration | `vitest.integration.config.ts` | forks | 30 s | `tests/integration/**/*.spec.ts` |
65+
| E2E | `playwright.config.ts` | browser || `e2e/` |
66+
67+
Test fixtures (real apps installed with the local .tgz):
68+
- `tests/test-nextjs/` — ESM Next.js app
69+
- `tests/test-nextjs-cjs/` — CJS Next.js app
70+
- `tests/test-commonjs/` — CommonJS Vite app
71+
72+
## Key conventions
73+
74+
- **Dual ESM/CJS output** — Rollup builds `dist/esm/`, `dist/cjs/`, `dist/types/` from 4 entry points.
75+
- **Config caching**`src/config.ts` caches loaded config (30 s) and `package.json` (60 s).
76+
- **Lazy heavy imports**`esbuild`, `jsdom`, `sharp` are imported lazily to keep startup fast.
77+
- **Axios instance cache** — one Axios instance per base URL; `keepAlive: false` avoids max-listeners warnings.
78+
- **No bare `npm audit`** — always `npm run audit:all` so test fixtures are included.
79+
80+
## PR message format
81+
82+
See `.cursor/rules/pr-message-format.mdc`. Use emojis: 🚀 features, 🔧 fixes, 🔐 security, 🧪 tests, 🧹 chore.

0 commit comments

Comments
 (0)