|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +The project uses pnpm workspaces. Key commands: |
| 8 | + |
| 9 | +- `pnpm build` - Build all packages (runs recursive build command) |
| 10 | +- `pnpm test` - Run all tests with Vitest |
| 11 | +- `pnpm test:watch` - Run tests in watch mode |
| 12 | +- `pnpm dev` - Execute code with tsx under source conditions |
| 13 | +- `pnpm dev:play` - Execute play.ts for experimentation |
| 14 | +- `pnpm lint` - Run biome linter with auto-fix |
| 15 | +- `pnpm format` - Format code with biome |
| 16 | +- `pnpm fix` - Run both format and lint |
| 17 | + |
| 18 | +### Testing |
| 19 | + |
| 20 | +- Tests use Vitest with workspace-based configuration |
| 21 | +- Test files are located in `src/*/tests/` directories |
| 22 | +- Run specific tests: `pnpm test <pattern>` or `pnpm test --filter <workspace> <pattern>` |
| 23 | +- Tests include type checking via `typecheck.enabled = true` |
| 24 | + |
| 25 | +### Package-Specific Commands |
| 26 | + |
| 27 | +In the `packages/zod/` workspace: |
| 28 | +- `pnpm build` - Uses zshy build tool with tsconfig.build.json |
| 29 | +- `pnpm clean` - Clean build artifacts (preserving node_modules) |
| 30 | + |
| 31 | +## Architecture Overview |
| 32 | + |
| 33 | +Zod is a TypeScript-first schema validation library organized as a monorepo with multiple versions and variants: |
| 34 | + |
| 35 | +### Repository Structure |
| 36 | + |
| 37 | +- **Root**: Monorepo configuration with pnpm workspaces |
| 38 | +- **packages/zod/**: Main Zod package with multiple version exports |
| 39 | +- **packages/docs/**: Documentation website (Next.js) |
| 40 | +- **packages/bench/**: Performance benchmarks |
| 41 | +- **packages/resolution/**: Module resolution testing |
| 42 | +- **packages/treeshake/**: Bundle size analysis |
| 43 | +- **packages/tsc/**: TypeScript compilation benchmarks |
| 44 | + |
| 45 | +### Version Architecture |
| 46 | + |
| 47 | +The main zod package exports multiple versions: |
| 48 | + |
| 49 | +1. **v4 (default)**: Current version, exports from `v4/classic/external.js` |
| 50 | +2. **v4/core**: Core v4 implementation without legacy compatibility |
| 51 | +3. **v4/mini**: Lightweight v4 variant |
| 52 | +4. **v3**: Legacy version for backward compatibility |
| 53 | +5. **mini**: General minimal build |
| 54 | + |
| 55 | +### Key Implementation Files |
| 56 | + |
| 57 | +- `src/v4/core/`: Core validation logic, schemas, parsing, and error handling |
| 58 | +- `src/v4/classic/`: v4 with legacy compatibility layer |
| 59 | +- `src/v4/mini/`: Minimal v4 implementation |
| 60 | +- `src/v3/`: Legacy v3 implementation |
| 61 | +- `src/locales/`: Internationalization support |
| 62 | + |
| 63 | +### Export Strategy |
| 64 | + |
| 65 | +The package uses conditional exports with: |
| 66 | +- `@zod/source`: Development condition pointing to TypeScript source |
| 67 | +- Standard ESM/CJS exports for distribution |
| 68 | +- Multiple entry points for different versions and variants |
| 69 | + |
| 70 | +## Code Standards |
| 71 | + |
| 72 | +### Linting and Formatting |
| 73 | + |
| 74 | +- Uses Biome for both linting and formatting |
| 75 | +- Line width: 120 characters |
| 76 | +- Trailing commas: ES5 style for JavaScript, none for JSON |
| 77 | +- Notable lint rule relaxations: |
| 78 | + - `noExplicitAny: "off"` - `any` is allowed |
| 79 | + - `noParameterAssign: "off"` - Required for performance optimizations |
| 80 | + - `noNonNullAssertion: "off"` - Non-null assertions are allowed |
| 81 | + |
| 82 | +### TypeScript Configuration |
| 83 | + |
| 84 | +- Strict mode enabled with exact optional property types |
| 85 | +- Node.js module resolution (NodeNext) |
| 86 | +- Target: ES2020 |
| 87 | +- Custom conditions support for `@zod/source` |
| 88 | + |
| 89 | +## Development Workflow |
| 90 | + |
| 91 | +1. Use `play.ts` for experimentation with `pnpm dev:play` |
| 92 | +2. Write tests in appropriate `tests/` directories |
| 93 | +3. Build with `pnpm build` before testing changes |
| 94 | +4. Run linting/formatting with `pnpm fix` |
| 95 | +5. All changes must pass tests and type checking |
| 96 | + |
| 97 | +## Build System |
| 98 | + |
| 99 | +- Uses `zshy` build tool for the main package |
| 100 | +- Generates both ES modules and CommonJS outputs |
| 101 | +- Supports source maps and declaration files |
| 102 | +- Post-build formatting with Biome |
| 103 | + |
| 104 | +## Performance Considerations |
| 105 | + |
| 106 | +- Performance is critical - parameter reassignment is allowed for optimization |
| 107 | +- Benchmarks available in `packages/bench/` |
| 108 | +- Bundle size monitoring in `packages/treeshake/` |
| 109 | +- TypeScript compilation performance tracked in `packages/tsc/` |
0 commit comments