Skip to content

Commit fc0fe58

Browse files
fix: add CLAUDE.md
1 parent 2fb8ea0 commit fc0fe58

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
git-essentials is a TypeScript library providing essential Git commands for both Node.js and browser environments with zero native dependencies. It works by directly modifying `.git` directory contents, aiming for 100% interoperability with canonical git. Based on isomorphic-git.
8+
9+
## Build & Development Commands
10+
11+
```bash
12+
npm run check # TypeScript type checking (tsc --noEmit)
13+
npm run build # Compile TypeScript to ESM (outputs to dist/)
14+
npm test # Run Jest tests with coverage
15+
npm run test:browser # Run Karma browser tests (dev mode, needs browsers)
16+
npm run test:browsers # Run Karma headless (Chrome, Firefox, WebKit)
17+
```
18+
19+
Run a single test file:
20+
```bash
21+
npx jest tests/clone.test.ts
22+
```
23+
24+
Run a specific test by name:
25+
```bash
26+
npx jest -t "test name pattern"
27+
```
28+
29+
## Architecture
30+
31+
### Layered Design
32+
33+
The codebase follows a strict layered architecture:
34+
35+
1. **API layer** (`src/api/`) — Public functions. Each validates parameters via `assertParameter`, wraps `FsClient` in a `FileSystem` abstraction, delegates to the command layer, and tags errors with `err.caller`.
36+
37+
2. **Command layer** (`src/commands/`) — Internal implementations prefixed with underscore (e.g., `_clone`). Contains the actual git logic.
38+
39+
3. **Manager layer** (`src/managers/`) — Stateful git resource management: config, index, refs, remotes, ignores, shallow commits.
40+
41+
4. **Model layer** (`src/models/`) — Data structures: `GitCommit`, `GitTree`, `GitIndex`, `GitPackIndex`, `GitObject`, walker types. Re-exported from `src/index.ts`.
42+
43+
5. **Storage layer** (`src/storage/`) — Git object database: reading/writing loose and packed objects.
44+
45+
6. **Wire layer** (`src/wire/`) — Git smart HTTP protocol: parsing and writing upload-pack/receive-pack messages.
46+
47+
### Cross-Environment Support
48+
49+
The library uses an adapter pattern for environment portability:
50+
51+
- **Filesystem clients** (`src/clients/fs/`): `InMemoryFsClient`, `IndexedDbFsClient`, `FileSystemAccessApiFsClient`. All implement the `FsClient` interface.
52+
- **HTTP clients** (`src/clients/http/`): `NodeHttpClient`, `WebHttpClient`. Both implement `HttpClient`.
53+
- Consumers pass `fs` and `http` implementations into every API call — the library never imports environment-specific code directly.
54+
55+
### Error Handling
56+
57+
Custom error hierarchy in `src/errors/` with 30+ specific types extending `BaseError`. All API functions catch errors and attach a `caller` property (e.g., `git.clone`).
58+
59+
## Testing
60+
61+
Tests use **Jest** with **ts-jest** and run against in-memory fixtures (no real filesystem or network):
62+
63+
- `makeFsFixture()` — creates an `InMemoryFsClient` with optional pre-populated directory tree from JSON fixture data
64+
- `makeHttpFixture()` — creates a mock `HttpClient` that matches requests against fixture data (JSON files with base64-encoded request/response pairs)
65+
- Fixture data is generated by scripts in `scripts/` (`gen-fs-fixture.js`, `gen-http-fixture.js`)
66+
67+
Module aliases in tests: `git-essentials` maps to `src/`, and `src/*` paths are supported via Jest's `moduleNameMapper`.
68+
69+
## Package Exports
70+
71+
The package is ESM-only (`"type": "module"`) with tree-shakeable sub-path exports:
72+
- `git-essentials` — all API functions + models
73+
- `git-essentials/api/*` — individual API functions
74+
- `git-essentials/errors` — error types
75+
- `git-essentials/models/*` — data models
76+
- `git-essentials/clients/*` — fs/http client implementations

0 commit comments

Comments
 (0)