Skip to content

Commit b899fca

Browse files
authored
add CLAUDE.md (#75)
1 parent 6c01a89 commit b899fca

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

CLAUDE.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Architecture Overview
6+
7+
This project generates alternative TypeScript standard library definitions with improved type safety. The architecture consists of:
8+
9+
- **`build/`** - TypeScript build system and generation logic
10+
- `lib.ts` - Main script for generating improved lib definitions
11+
- `package.ts` - Script for building npm packages
12+
- `diff.ts` - Script for generating documentation diffs
13+
- `logic/` - Core generation logic and AST manipulation
14+
15+
- **`lib/`** - Source TypeScript lib definition improvements (what gets applied to TypeScript's built-in libs)
16+
17+
- **`generated/`** - Output directory for processed TypeScript lib files
18+
19+
- **`dist-package/`** - Individual npm packages for each TypeScript lib (e.g., es2015, dom, etc.)
20+
21+
- **`TypeScript/`** - Git submodule containing the official TypeScript repository for source lib files
22+
23+
- **`tests/`** - Type-level tests using `tsd` to verify the improved type definitions work correctly
24+
25+
## Essential Commands
26+
27+
### Build Commands
28+
```bash
29+
# Compile TypeScript build scripts
30+
npm run build:tsc
31+
32+
# Generate improved lib files from TypeScript source + better-typescript-lib improvements
33+
npm run build:lib
34+
35+
# Build npm packages for distribution
36+
npm run build:package
37+
38+
# Generate documentation diffs
39+
npm run build:diff
40+
```
41+
42+
### Testing
43+
```bash
44+
# Run type-level tests in tests/ directory
45+
cd tests && npm test
46+
47+
# Or run tsd directly
48+
cd tests && npx tsd
49+
```
50+
51+
### Development Workflow
52+
1. Modify type definitions in `lib/` directory
53+
2. Run `npm run build:tsc && npm run build:lib` to regenerate
54+
3. Test changes with `cd tests && npm test`
55+
4. Generate packages with `npm run build:package` if needed
56+
57+
## Key Implementation Details
58+
59+
- Uses AST manipulation to apply improvements to TypeScript's standard library definitions
60+
- Generates separate npm packages that TypeScript automatically detects and uses (via `@typescript/lib-*` naming)
61+
- The `ReplacementMap` system tracks which parts of the original TypeScript libs should be replaced with improved versions
62+
- Type improvements focus on replacing `any` with more specific types like `JSONData` for `JSON.parse()`
63+
- All changes prioritize type safety over convenience, potentially causing breaking changes in existing codebases
64+
65+
## Important Files
66+
- `build/logic/generate.ts` - Core generation algorithm
67+
- `build/logic/ReplacementMap.ts` - Tracks lib modifications
68+
- `lib/es5.d.ts` - Main improvements to core JavaScript APIs
69+
- `tests/src/` - Type-level tests for verifications

0 commit comments

Comments
 (0)