This guide covers how to set up your development environment and contribute to @fairgarden/docs.
npm install -g pnpm@11.9.0)# Clone the repository
git clone https://github.com/fairgarden/docs.git
cd docs
# Install dependencies
pnpm install --no-frozen-lockfile
# Build all packages
pnpm release:build
# Start dev server
pnpm docs:dev
| Command | Description |
|---|---|
pnpm docs:dev | Start docs dev server |
pnpm docs:build | Build docs site |
pnpm docs:validate | Validate docs files |
pnpm release:build | Build all packages |
pnpm typescript | Type check |
pnpm eslint | Lint code |
pnpm prettier | Format code |
pnpm test --run | Run all tests |
pnpm test --run {name} | Run specific test file |
pnpm test:browser --run | Run browser tests (requires podman/docker) |
pnpm test:browser:unconfined | Run browser tests directly (CI/Playwright image) |
Important
Always run
pnpm prettier,pnpm eslint,pnpm typescript, andpnpm docs:validatebefore submitting a PR.
Create or modify tests before changing implementation. When fixing bugs, write a failing test that reproduces the issue first:
src/{functionName}/{functionName}.test.ts # Unit tests
src/{functionName}/user.spec.ts # Integration tests
src/{functionName}/optimization.test.ts # Performance tests
Document public functions in MDX:
docs/app/lib/{category}/{function-name}/page.mdx
docs/app/lib/{category}/{function-name}/demos/{demo-name}/index.ts
Follow the Architecture patterns for consistency.
pnpm release:build && pnpm typescript && pnpm eslint && pnpm prettier && pnpm test --run
packages/docs/
├── src/
│ ├── CodeHighlighter/ # React components
│ ├── useCode/ # React hooks
│ ├── pipeline/ # Build-time processing
│ │ ├── loadPrecomputed*/ # Webpack loaders
│ │ ├── loadServer*/ # Server-side loaders
│ │ ├── syncTypes/ # Type extraction
│ │ └── transform*/ # Markdown transformers
│ ├── abstractCreate*/ # Factory utilities
│ └── cli/ # CLI commands
└── build/ # Built output
docs/app/lib/
├── architecture/ # System design docs
├── components/ # Component documentation
├── hooks/ # Hook documentation
├── functions/ # Function documentation
├── patterns/ # Architectural patterns
└── commands/ # CLI documentation
Functions are named {Purpose}{Object} for alphabetical sorting:
| Prefix | Purpose | Example |
|---|---|---|
load | Load data from files/network | loadServerCodeSource |
parse | Parse strings into structures | parseSource |
transform | Transform data structures | transformMarkdownCode |
sync | Update committed files | syncTypes |
create | Factory functions | createDemo |
abstract | Factory factory functions | abstractCreateDemo |
use | React hooks | useCode |
with | Configuration plugins | withFairGardenDocs |
React components use {Object}{Purpose}: CodeHighlighter, CodeProvider.
src/{functionName}/
├── {functionName}.ts # Main implementation
├── {functionName}.test.ts # Unit tests
├── {helperFunction}.ts # Split out large helpers
├── types.ts # Complex/shared types
├── errors.ts # Custom error classes
├── constants.ts # Large string constants
└── index.ts # Re-exports
any, prefer unknown with narrowing.then() chainsPromise.all() for independent async operationsButton, Checkbox)describe('parseSource', () => {
it('highlights TypeScript code', () => {
const result = parseSource('const x = 1', 'example.ts');
expect(result.type).toBe('root');
});
});
// user.spec.ts
describe('user can highlight code', () => {
it('renders highlighted TypeScript', async () => {
// Test the full pipeline
});
});
src/{functionName}/{functionName}.tssrc/{functionName}/{functionName}.test.tssrc/{functionName}/index.tspackage.json exportsdocs/app/lib/functions/{function-name}/page.mdxsrc/{ComponentName}/{ComponentName}.tsx.ts files'use client'docs/app/lib/components/{component-name}/page.mdxsrc/pipeline/loadPrecomputed{Name}/loadPrecomputed{Name}.tswithFairGardenDocs default patterns if appropriateThis extends Next.js filesystem conventions with special handling for documentation files.
./app/**/demos/*/index.ts - Load Precomputed Code Highlighter./app/**/demos/*/client.ts - Load Precomputed Code Highlighter Client./app/**/types.ts - Load Precomputed Types./app/sitemap/index.ts - Load Precomputed SitemapWhen working with workspace packages, use the -F flag:
# Add a dependency
pnpm -F @fairgarden/docs add lodash
# Remove a dependency
pnpm -F @fairgarden/docs remove lodash
# Always dedupe after adding dependencies
pnpm dedupe
Warning
Do not manually edit
package.jsonto add/remove dependencies. Use pnpm commands to keep ordering deterministic.
The package uses 0.x.0 versioning to allow breaking changes while working toward a stable 1.0.0. Breaking changes should improve developer experience and be documented in the changelog.