This is a pnpm monorepo containing multiple PostHog JavaScript SDKs and development tooling. The repository uses Turbo for build orchestration and supports local development through tarball-based testing.
Key Information:
- Node Version:
v22.17.1(see.nvmrc) - Package Manager:
pnpm@10.12.4 - TypeScript Version:
5.8.2 - Main Branch:
main
./packages- All JS SDKs that are distributed as npm packages./playground- Projects to test packages locally during development./examples- Simple example projects demonstrating how to install and use our SDKs./target- Generated tarballs for SDK packages (created bypnpm package)./tooling- Shared development packages (ESLint plugin, Rollup utils, TSConfig base)./.github- CI/CD workflows and custom GitHub Actions
The repository contains the following SDK packages in ./packages/:
| Package | Name | Description |
|---|---|---|
core/ |
@posthog/core |
Shared core functionality used by multiple SDKs |
browser/ |
posthog-js |
Main browser SDK for capturing events and usage |
web/ |
posthog-js-lite |
Lightweight browser SDK |
ai/ |
@posthog/ai |
AI integrations for Node.js |
convex/ |
@posthog/convex |
Convex.dev component |
node/ |
posthog-node |
Node.js backend SDK (requires Node >= 20) |
react/ |
@posthog/react |
React components and hooks |
react-native/ |
posthog-react-native |
React Native mobile SDK |
nuxt/ |
@posthog/nuxt |
Nuxt framework module |
next/ |
@posthog/next |
Next.js framework module |
nextjs-config/ |
@posthog/nextjs-config |
Next.js configuration helper |
types/ |
@posthog/types |
TypeScript type definitions for the SDK |
- This repository is structured as a pnpm workspace and each SDK and tooling package is a member of this global workspace.
- Example and playground projects are independent pnpm workspaces. You can install their dependencies by running
pnpm installinside the specific project folder. All dependencies and sub-dependencies to PostHog SDKs will be overwritten using a pnpmfile.
# Use the correct Node version
nvm use
# Install all workspace dependencies
pnpm installRun these from the repository root:
# Build all packages (respects dependency order)
pnpm build
# Watch mode for development
pnpm dev
# Run all tests across packages
pnpm test
# Run unit tests only
pnpm test:unit
# Lint all packages
pnpm lint
# Auto-fix linting issues
pnpm lint:fix
# Create tarballs for all packages
pnpm package
# Watch mode - auto-regenerate tarballs on changes
pnpm package:watch
# Generate API reference documentation
pnpm generate-references
# Clean all build artifacts
pnpm clean
# Clean all node_modules (workspace-wide)
pnpm clean:depAll SDK packages have the following scripts:
clean- Remove build artifactslint- Lint all files for this packagelint:fix- Fix linting issuesbuild- Transpile, minify and/or bundle source code from ./src to ./distdev- Build and watch for changestest:unit- Run unit teststest:functional- Run functional/integration tests (if applicable)package- Create a tarball of this package that can be installed inside an example or playground project
You can run commands using the turbo CLI and target specific packages. Useful examples:
# Create tarballs for all packages
pnpm turbo package
# Run unit tests for posthog-js only
pnpm turbo --filter=posthog-js test:unit
# Build posthog-react-native and its dependencies
pnpm turbo --filter=posthog-react-native build
# Lint a specific package
pnpm turbo --filter=@posthog/react lint:fixThe recommended workflow for testing local changes uses tarballs, which most realistically simulates how packages are installed from npm:
- Run
pnpm turbo packageinside the root folder to generate tarballs in./target - Navigate to the example/playground project:
cd examples/example-nextjs - Run
pnpm install(removepnpm-lock.yamlif it exists) to install local tarballs - you might need to point package.json at the tarball like
"posthog-js": "file:../../target/posthog-js.tgz", - Run
pnpm devorpnpm startto start the project
- Terminal 1 (root): Run
pnpm package:watch- auto-regenerates tarballs on changes - Terminal 2 (example project): Navigate to example folder
- Make changes to SDK source code - tarballs update automatically
- Re-run
pnpm installin the example project to pick up new tarballs - Restart the example project
Turbo handles build orchestration and ensures packages are built in the correct dependency order.
- Custom
eslint-plugin-posthog-jsfor repository-specific rules - TypeScript support
- React support
- Prettier integration
Pre-commit hooks (via lint-staged) automatically format code on commit:
- TypeScript/JavaScript files: ESLint + Prettier
- JSON/Markdown files: Prettier
This repository uses Changesets for version management and publishing.
Before submitting a PR with changes that should be released:
# Interactive CLI to create a changeset
pnpm changesetThis will:
- Prompt you to select which packages are affected
- Ask for the version bump type (major/minor/patch)
- Request a description of the change
- Create a file in
.changesets/directory
- Add the
releaselabel to your PR - When the PR is merged to
main, therelease.ymlGitHub Action will:- Update package versions
- Update CHANGELOG files
- Publish to npm
- Create GitHub releases
| Workflow | Purpose | Trigger |
|---|---|---|
library-ci.yml |
Main testing pipeline (unit + E2E tests) | PR + Push to main |
release.yml |
Publishes to npm and creates releases | Push to main |
integration.yml |
Playwright tests across browsers | PR |
lint-pr.yml |
Validates PR titles (Conventional Commits) | PR events |
es-check.yml |
Validates ES5/ES6 bundle compatibility | PR |
bundled-size.yaml |
Monitors bundle size changes | PR |
generate-references.yml |
Generates API documentation | Push to main |
- PR titles must follow Conventional Commits format
- Examples:
feat:,fix:,chore:,docs: - Validated by
lint-pr.ymlworkflow
package.json- Root workspace scripts and dependenciespnpm-workspace.yaml- Workspace definition and version catalogsturbo.json- Build orchestration and task caching.nvmrc- Node version specification.eslintrc.cjs- ESLint configuration.prettierrc- Code formatting rules
CONTRIBUTING.md- Contribution guidelinesAGENTS.md- This file - agent development guideRELEASING.md- Detailed release processREADME.md- Project overview
# Clean all build artifacts
pnpm clean
# Clean all node_modules
pnpm clean:dep
# Reinstall dependencies
pnpm install
# Rebuild everything
pnpm build# Regenerate all tarballs
pnpm package
# In example project, force reinstall
rm -rf node_modules pnpm-lock.yaml
pnpm install# Run tests with verbose output
pnpm turbo --filter=<package-name> test:unit -- --verbose
# Update snapshots if needed
pnpm turbo --filter=<package-name> test:unit -- -u