|
| 1 | +# Guidelines for Claude Code |
| 2 | + |
| 3 | +This repository is **Lerna**, a popular tool for managing JavaScript projects with multiple packages. Lerna uses Nx as the task runner and monorepo manager for building, testing, and managing the various Lerna commands and core functionality. |
| 4 | + |
| 5 | +## Package Manager |
| 6 | + |
| 7 | +This project uses **npm** (version 10.8.0) as the package manager. Always use `npm` commands instead of `pnpm` or `yarn`. |
| 8 | + |
| 9 | +## Required checks |
| 10 | + |
| 11 | +When modifying core Lerna functionality, commands, or documentation, run the following commands and ensure they pass: |
| 12 | + |
| 13 | +```bash |
| 14 | +npm run format:check # run npm run format:write and commit the result if this check fails |
| 15 | +npm run lint # run linting across all packages |
| 16 | +npm run test # run all unit tests |
| 17 | +npm run integration # run integration tests |
| 18 | +``` |
| 19 | + |
| 20 | +When working on a specific Lerna command, you can target tests for that command. For example, to run tests for the `publish` command: |
| 21 | + |
| 22 | +```bash |
| 23 | +nx test commands-publish |
| 24 | +``` |
| 25 | + |
| 26 | +For E2E tests of specific commands: |
| 27 | + |
| 28 | +```bash |
| 29 | +nx e2e publish # test the publish command end-to-end |
| 30 | +``` |
| 31 | + |
| 32 | +Use these commands for comprehensive testing: |
| 33 | + |
| 34 | +- `nx run-many -t build` to build all packages |
| 35 | +- `nx run-many -t test` to run all unit tests across all packages |
| 36 | +- `nx run-many -t lint` to run all linting across all packages |
| 37 | + |
| 38 | +IMPORTANT: Only run e2e commands once all other types of tests (and linting and building) have passed successfully. |
| 39 | + |
| 40 | +## Project Structure |
| 41 | + |
| 42 | +This is a monorepo with the following main structure: |
| 43 | + |
| 44 | +### `/libs/` - Core Libraries |
| 45 | + |
| 46 | +- **commands/**: Individual Lerna command implementations (add, bootstrap, changed, clean, create, diff, exec, import, info, init, link, list, publish, run, version) |
| 47 | +- **core/**: Core Lerna functionality and shared utilities |
| 48 | +- **legacy-core/**: Legacy core functionality maintained for backwards compatibility |
| 49 | +- **child-process/**: Utilities for spawning and managing child processes |
| 50 | +- **e2e-utils/**: Utilities for end-to-end testing |
| 51 | +- **test-helpers/**: Shared testing utilities and mocks |
| 52 | +- **nx-plugin/**: Nx plugin for the Lerna monorepo (not published) |
| 53 | + |
| 54 | +### `/packages/` - Published Packages |
| 55 | + |
| 56 | +- **lerna/**: Main Lerna package that gets published to npm |
| 57 | +- **legacy-package-management/**: Legacy package management functionality |
| 58 | +- **legacy-structure/**: Legacy structure maintained for compatibility |
| 59 | + |
| 60 | +### `/e2e/` - End-to-End Tests |
| 61 | + |
| 62 | +- Individual test suites for each Lerna command (changed, clean, create, diff, exec, info, init, list, publish, repair, run, version, watch) |
| 63 | + |
| 64 | +### `/__fixtures__/` - Test Fixtures |
| 65 | + |
| 66 | +- Various test scenarios and sample monorepo structures for integration testing |
| 67 | + |
| 68 | +## Code Conventions |
| 69 | + |
| 70 | +### TypeScript Configuration |
| 71 | + |
| 72 | +- **Strict TypeScript**: Uses strict mode with modern ES2022 target |
| 73 | +- **Target**: ES2022 with Node.js module resolution |
| 74 | +- **Module system**: Modern Node.js compatibility |
| 75 | +- **Node.js version**: 20.18.3 (managed by Volta) |
| 76 | + |
| 77 | +### ESLint Configuration |
| 78 | + |
| 79 | +- Uses **flat config** format (eslint.config.mjs) |
| 80 | +- Nx ESLint plugin for monorepo management |
| 81 | +- TypeScript ESLint for type-aware linting |
| 82 | +- Enforces module boundaries between packages |
| 83 | + |
| 84 | +### File Naming and Structure |
| 85 | + |
| 86 | +- **Test files**: Use `.spec.ts` suffix and live in `__tests__/` or `src/__tests__/` directories |
| 87 | +- **Command files**: Individual TypeScript files in `libs/commands/{command-name}/src/` |
| 88 | +- **Core utilities**: In `libs/core/src/` and related core packages |
| 89 | +- **E2E tests**: Organized in `e2e/{command-name}/src/` directories |
| 90 | +- **Fixtures**: Test scenarios in `__fixtures__/` directories |
| 91 | + |
| 92 | +### Command Development Patterns |
| 93 | + |
| 94 | +When creating or modifying Lerna commands: |
| 95 | + |
| 96 | +1. Commands are implemented in TypeScript in `libs/commands/{command-name}/` |
| 97 | +2. Each command has its own library with tests and documentation |
| 98 | +3. Commands use shared utilities from `libs/core/` and other core packages |
| 99 | +4. E2E tests verify command behavior in realistic scenarios |
| 100 | +5. Commands follow consistent patterns for CLI argument parsing and execution |
| 101 | + |
| 102 | +### Testing Conventions |
| 103 | + |
| 104 | +- **Jest**: Primary testing framework with Nx test runner |
| 105 | +- **Unit tests**: Test individual functions and command logic |
| 106 | +- **Integration tests**: Test command interactions and workflows |
| 107 | +- **E2E tests**: Test full command execution in realistic monorepo scenarios |
| 108 | +- **Fixtures**: Predefined test scenarios for consistent testing |
| 109 | + |
| 110 | +### Build and Release |
| 111 | + |
| 112 | +- **Build**: Uses Nx with TypeScript compilation and esbuild |
| 113 | +- **Targets**: Multiple build targets with dependency management |
| 114 | +- **Release**: Conventional Commits with automated versioning |
| 115 | +- **Versioning**: Uses Lerna's own versioning system |
| 116 | +- **Publishing**: Commands handle npm package publishing |
| 117 | + |
| 118 | +Claude should NEVER run versioning or publishing commands. |
| 119 | + |
| 120 | +## Commit conventions |
| 121 | + |
| 122 | +Use [Conventional Commits](https://www.conventionalcommits.org/) for commit messages and PR titles. |
| 123 | + |
| 124 | +- When a change affects a single command, include its name as the scope: `feat(publish): add registry authentication`. |
| 125 | +- When multiple commands are affected, omit the scope: `fix: correct workspace detection`. |
| 126 | +- When affecting core functionality: `feat(core): add new package discovery method`. |
| 127 | + |
| 128 | +By convention, if only updating a single command within the commands library, for example the `version` command, the commit message should be `fix(version): description of the change`. |
| 129 | + |
| 130 | +For any changes that only update tests, use `test` or `chore` as the commit/PR type, do not use `fix` or `feat`. |
| 131 | + |
| 132 | +## Development Tools |
| 133 | + |
| 134 | +- **Node.js**: Version 20.18.3 (managed by Volta, check `package.json` for current version) |
| 135 | +- **npm**: Version 10.8.0 as the package manager |
| 136 | +- **Nx**: Task runner and monorepo management |
| 137 | +- **TypeScript**: Strict configuration for type safety |
| 138 | +- **Jest**: Testing framework with Nx integration |
| 139 | + |
| 140 | +## Common Commands |
| 141 | + |
| 142 | +```bash |
| 143 | +# Install dependencies |
| 144 | +npm install |
| 145 | + |
| 146 | +# Build all packages |
| 147 | +npm run build |
| 148 | +# or use Nx directly |
| 149 | +nx run-many -t build |
| 150 | + |
| 151 | +# Run all tests |
| 152 | +npm run test |
| 153 | +# or use Nx directly |
| 154 | +nx run-many -t test |
| 155 | + |
| 156 | +# Run integration tests |
| 157 | +npm run integration |
| 158 | + |
| 159 | +# Run E2E tests for a specific command |
| 160 | +nx e2e publish |
| 161 | + |
| 162 | +# Format code |
| 163 | +npm run format:write |
| 164 | + |
| 165 | +# Check formatting |
| 166 | +npm run format:check |
| 167 | + |
| 168 | +# Lint all packages |
| 169 | +npm run lint |
| 170 | +# or use Nx directly |
| 171 | +nx run-many -t lint |
| 172 | + |
| 173 | +# Test a specific command |
| 174 | +nx test commands-publish |
| 175 | + |
| 176 | +# Build and test everything |
| 177 | +nx run-many -t build test lint |
| 178 | + |
| 179 | +# Start local registry for E2E testing |
| 180 | +npm run e2e-start-local-registry |
| 181 | + |
| 182 | +# Build package for E2E publishing tests |
| 183 | +npm run e2e-build-package-publish |
| 184 | +``` |
| 185 | + |
| 186 | +## Lerna Configuration |
| 187 | + |
| 188 | +The project includes a `lerna.json` configuration file that defines: |
| 189 | + |
| 190 | +- Command-specific settings (create, publish, version) |
| 191 | +- Conventional commits for versioning |
| 192 | +- GitHub releases integration |
| 193 | +- Files to ignore when detecting changes |
| 194 | + |
| 195 | +This configuration is used both for Lerna's own development and as a reference implementation for users. |
0 commit comments