diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..935a06e0 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,198 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +Microbundle is a zero-configuration bundler for tiny JavaScript libraries, powered by Rollup. It takes source code and produces multiple output formats (modern ES modules, CommonJS, UMD) with minimal setup. + +## Development Commands + +### Building + +- `npm run build` - Full build: first builds with Babel, then self-builds +- `npm run build:babel` - Build using Babel only +- `npm run build:self` - Self-build using microbundle's own dist output +- `npm run prepare` - Runs full build (called before npm publish) + +### Testing + +- `npm test` - Run linter, build, and Jest tests +- `npm run jest` - Run Jest tests only (without lint/build) +- Test timeout is set to 11 seconds for fixture tests + +### Linting and Formatting + +- `npm run lint` - Run ESLint on src directory +- `npm run format` - Format all JS and CSS files with Prettier + +### Changesets and Versioning + +This project uses [@changesets/cli](https://github.com/changesets/changesets) to track notable changes and generate changelogs. + +#### Creating a Changeset + +When making a change that should be documented in the changelog: + +```bash +npm run changeset +``` + +This will: + +1. Prompt you to select the type of change (major, minor, or patch) +2. Ask you to describe the change +3. Create a markdown file in `.changeset/` with a randomly generated name + +#### Changeset Configuration + +- **Changelog Format**: Uses `@changesets/changelog-github` to generate GitHub-flavored changelogs +- **Base Branch**: `master` (configured in .changeset/config.json:10) +- **Access**: Public (for npm publishing) +- **Commit Mode**: Changesets are not automatically committed (commit: false) + +#### Changeset File Format + +Changeset files in `.changeset/` follow this format: + +```markdown +--- +"microbundle": patch +--- + +Description of the change +``` + +The version bump type can be: `major`, `minor`, or `patch` + +### Running Tests + +Individual tests can be run with Jest's standard CLI options: + +```bash +npm run jest -- --testNamePattern="build shebang" +npm run jest -- test/index.test.js +``` + +## Architecture + +### Entry Points + +- **src/cli.js** - CLI entry point (shebang script), parses arguments and invokes main function +- **src/index.js** - Main bundling logic, exports the `microbundle()` function +- **src/prog.js** - CLI command definitions using `sade` library + +### Core Build Flow + +1. **Input Resolution** (`getInput()` in src/index.js:205) + + - Resolves entry files from CLI args, `source` field in package.json, or defaults (src/index.js, index.js) + - Supports glob patterns for multiple entries + - Handles TypeScript (.ts/.tsx) and JavaScript files + +2. **Output Resolution** (`getOutput()` in src/index.js:227) + + - Determines output location from CLI args or package.json `main` field + - Defaults to dist/ directory + +3. **Format Generation** (`getMain()` in src/index.js:278) + + - Maps each format (modern, es, cjs, umd) to appropriate output filenames + - Reads from package.json fields: `module`, `main`, `exports`, `unpkg`, etc. + - Respects `{"type":"module"}` for ES Module packages + +4. **Configuration Creation** (`createConfig()` in src/index.js:327) + + - Creates Rollup configuration for each entry/format combination + - Configures plugins: Babel, TypeScript, PostCSS, Terser, etc. + - Handles externals (dependencies vs devDependencies) + - Manages source maps, compression, and name caching + +5. **Build Execution** + - Sequential builds with caching (cjs format builds first) + - Watch mode available via Rollup's watch API + +### Format Types + +- **modern** - ES2017+ with modern syntax (async/await, arrow functions) for `