|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Requirements |
| 6 | +- **Node.js**: >=20.0.0 |
| 7 | +- **Bun**: 1.3.5+ |
| 8 | + |
| 9 | +## Package Manager |
| 10 | + |
| 11 | +This branch (`main`) uses **Bun** as the package manager and runtime. |
| 12 | + |
| 13 | +## Commands |
| 14 | +- **Install**: `bun install` |
| 15 | +- **Build**: `bun run build` |
| 16 | +- **Lint**: `bun run lint` | **Format**: `bun run format` |
| 17 | +- **Test all**: `bun run test` |
| 18 | +- **Test single package**: `bun test packages/<name>` (e.g., `bun test packages/core`) |
| 19 | +- **Test single file**: `bun test packages/core/__tests__/core.test.ts` |
| 20 | +- **Typecheck**: `bun run typecheck` |
| 21 | +- **CI (full)**: `bun run ci` |
| 22 | + |
| 23 | +## Code Style (Biome) |
| 24 | +- **Indent**: 4 spaces | **Quotes**: double | **Semicolons**: always | **Trailing commas**: ES5 |
| 25 | +- **Imports**: Use `type` keyword for type-only imports. Use `node:` prefix for Node.js built-ins (e.g., `node:child_process`) |
| 26 | +- **File extensions**: Include `.ts` in local imports (e.g., `./setup.ts`) |
| 27 | +- **Naming**: camelCase for functions/variables, PascalCase for types/interfaces |
| 28 | +- **Tests**: Vitest with `describe`/`test`/`expect`. Files in `packages/*/__tests__/*.test.ts` |
| 29 | +- **Error handling**: Use `try/catch` with `if (err instanceof Error)` checks |
| 30 | +- **Source files**: Include copyright header: `/*! node-minify ... MIT Licensed */` |
| 31 | + |
| 32 | +## Architecture |
| 33 | + |
| 34 | +This is a Bun monorepo for compressing JavaScript, CSS, and HTML files using various backends. |
| 35 | + |
| 36 | +### Package Structure |
| 37 | + |
| 38 | +**Core packages** (in `/packages`): |
| 39 | +- `core` - Main `minify()` function, orchestrates compression |
| 40 | +- `utils` - Shared utilities (file operations, gzip sizing) |
| 41 | +- `run` - Command execution wrapper for external tools |
| 42 | +- `types` - TypeScript type definitions (not compiled) |
| 43 | +- `cli` - Command-line interface |
| 44 | + |
| 45 | +**Compressor packages** - Each wraps a specific minification library: |
| 46 | +- JS: `babel-minify`, `google-closure-compiler`, `terser`, `uglify-js`, `uglify-es` |
| 47 | +- CSS: `clean-css`, `crass`, `cssnano`, `csso`, `sqwish` |
| 48 | +- HTML: `html-minifier` |
| 49 | +- Other: `yui` (JS/CSS), `jsonminify`, `no-compress` (passthrough) |
| 50 | + |
| 51 | +**Deprecated** (still available but unmaintained upstream): |
| 52 | +- `babel-minify` - Babel 6 only, use `terser` instead |
| 53 | +- `uglify-es` - Unmaintained, use `terser` instead |
| 54 | + |
| 55 | +### Dependencies |
| 56 | + |
| 57 | +`core` depends on `utils` and `run`. All compressor packages depend on `core`. The build script (`scripts/build-packages.js`) builds `utils` and `run` first, then all other packages in parallel. |
| 58 | + |
| 59 | +### Package Pattern |
| 60 | + |
| 61 | +All packages follow the same structure: |
| 62 | +``` |
| 63 | +packages/<name>/ |
| 64 | +├── src/index.ts # Main export |
| 65 | +├── __tests__/ # Vitest tests |
| 66 | +├── package.json |
| 67 | +└── tsconfig.json |
| 68 | +``` |
| 69 | + |
| 70 | +Build: `tsdown` (configured via `tsdown.config.ts`) |
0 commit comments