You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+38-71Lines changed: 38 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,110 +1,80 @@
1
1
# CLAUDE.md
2
2
3
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
3
## Project Overview
6
4
7
5
Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It uses WebGL to render vector tiles that conform to the Mapbox Vector Tile Specification.
8
6
9
7
## Workflow
10
-
- Make changes as concise as possible, ensure they are minimal and fully justified
11
-
- Read and understand relevant files before proposing code edits. If the user references a specific file/path, inspect it before explaining or proposing fixes.
12
-
- Understand WHY code exists before changing it. GL JS handles browser quirks, performance hacks, and WebGL state subtleties. Non-obvious patterns often exist for a reason—check git blame when in doubt.
13
-
- Avoid over-engineering. Only make changes that are directly requested or clearly necessary.
14
-
- Don't add features, refactor code, or make "improvements" beyond what was asked
15
-
- Don't create helpers or abstractions until you see repetition
- Read relevant files before proposing edits; always inspect a referenced file before explaining or fixing it
10
+
- Understand WHY code exists before changing it — GL JS has many browser quirks, performance hacks, and WebGL subtleties; check git blame when in doubt
11
+
- Avoid over-engineering: don't add features, refactor, or "improve" beyond what was asked; no abstractions or helpers until you see repetition, and only if cleaner than the duplication
17
12
- Always run `npm run tsc` and `npm run lint` when you're done making a series of code changes
18
-
- Run `npm run codegen` if you modify style properties or the style specification (regenerates style code, struct arrays, and TypeScript types)
13
+
- Run `npm run codegen` if you modify style properties or the style specification
19
14
- Run `npm run test-typings` after modifying public API types or the style specification
20
15
- Prefer running single tests, and avoid running the whole test suite, for performance
21
16
- Never add any dependencies unless explicitly requested
17
+
- Never use grep or find to look up symbols, types, or references — use LSP (`goToDefinition`, `findReferences`, `hover`, `documentSymbol`, `incomingCalls`, `outgoingCalls`) instead; fall back to grep only if LSP returns an error. Never use `workspaceSymbol` — it dumps the entire codebase (~43K symbols) and is never worth the token cost.
22
18
23
19
## Essential Commands
24
20
25
21
### Development
26
-
```bash
27
-
# Start development server with live reload
28
-
npm run start
29
22
30
-
# Build development version (ESM)
23
+
```bash
24
+
npm start
31
25
npm run build-esm-dev
32
-
33
-
# Build production bundles
34
-
npm run build-esm-prod # Minified ESM production build
35
-
npm run build-prod # Minified UMD production build
36
-
npm run build-css # Build CSS file
37
-
38
-
# Generate code (style code, struct arrays, and TypeScript types)
26
+
npm run build-esm-prod
27
+
npm run build-prod # UMD build
28
+
npm run build-css
39
29
npm run codegen
40
30
```
41
31
42
32
### Testing
43
-
```bash
44
-
# Test TypeScript definitions
45
-
npm run test-typings
46
33
47
-
# Run unit tests
34
+
```bash
48
35
npm run test-unit
36
+
npm run test-unit -- test/unit/style-spec/spec.test.ts -t 'Style#addImage'
49
37
50
-
# Run unit tests for specific file
51
-
npm run test-unit -- test/unit/style-spec/spec.test.ts
52
-
53
-
# Run specific test inside a file (use -t with test name pattern)
54
-
npm run test-unit -- test/unit/style/style.test.ts -t 'Style#addImage'
55
-
56
-
# Run render tests with pattern matching (matches test path segments)
57
38
npm run test-render -- -t "background-color"
58
-
59
39
# Regenerate expected.png baselines (inspect diffs before committing!)
60
40
UPDATE=1 npm run test-render -- -t "<pattern>"
41
+
42
+
npm run test-typings
61
43
```
62
44
63
45
Render tests:
64
-
- Test name = folder path under `test/integration/render-tests/` (e.g. `circle-radius/literal`). `-t`is Vitest's substring pattern, so `-t "circle"` also hits `circle-color`, `circle-blur`, etc. — add a slash to narrow: `-t "circle-radius/"`
46
+
- Test name = folder path under `test/integration/render-tests/` (e.g. `circle-radius/literal`). `-t`matches substrings — use a trailing slash to narrow: `-t "circle-radius/"`not `-t "circle"` (also hits `circle-color`, `circle-blur`, etc.)
65
47
- Always use `npm run test-render`, not `npx vitest` — the `pretest` hook rebuilds `dist/mapbox-gl-dev.js` and pmtiles
- Any PR that changes rendering behavior (shader changes, draw function logic, bucket data changes) must include a render test in `test/integration/render-tests/`
169
137
- For query behavior changes, add corresponding query tests covering all affected layer types
170
138
- Render tests for bug fixes must fail without the fix; a tolerance loose enough to pass either way is useless
171
139
- Every render test `style.json` must include a `_comment` field explaining what it checks; drop unused intermediate `wait` steps
172
140
- Don't inflate render test tolerance to make a failing test pass — investigate the root cause
173
141
- Size render test expected images to the minimum needed (e.g., 32×64, not 128×128)
- One return value or side effect per test - pull shared logic into functions
180
149
- Only test return values and global side effects - not internal behavior or method calls
181
150
- No network requests - use `mockFetch` from `test/util/network.ts` if needed
182
-
- Use clear input space partitioning - look for edge cases
183
151
184
152
## Documentation Conventions
185
153
186
154
- All public API must have JSDoc comments; private items tagged with `@private`
187
155
- Use markdown in JSDoc; surround code identifiers with \`backticks\`
188
156
- Class descriptions: describe what the class/instances *are* (e.g., "A layer that...")
189
157
- Function descriptions: start with third-person verb (e.g., "Sets...", "Returns...")
190
-
- For functions returning values, start with "Returns..."
191
158
- Event descriptions: start with "Fired when..."
192
159
- Style-spec `doc` fields in `v8.json` render verbatim in the public API reference — use unambiguous language, avoid internal terms, and don't reference implementation details
193
160
- When adding a new property to `v8.json`, populate the `sdk-support` table and set `experimental: true` until release version is confirmed
@@ -197,7 +164,7 @@ test/
197
164
- Custom `#pragma mapbox` directives in shaders expand to uniforms or attributes
198
165
- Shader programs are dynamically generated based on style properties
199
166
- Data-driven styling creates paint vertex arrays at layout time
200
-
- See [@src/shaders/README.md](src/shaders/README.md) for shader documentation
167
+
- See [src/shaders/README.md](src/shaders/README.md) for shader documentation
201
168
- Use named `#define` constants for integer mode values in shaders — never bare magic numbers like `if (u_blend_mode == 1)`
202
169
- Use `#if defined(A) && defined(B)` for compound shader conditionals (not `#ifdef`); required for the Metal preprocessing pipeline
0 commit comments