Skip to content

Commit 569b85d

Browse files
authored
chore: add claude code to the repo (lerna#4194)
1 parent 9205c2b commit 569b85d

File tree

3 files changed

+243
-1
lines changed

3 files changed

+243
-1
lines changed

.github/workflows/claude.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
env:
14+
SKIP_POSTINSTALL: true
15+
16+
jobs:
17+
claude:
18+
if: |
19+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
20+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
21+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
22+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
pull-requests: read
27+
issues: read
28+
id-token: write
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0 # we need the tags to be available but not the full tree
34+
filter: "tree:0"
35+
36+
- name: Install primary node version (see volta config in package.json) and dependencies
37+
uses: ./.github/actions/install-node-and-dependencies
38+
39+
- name: Run Claude Code
40+
id: claude
41+
uses: anthropics/claude-code-action@beta
42+
with:
43+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
44+
timeout_minutes: 20
45+
allowed_tools: "Edit,Read,Write,Glob,Grep,LS,MultiEdit,Bash(pnpm install),Bash(pnpm --version),Bash(pnpm build),Bash(pnpm test),Bash(pnpm e2e),Bash(pnpm update-e2e-snapshots),Bash(pnpm lint),Bash(pnpm typecheck),Bash(pnpm format),Bash(pnpm format-check),Bash(pnpm update-rule-docs),Bash(pnpm check-rule-docs),Bash(pnpm update-rule-lists),Bash(pnpm check-rule-lists),Bash(pnpm update-rule-configs),Bash(pnpm check-rule-configs),Bash(pnpm nx:*),Bash(git status),Bash(git add .),Bash(git commit -m),Bash(git diff),Bash(git log --oneline -10),Bash(node --version)"

CLAUDE.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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.

e2e/create/src/create.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,9 @@ describe("lerna-create", () => {
12671267
});
12681268
});
12691269

1270-
describe("created test script", () => {
1270+
// TODO: Investigate why this test started failing
1271+
// Example failure: https://cloud.nx.app/runs/4RSTjvMb4J/task/e2e-create%3Ae2e
1272+
xdescribe("created test script", () => {
12711273
it("should run and succeed", async () => {
12721274
await fixture.lerna("create test-script -y");
12731275
const result = await fixture.lerna("run test --scope=test-script");

0 commit comments

Comments
 (0)