Guidelines for AI coding agents working in this repository.
This is a monorepo for OpenNext.js adapters, enabling Next.js deployment to various platforms (AWS Lambda, Cloudflare Workers, Node.js). The repository uses pnpm workspaces with multiple packages under packages/ and example applications under examples/ and examples-cloudflare/.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Build only opennext packages
pnpm build:opennext
# Run linter
pnpm lint
# Fix linting issues
pnpm lint:fix
# Check formatting
pnpm fmt
# Fix formatting issues
pnpm fmt:fix
# TypeScript type checking (all packages)
pnpm ts:check
# Run all code checks (fmt + lint + ts:check)
pnpm code:checks
# Run all unit tests
pnpm test
# Run e2e tests
pnpm e2e:test# Run a specific test file in the cloudflare package
pnpm --filter @opennextjs/cloudflare vitest run path/to/test.spec.ts
# Run tests matching a pattern in the tests-unit package
pnpm --filter tests-unit vitest run --testNamePattern="test name pattern"
# Run a single test file with vitest directly
cd packages/tests-unit && pnpm vitest run tests/core/routing/matcher.test.ts
# Run tests in watch mode
pnpm --filter tests-unit vitest
# Run tests in a specific package
pnpm --filter @opennextjs/cloudflare test# Build a specific package
pnpm --filter @opennextjs/cloudflare build
# Type check a specific package
pnpm --filter @opennextjs/cloudflare ts:check- Use explicit file extensions (
.js) for local imports:import { foo } from "./bar.js" - Use Node.js built-in imports with
node:prefix:import fs from "node:fs" - Group imports logically: built-ins first, then external packages, then local modules
- Use workspace protocol for internal packages:
"@opennextjs/aws": "workspace:*"
- TypeScript strict mode is enabled via
@tsconfig/strictest - Use explicit type annotations for function parameters and return types
- Prefer
typefor object types,interfacefor extensible types - Use
import typefor type-only imports - Avoid
any- useunknownor specific types; if unavoidable, add// oxlint-disable @typescript-eslint/no-explicit-anycomment - Target ES2022 for compilation
- Tabs for indentation (check .editorconfig if present)
- Double quotes for strings
- Trailing commas in objects/arrays
- Semicolons are required
- camelCase for variables and functions
- PascalCase for types, interfaces, and classes
- SCREAMING_SNAKE_CASE for constants
- kebab-case for file names:
my-component.ts,use-cache.ts .spec.tssuffix for test files (unit tests use vitest).test.tssuffix for test files in tests-unit package
- Throw descriptive
Errorobjects with context - Use typed errors when specific error handling is needed
- Log errors with console.error/console.log for CLI commands
- Handle async errors with try/catch or .catch()
- Source code in
src/directory - Test files co-located with source (
.spec.ts) or in separate tests directory (.test.ts) - Export public API through
index.tsfiles - Use barrel exports:
export * from "./module.js" - Configuration files at package root
- Use vitest for unit tests
- Use
describe/test/expectfrom vitest - Test file naming:
*.spec.tsfor co-located tests,*.test.tsfor tests-unit package - Mock external dependencies with
vi.mock()andvi.fn() - Run tests in Node.js environment (not jsdom) by default
- Use JSDoc comments for public APIs
- Document complex logic with inline comments
- Use
// TODO(username)or// TODO: descriptionfor TODOs - Keep comments concise and relevant
This project uses pnpm exclusively. Do not use npm or yarn commands.
# Add a dependency to a specific package
pnpm --filter <package-name> add <dependency>
# Add a dev dependency
pnpm --filter <package-name> add -D <dependency>
# Run a script in a specific package
pnpm --filter <package-name> <script-name>Before committing, ensure:
pnpm fmt:fix- Code is properly formattedpnpm lint:fix- No linting errorspnpm ts:check- TypeScript compiles without errorspnpm test- All tests pass
Run pnpm code:checks to verify all checks pass.