Skip to content

Commit f51cc93

Browse files
authored
chore: Add contributing guide, PR template and improve post-install (#1270)
1 parent 49c0b50 commit f51cc93

File tree

6 files changed

+131
-7
lines changed

6 files changed

+131
-7
lines changed

.github/pull_request_template.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Problem
2+
3+
<!-- Who is this for and what problem does it solve? -->
4+
5+
<!-- Closes #ISSUE_ID -->
6+
7+
## Changes
8+
9+
<!-- What did you change and why? -->
10+
<!-- If there are frontend changes, include screenshots. -->
11+
12+
## How did you test this?
13+
14+
<!-- Describe what you tested -- manual steps, automated tests, or both. -->
15+
<!-- If you're an agent, only list tests you actually ran. -->

CONTRIBUTING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contributing to PostHog Code
2+
3+
We love contributions big and small. PostHog Code is the IDE for understanding how users interact with your product -- and we want the community involved in shaping it.
4+
5+
## Getting started
6+
7+
1. Fork the repo and clone it locally
8+
2. Follow the [Development setup](#development-setup) below
9+
3. Create a branch (`feat/my-change`, `fix/that-bug`)
10+
4. Make your changes and open a pull request
11+
12+
We recommend creating an issue first if one doesn't already exist so we can align on the approach before you invest time.
13+
14+
## Development setup
15+
16+
```bash
17+
# Prerequisites: Node.js 22+, pnpm 10.23+
18+
pnpm install
19+
cp .env.example .env
20+
pnpm dev
21+
```
22+
23+
See [docs/LOCAL-DEVELOPMENT.md](./docs/LOCAL-DEVELOPMENT.md) for connecting to a local PostHog instance.
24+
25+
## Before submitting
26+
27+
- Run `pnpm typecheck`, `pnpm lint` and `pnpm test` locally
28+
- Resolve merge conflicts before requesting review
29+
- Keep changes focused -- one logical change per PR
30+
- Add tests where they meaningfully improve confidence
31+
- Follow existing patterns and conventions in the areas you touch (see [CLAUDE.md](./CLAUDE.md) for code style details)
32+
33+
## What to expect
34+
35+
- PRs are triaged and assigned to the relevant team
36+
- Expect acknowledgement within a few days. Thorough reviews may take longer depending on load
37+
- We sometimes close PRs that are out of scope or would add long-term maintenance burden. You're always welcome to reopen with updates
38+
39+
## Issues
40+
41+
Spotted a bug? Something broken? [Raise an issue](https://github.com/PostHog/code/issues/new) for the fastest response.
42+
43+
## Feature requests
44+
45+
Raise an issue and tag it as an enhancement. Give us as much context on the _why_ as possible -- we love hearing about the problem you're trying to solve.
46+
47+
If you're unsure whether something fits, open an issue first and we'll get back to you quickly.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,15 @@ posthog-code/
9292
| [apps/mobile/README.md](./apps/mobile/README.md) | Mobile app: Expo setup, EAS builds, and TestFlight deployment |
9393
| [apps/cli/README.md](./apps/cli/README.md) | CLI: stacked PR management with Jujutsu |
9494
| [CLAUDE.md](./CLAUDE.md) | Code style, patterns, and testing guidelines |
95+
| [CONTRIBUTING.md](./CONTRIBUTING.md) | How to contribute to PostHog Code |
9596
| [docs/LOCAL-DEVELOPMENT.md](./docs/LOCAL-DEVELOPMENT.md) | Connecting PostHog Code to a local PostHog instance |
9697
| [docs/UPDATES.md](./docs/UPDATES.md) | Release versioning and git tagging |
9798
| [docs/TROUBLESHOOTING.md](./docs/TROUBLESHOOTING.md) | Common issues and fixes |
9899

100+
## Contributing
101+
102+
We love contributions big and small. See [CONTRIBUTING.md](./CONTRIBUTING.md) to get started.
103+
99104
## Troubleshooting
100105

101106
See [docs/TROUBLESHOOTING.md](./docs/TROUBLESHOOTING.md) for common issues (black screen, Electron install failures, native module crashes, etc.).

apps/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test": "vitest run",
2626
"test:e2e": "playwright test --config=tests/e2e/playwright.config.ts",
2727
"test:e2e:headed": "playwright test --config=tests/e2e/playwright.config.ts --headed",
28-
"postinstall": "cd ../.. && npx @electron/rebuild -f -m node_modules/node-pty && npx @electron/rebuild -f -m node_modules/better-sqlite3 || true && bash apps/code/scripts/patch-electron-name.sh && node apps/code/scripts/download-binaries.mjs",
28+
"postinstall": "bash scripts/postinstall.sh",
2929
"storybook": "storybook dev -p 6006",
3030
"build-storybook": "storybook build",
3131
"clean": "rm -rf .vite .turbo out node_modules/.vite",

apps/code/scripts/postinstall.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Postinstall script for the Electron app
4+
# Rebuilds native modules against Electron's Node headers and applies patches
5+
6+
set -e
7+
8+
REPO_ROOT="$(cd ../.. && pwd)"
9+
SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd)"
10+
11+
echo "Rebuilding native modules for Electron..."
12+
13+
cd "$REPO_ROOT"
14+
npx @electron/rebuild -f -m node_modules/node-pty
15+
npx @electron/rebuild -f -m node_modules/better-sqlite3 || true
16+
17+
echo "Patching Electron app name..."
18+
bash "$SCRIPTS_DIR/patch-electron-name.sh"
19+
20+
echo "Downloading binaries..."
21+
node "$SCRIPTS_DIR/download-binaries.mjs"
22+
23+
echo "Postinstall complete."

docs/TROUBLESHOOTING.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ If the app crashes with something like:
4545
libc++abi: terminating due to uncaught exception of type Napi::Error
4646
```
4747

48-
Native modules (like node-pty) need to be rebuilt for your Electron version:
48+
Native modules (like node-pty) need to be rebuilt for your Electron version.
49+
50+
### Fix
4951

5052
```bash
51-
pnpm --filter code exec electron-rebuild
53+
cd apps/code && npx electron-rebuild -f
5254
```
5355

5456
## Codex agent crashes with GPU process errors
@@ -70,24 +72,56 @@ node apps/code/scripts/download-binaries.mjs
7072

7173
Then restart the app. This downloads the codex-acp binary to `apps/code/resources/codex-acp/`, which gets copied to `.vite/build/codex-acp/` during build.
7274

73-
## Database initialization failed (better-sqlite3 bindings not found)
75+
## Database initialization failed (better-sqlite3)
7476

75-
If you see this error on startup:
77+
If you see either of these errors on startup:
7678

7779
```
7880
Database initialization failed Error: Could not locate the bindings file.
7981
```
8082

81-
The `better-sqlite3` native binary wasn't compiled for your Electron version. This commonly happens after a merge, branch switch or fresh install because the postinstall rebuild can fail silently (`|| true`).
83+
```
84+
Database initialization failed Error: The module '.../better_sqlite3.node'
85+
was compiled against a different Node.js version using
86+
NODE_MODULE_VERSION 145. This version of Node.js requires
87+
NODE_MODULE_VERSION 123.
88+
```
89+
90+
The `better-sqlite3` native binary wasn't compiled for your Electron version. This commonly happens after a merge, branch switch or Electron upgrade because the postinstall rebuild can fail silently (`|| true`).
8291

8392
### Fix
8493

8594
```bash
86-
npx @electron/rebuild -f -m node_modules/better-sqlite3
95+
cd apps/code && npx electron-rebuild -f
8796
```
8897

8998
Then restart the app.
9099

100+
## node-gyp failed to rebuild @parcel/watcher
101+
102+
If you see this error after pulling or switching branches:
103+
104+
```
105+
Error: node-gyp failed to rebuild '/path/to/node_modules/@parcel/watcher'
106+
```
107+
108+
`@parcel/watcher` ships prebuilt N-API binaries per platform (e.g. `@parcel/watcher-darwin-arm64`) and should not need recompilation. This error usually means a stale or partial install state is triggering a source rebuild that fails.
109+
110+
### Fix
111+
112+
```bash
113+
rm -rf node_modules/@parcel/watcher
114+
pnpm install
115+
```
116+
117+
If that doesn't work, nuke and reinstall:
118+
119+
```bash
120+
rm -rf node_modules && pnpm install
121+
```
122+
123+
Do **not** run `npx @electron/rebuild` against `@parcel/watcher` — it doesn't need it and the rebuild will fail.
124+
91125
## `pnpm i` shows "Packages: -198"
92126

93127
You might see something like this every time you run `pnpm install`:

0 commit comments

Comments
 (0)