|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This is `@bacons/xcode`, a TypeScript package that provides a spec-compliant parser for Xcode's `.pbxproj` files (project files). It's designed as a faster, more accurate alternative to the legacy `xcode` npm package, using Chevrotain parser instead of PEG.js. |
| 8 | + |
| 9 | +The package offers two main APIs: |
| 10 | +1. **Low-level JSON API** (`src/json/`) - Direct parsing and building of pbxproj files |
| 11 | +2. **High-level Object API** (`src/api/`) - Mutable graph-based API for easier manipulation |
| 12 | + |
| 13 | +## Development Commands |
| 14 | + |
| 15 | +- **Build**: `yarn build` (compiles TypeScript to `build/` directory) |
| 16 | +- **Test**: `yarn test` (runs Jest tests) |
| 17 | +- **Clean**: `yarn clean` (removes build directory) |
| 18 | +- **Test single file**: `yarn test <filename>` (e.g., `yarn test PBXProject.test.ts`) |
| 19 | +- **Watch tests**: `yarn test --watch` |
| 20 | + |
| 21 | +## Architecture |
| 22 | + |
| 23 | +### Core Components |
| 24 | + |
| 25 | +**JSON Layer** (`src/json/`): |
| 26 | +- `parser/` - Chevrotain-based parser for pbxproj format (old-style plist) |
| 27 | +- `writer.ts` - Serializes JSON back to pbxproj format |
| 28 | +- `types.ts` - TypeScript definitions for all pbxproj object types |
| 29 | +- `unicode/` - Handles string parsing using port of CFOldStylePlist parser |
| 30 | +- `visitor/JsonVisitor.ts` - Converts CST to JSON representation |
| 31 | + |
| 32 | +**API Layer** (`src/api/`): |
| 33 | +- `XcodeProject.ts` - Main entry point, manages the object graph |
| 34 | +- Individual object classes (PBXProject, PBXNativeTarget, PBXFileReference, etc.) |
| 35 | +- `AbstractObject.ts` - Base class for all pbxproj objects |
| 36 | +- `utils/` - Shared utilities including build settings resolution |
| 37 | + |
| 38 | +### Key Patterns |
| 39 | + |
| 40 | +1. **Lazy Loading**: Objects are inflated on-demand to avoid loading entire project graphs |
| 41 | +2. **UUID Management**: Deterministic UUID generation based on content hashing |
| 42 | +3. **Reference Resolution**: Objects maintain references to each other via UUIDs |
| 43 | +4. **Type Safety**: Full TypeScript coverage with strict compiler options |
| 44 | + |
| 45 | +### Entry Points |
| 46 | + |
| 47 | +- `src/index.ts` - Exports the high-level API |
| 48 | +- `json.js` / `json.d.ts` - Low-level JSON API entry point |
| 49 | +- Main exports: `XcodeProject.open()`, `parse()`, `build()` |
| 50 | + |
| 51 | +## Testing |
| 52 | + |
| 53 | +Tests are located in `__tests__/` directories throughout the codebase: |
| 54 | +- `src/api/__tests__/` - API layer tests with real project fixtures |
| 55 | +- `src/json/__tests__/` - JSON parser tests with various pbxproj formats |
| 56 | +- Fixtures in `src/json/__tests__/fixtures/` contain real-world project files |
| 57 | + |
| 58 | +The test suite uses Jest with TypeScript support and includes extensive fixtures from various Xcode project types (React Native, Swift, CocoaPods, etc.). |
0 commit comments