|
| 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 | +prettierd is a daemon-based wrapper around Prettier that provides fast code formatting |
| 8 | +for editor integration. It uses [core_d.js](https://github.com/mantoni/core_d.js) to |
| 9 | +run Prettier as a persistent background process, avoiding repeated Node.js startup |
| 10 | +overhead. Published as `@fsouza/prettierd` on npm. |
| 11 | + |
| 12 | +## Commands |
| 13 | + |
| 14 | +- `yarn build` — compile TypeScript (`tsc -b`, outputs to `dist/`) |
| 15 | +- `yarn prettier:check` — verify code formatting |
| 16 | +- `yarn prettier:fix` — auto-format all code |
| 17 | +- `yarn start` — start the prettierd daemon |
| 18 | + |
| 19 | +There is no test suite. CI runs `prettier:check`, `build`, and then starts the daemon |
| 20 | +to verify it works. |
| 21 | + |
| 22 | +## Architecture |
| 23 | + |
| 24 | +``` |
| 25 | +bin/prettierd Shell entry point (sets FORCE_COLOR=0, requires dist/prettierd.js) |
| 26 | + ↓ |
| 27 | +src/prettierd.ts CLI orchestration: parses args, sets up env vars, manages daemon |
| 28 | + ├─→ src/args.ts CLI argument definitions and help display |
| 29 | + ├─→ src/get-stdin.ts Vendored stdin reader (from get-stdin package) |
| 30 | + ├─→ src/service.ts Core formatting service invoked by core_d daemon |
| 31 | + └─→ core_d External daemon lifecycle manager (start/stop/restart/status) |
| 32 | +``` |
| 33 | + |
| 34 | +**prettierd.ts** — Processes CLI arguments into actions (INVOKE_CORE_D, STOP, |
| 35 | +PRINT_VERSION, etc.), determines the runtime directory (XDG_RUNTIME_DIR or TMPDIR or |
| 36 | +HOME), and forwards `PRETTIERD_*` environment variables from client to the daemon |
| 37 | +service. |
| 38 | + |
| 39 | +**service.ts** — The service module loaded by core_d. Handles: |
| 40 | +- Prettier resolution: tries local project prettier first, falls back to bundled. |
| 41 | + `PRETTIERD_LOCAL_PRETTIER_ONLY` env var disables the fallback. |
| 42 | +- Config resolution chain: explicit config path → `PRETTIERD_DEFAULT_CONFIG` env var → |
| 43 | + `prettier.resolveConfig()` with editorconfig support. |
| 44 | +- Config precedence modes: `cli-override` (default), `file-override`, `prefer-file`. |
| 45 | +- Two tasks: `format` (default) and `check`. |
| 46 | + |
| 47 | +**Daemon model** — One daemon instance per working directory, identified by an encoded |
| 48 | +dotfile name (`.prettierd@{encoded_cwd}`). Invocation: content is piped via stdin with |
| 49 | +the filename as the first argument. |
| 50 | + |
| 51 | +## Code Conventions |
| 52 | + |
| 53 | +- Strict TypeScript (`strict: true` plus all additional strict flags in tsconfig.json) |
| 54 | +- ES2018 target, CommonJS modules |
| 55 | +- 2-space indentation, formatting enforced by Prettier |
| 56 | +- Type declarations for untyped dependencies live in `src/types/` |
0 commit comments