Skip to content

Commit 7a7ac59

Browse files
authored
chore: modernize toolchain to vite-plus + turbo and prune dead code (aidenybai#436)
1 parent bba4bbd commit 7a7ac59

59 files changed

Lines changed: 1621 additions & 19761 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/build-extension.yml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ jobs:
1919
fetch-depth: 0
2020
ref: main
2121

22+
- name: Setup PNPM
23+
uses: pnpm/action-setup@v4
24+
2225
- name: Setup Node.js
2326
uses: actions/setup-node@v4
2427
with:
25-
node-version: '20'
26-
27-
- name: Setup PNPM
28-
uses: pnpm/action-setup@v2
29-
with:
30-
version: 9.x
28+
node-version: '22'
29+
cache: 'pnpm'
3130

3231
- name: Install dependencies
3332
run: pnpm install

‎.github/workflows/pkg-pr-new.yaml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
node-version: [18]
15+
node-version: [22]
1616

1717
steps:
1818
- uses: actions/checkout@v4
1919

2020
- name: Install pnpm
2121
uses: pnpm/action-setup@v4
22-
with:
23-
version: 9.1.0
2422

2523
- name: Use Node.js ${{ matrix.node-version }}
2624
uses: actions/setup-node@v4

‎.gitignore‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ dist
77
build
88
!packages/extension/build/
99
playgrounds
10-
# SSL Certificates
11-
bin/certs/*.pem
12-
bin/certs/*.key
13-
.cursor
10+
# Turbo cache
11+
.turbo/
1412
# Playwright
1513
test-results/
1614
playwright-report/
15+
.cursor

‎.oxlintrc.json‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,92 @@
22

33
- MUST: Use TypeScript interfaces over types.
44
- MUST: Keep all types in the global scope.
5-
- MUST: Use arrow functions over function declarations
6-
- MUST: Never comment unless absolutely necessary.
7-
- If the code is a hack (like a setTimeout or potentially confusing code), it must be prefixed with // HACK: reason for hack
8-
- MUST: Use kebab-case for files
5+
- MUST: Use arrow functions over function declarations.
6+
- MUST: Default to NO comments. Only add a comment when the user explicitly asks, or when the "why" is truly non-obvious - browser quirks, platform bugs, performance tradeoffs, fragile internal patching, or counter-intuitive design decisions. Never add comments that restate what the code does or what a well-named function/variable already conveys. When in doubt, leave the comment out.
7+
- If a hack is required (like a `setTimeout` that hides a race), prefix with `// HACK: reason for hack`.
8+
- Do not delete descriptive comments >3 lines without confirming with the user.
9+
- MUST: Use kebab-case for files.
910
- MUST: Use descriptive names for variables (avoid shorthands, or 1-2 character names).
10-
- Example: for .map(), you can use `innerX` instead of `x`
11-
- Example: instead of `moved` use `didPositionChange`
11+
- Example: for `.map()`, use `innerNode` instead of `n`.
12+
- Example: instead of `moved` use `didPositionChange`.
1213
- MUST: Frequently re-evaluate and refactor variable names to be more accurate and descriptive.
13-
- MUST: Do not type cast ("as") unless absolutely necessary
14+
- MUST: Do not type cast (`as`) unless absolutely necessary.
1415
- MUST: Remove unused code and don't repeat yourself.
1516
- MUST: Always search the codebase, think of many solutions, then implement the most _elegant_ solution.
1617
- MUST: Put all magic numbers in `constants.ts` using `SCREAMING_SNAKE_CASE` with unit suffixes (`_MS`, `_PX`).
1718
- MUST: Put small, focused utility functions in `utils/` with one utility per file.
18-
- MUST: Use Boolean over !!.
19+
- MUST: Use `Boolean(x)` over `!!x`.
20+
21+
## Preact + @preact/signals Rules
22+
23+
React Scan's overlay UI runs as a Preact app mounted inside a Shadow DOM (see [`packages/scan/src/core/index.ts`](packages/scan/src/core/index.ts)). Reactivity is driven by `@preact/signals`, not React state.
24+
25+
### Signals
26+
27+
- MUST: Read signals via `.value` inside JSX/effects: `signalWidget.value` not `signalWidget()`.
28+
- MUST: Write signals atomically: `signalWidget.value = { ...signalWidget.value, dimensions: ... }`. One signal per logical slice.
29+
- MUST: Use `useSignal(initial)` for component-local reactive state, `useComputed(() => ...)` for derived values, `useSignalEffect(() => ...)` for subscriptions/DOM imperative work.
30+
- MUST: Wrap module-level signals exported from a tree-shaken bundle with `/* @__PURE__ */ signal(...)` so production builds can drop unused state.
31+
- SHOULD: Persist user-facing state via `readLocalStorage`/`saveLocalStorage` from [`~web/utils/helpers`](packages/scan/src/web/utils/helpers.ts) and seed the signal with the persisted value.
32+
- NEVER: Mirror one signal into another inside `useSignalEffect` - find the single source of truth (compute on read).
33+
34+
### Effects
35+
36+
Before reaching for `useEffect`/`useSignalEffect`, classify the work:
37+
38+
- MUST: Use `useComputed` when the result is pure derived state from other signals. If no external system is touched, it is not an effect.
39+
- MUST: Use event handlers and direct action calls when work happens because the user clicked, dragged, or navigated. Do not watch a flag in an effect to trigger imperative logic.
40+
- MUST: Use `useEffect(..., [])` (or `useSignalEffect` with no deps) for one-time mount/cleanup of subscriptions, timers, listeners, and `MutationObserver`s. Always return the cleanup.
41+
- MUST: Keep each effect single-purpose - one effect, one external bridge. Split mixed-responsibility effects.
42+
- NEVER: Use an effect just to copy one signal into another.
43+
- NEVER: Use an effect as an event bus (watching a trigger signal to run a command). Call the action directly from the event source.
44+
45+
### Props
46+
47+
- MUST: Access props via `props.title`, not destructuring, when the prop is read inside an event handler that fires later or inside an effect.
48+
- SHOULD: Destructure props at the top of the body for purely-rendered values (read once during render).
49+
- NEVER: Destructure a prop that is itself a signal-driven slice if you intend to re-read it after async work.
50+
51+
### JSX & DOM
52+
53+
- MUST: Use `className` (we render via Preact's React-compat JSX in [`tsconfig.json`](tsconfig.json) `jsxImportSource: preact`).
54+
- MUST: Combine static `className="btn"` with reactive `className={cn("btn", isActive.value && "active")}` via [`cn`](packages/scan/src/web/utils/helpers.ts).
55+
- MUST: Read refs in `useEffect` or via the callback ref pattern - DOM refs are populated after render.
56+
- MUST: Mount overlay UI under the existing shadow root from `initRootContainer()` in [`core/index.ts`](packages/scan/src/core/index.ts). Do not append directly to `document.body`.
57+
- SHOULD: Use `style={{ "--css-var": value }}` for dynamic CSS variables; class toggles for boolean states.
58+
- SHOULD: Type refs as `let element: HTMLElement | null = null` with a guard.
59+
60+
## Build & Toolchain
61+
62+
This is a pnpm 10 monorepo with `packages/*` (libraries, extension, website) and a top-level `kitchen-sink/` (Playwright target). The toolchain is [Vite+](https://viteplus.dev) (`vp lint`, `vp fmt`, `vp check`) and `turbo` for pipeline orchestration.
63+
64+
### Approved built dependencies
65+
66+
The root [`package.json`](package.json) declares `pnpm.onlyBuiltDependencies` for `@parcel/watcher`, `esbuild`, `sharp`, `spawn-sync`, `unrs-resolver`. Without this list, `pnpm install` skips their native build steps and downstream packages fail.
67+
68+
### Build before test
69+
70+
`pnpm build` must complete before `pnpm test`, `pnpm test:e2e`, or `pnpm lint`. After modifying source files, always rebuild before running tests. Turbo enforces this via `dependsOn: ["^build"]` in [`turbo.json`](turbo.json).
71+
72+
### Playwright
73+
74+
`pnpm test:e2e` runs Playwright against the `kitchen-sink` Vite dev server on port 5173 (auto-started by [`playwright.config.ts`](playwright.config.ts)). Chromium must be installed: `npx playwright install chromium --with-deps`.
75+
76+
### Key commands
77+
78+
| Task | Command |
79+
| -------------- | -------------------------------------------- |
80+
| Install | `pnpm install` |
81+
| Build | `pnpm build` |
82+
| Dev watch | `pnpm dev` (watches `react-scan` + kitchen-sink) |
83+
| Unit tests | `pnpm test` |
84+
| E2E tests | `pnpm test:e2e` |
85+
| Lint | `pnpm lint` (oxlint via vite-plus) |
86+
| Lint + fix | `pnpm lint:fix` |
87+
| Format | `pnpm format` (oxfmt via vite-plus) |
88+
| Format check | `pnpm format:check` |
89+
| Typecheck | `pnpm typecheck` |
90+
| Combined | `pnpm check` (lint + fmt check + typecheck) |
1991

2092
## Testing
2193

@@ -25,4 +97,6 @@ Run checks always before committing with:
2597
pnpm build
2698
pnpm lint
2799
pnpm format
100+
pnpm typecheck
101+
pnpm test:e2e
28102
```

‎BROWSER_EXTENSION_GUIDE.md‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎CONTRIBUTING.md‎

Lines changed: 78 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,105 @@
11
# Contributing to React Scan
22

3-
First off, thanks for taking the time to contribute! ❤️
4-
5-
## Table of Contents
6-
7-
- [Contributing to React Scan](#contributing-to-react-scan)
8-
- [Table of Contents](#table-of-contents)
9-
- [Project Structure](#project-structure)
10-
- [Development Setup](#development-setup)
11-
- [Contributing Guidelines](#contributing-guidelines)
12-
- [Commits](#commits)
13-
- [Pull Request Process](#pull-request-process)
14-
- [Development Workflow](#development-workflow)
15-
- [Getting Help](#getting-help)
3+
Thanks for your interest in contributing to React Scan! This document covers the project layout, dev setup, and the workflow for getting your change merged.
164

175
## Project Structure
186

19-
This is a monorepo containing several packages:
7+
This is a pnpm 10 monorepo orchestrated by [turbo](https://turbo.build) and built on [Vite+](https://viteplus.dev) (oxlint, oxfmt, tsdown).
8+
9+
```
10+
packages/
11+
├── scan/ # Core React Scan library + CLI
12+
├── extension/ # Browser extension (Chrome / Firefox / Brave)
13+
├── vite-plugin-react-scan/ # Vite plugin wrapper
14+
└── website/ # Marketing site (Next.js, react-scan.com)
2015
21-
- `packages/scan` - Core React Scan package
22-
- `packages/vite-plugin-react-scan` - Vite plugin for React Scan
23-
- `packages/extension` - VS Code extension
16+
kitchen-sink/ # Playwright target app (Vite, port 5173)
17+
e2e/ # Playwright specs
18+
docs/installation/ # Per-framework install guides
19+
```
2420

2521
## Development Setup
2622

27-
1. **Clone and Install**
28-
```bash
29-
git clone https://github.com/aidenybai/react-scan.git
30-
cd react-scan
31-
pnpm install
32-
```
23+
### Prerequisites
3324

34-
2. **Build all packages**
35-
```bash
36-
pnpm build
37-
```
25+
- Node.js >= 22
26+
- pnpm >= 10
3827

39-
3. **Testing React Scan**
40-
```bash
41-
cd packages/scan
42-
pnpm build:copy
43-
```
44-
- This will build the package and then copy it to your clipboard as an IIFE (immedietely invoked function expression). This will allow you to paste it into the browser console to test it on any website
28+
### Setup
4529

46-
https://github.com/user-attachments/assets/f279e664-479f-4e39-bff4-1bbfee30af22
30+
```bash
31+
git clone https://github.com/aidenybai/react-scan.git
32+
cd react-scan
33+
pnpm install
34+
pnpm build
35+
```
4736

48-
## Contributing Guidelines
37+
### Dev workflow
4938

50-
### Commits
39+
```bash
40+
pnpm dev # watches react-scan + kitchen-sink in parallel
41+
pnpm --filter react-scan build:copy # build and copy IIFE to clipboard for ad-hoc testing
42+
pnpm --filter @react-scan/extension dev # extension in Chrome
43+
pnpm --filter @react-scan/website dev # marketing site
44+
```
5145

52-
We use conventional commits to ensure consistent commit messages:
46+
## Code Style
5347

54-
- `feat:` New features
55-
- `fix:` Bug fixes
56-
- `docs:` Documentation changes
57-
- `chore:` Maintenance tasks
58-
- `test:` Adding or updating tests
59-
- `refactor:` Code changes that neither fix bugs nor add features
48+
We use [Vite+](https://viteplus.dev) which bundles oxlint and oxfmt. See [`AGENTS.md`](AGENTS.md) for the full rule set.
49+
50+
```bash
51+
pnpm lint # check
52+
pnpm lint:fix # auto-fix
53+
pnpm format # write
54+
pnpm format:check # verify
55+
pnpm check # lint + format:check + typecheck
56+
pnpm typecheck
57+
```
58+
59+
Highlights:
60+
61+
- TypeScript everywhere; avoid `any`.
62+
- Interfaces over types; kebab-case filenames.
63+
- Arrow functions over function declarations.
64+
- No comments unless the "why" is non-obvious. Hacks must be prefixed with `// HACK: …`.
65+
- Magic numbers in `constants.ts` with `_MS` / `_PX` unit suffixes.
66+
- One utility per file under `utils/`.
67+
68+
## Tests
6069

61-
Example: `fix(scan): fix a typo`
70+
```bash
71+
pnpm test # vitest in each package
72+
pnpm test:e2e # Playwright against kitchen-sink (auto-started on :5173)
73+
pnpm test:e2e:ui # Playwright UI mode
74+
```
6275

63-
### Pull Request Process
76+
## Pull Requests
6477

65-
1. Fork the repository
66-
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
67-
3. Commit your changes using conventional commits
68-
4. Push to your branch
69-
5. Open a Pull Request
70-
6. Ask for reviews (@pivanov, @RobPruzan are your friends in this journey)
78+
1. Fork and create a branch (`git checkout -b feat/your-feature`).
79+
2. Make your changes; run `pnpm check` and `pnpm test:e2e` before pushing.
80+
3. If your change affects a published package, add a changeset:
81+
```bash
82+
pnpm changeset
83+
```
84+
4. Open a PR against `main`. Tag [@aidenybai](https://github.com/aidenybai) for review.
7185

72-
### Development Workflow
86+
### Commit Convention
7387

74-
1. **TypeScript**
75-
- All code must be written in TypeScript
76-
- Ensure strict type checking passes
77-
- No `any` types unless absolutely necessary
88+
We use conventional commits:
7889

79-
2. **Code Style**
80-
- We use Biome for formatting and linting
81-
- Run `pnpm format` to format code
82-
- Run `pnpm lint` to check for issues
90+
- `feat:` New features
91+
- `fix:` Bug fixes
92+
- `docs:` Documentation
93+
- `chore:` Maintenance
94+
- `refactor:` Code changes that neither fix bugs nor add features
95+
- `test:` Tests
8396

84-
3. **Documentation**
85-
- Update relevant documentation
86-
- Add JSDoc comments for public APIs
87-
- Update README if needed
97+
Example: `fix(scan): handle null fiber in flash overlay`
8898

8999
## Getting Help
90-
- Check existing issues
91-
- Create a new issue
92100

93-
<br />
101+
- Check existing [issues](https://github.com/aidenybai/react-scan/issues)
102+
- Open a new issue with a minimal repro
103+
- Join our [Discord](https://discord.gg/KV3FhDq7FA)
94104

95-
⚛️ Happy coding! 🚀
105+
Happy contributing!

0 commit comments

Comments
 (0)