This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a template for creating npm modules using Bun as the build tool. The project uses TypeScript and is configured for ES2022 module output. While Bun is used for development, the built module targets Node.js environments (>=18.0.0).
bun run build- Full build process (clean, bundle with Bun, generate TypeScript declarations)bun run check- Run all quality checks in parallel (lint, type-check, test:unit)bun run type-check- Run TypeScript type checking without emitting filesbun run dev:website- Run the documentation website locally
bun run test- Run all unit tests via Turbobun run test:unit- Run unit tests directly with Vitest- Tests use Vitest with
globals: true, so no need to importdescribe,it,expect - Test files:
test/**/*.test.tsandsrc/**/*.test.ts
bun run lint- Run Biome linter and formatter with auto-fix
bunx changeset- Create a new changeset for versioningbun run release- Build and publish to npm (requires proper setup)bun run build:pack- Build and create npm tarball for testing
The build uses a custom Bun-based bundler from @enalmada/bun-externals:
build:clear- Removes thedist/directory (cross-platform Node.js script)build:script- Bundles all source files fromsrc/using Bun with all dependencies marked as externalbuild:declaration- Generates TypeScript declaration files usingtsc
The build script (build.ts) automatically discovers all source files and bundles them, externalizing all dependencies. Turbo orchestrates the build with proper dependency chaining.
- Module format: ES modules (
"type": "module") - Entry points:
main:dist/index.jstypes:dist/index.d.tsexports: Modern exports field with types/import/default conditions
- Tree-shaking:
"sideEffects": falsefor better optimization - Files: Only
dist/is published to npm
src/- All TypeScript source files (template includes justindex.tsplaceholder)dist/- Build output (gitignored, only published to npm)test/- Test files using*.test.tsnaming conventionbuild.ts- Custom build script using@enalmada/bun-externals
- Target: ES2022 with ES modules
- Module Resolution:
Bundler(modern, optimized for bundlers like Bun) - Path alias:
@/*maps to./src/*(configured in bothtsconfig.jsonandvitest.config.ts) - Strict mode with additional strictness:
strictNullChecks,noImplicitAny,noUnusedLocalsexactOptionalPropertyTypesfor stricter optional property handlingisolatedModulesfor better build performance
- Declaration files generated separately from bundling
- Replaces ESLint and Prettier for both linting and formatting
- Configuration:
biome.jsonc(supports comments) - Formatting:
- Tabs for indentation
- Double quotes
- 120 character line width
- Trailing commas: all for JS/TS, none for JSON
- Import organization: Enabled via
assist.actions.source.organizeImports: "on" - Linter rules:
noUnusedImportsset to error - VCS integration enabled to respect .gitignore
Pre-commit hooks run in parallel (parallel: true) for performance:
-
type-check: Validates TypeScript on staged
.ts/.tsxfiles- Runs:
bun run type-check - Fail message provides instructions to fix errors
- Runs:
-
lint: Runs Biome check with auto-fix on staged files
- Runs:
biome check --fix --unsafe {staged_files} - Auto-stages fixed files (
stage_fixed: true) - Fail message indicates most issues are auto-fixed
- Runs:
-
package-fix: Normalizes
package.jsonwhen modified- Runs:
npm pkg fix && fixpack - Ensures consistent package.json ordering
- Runs:
All hooks provide custom fail messages for better developer experience.
Uses Turbo for task orchestration and caching:
- Build tasks: Dependency chain ensures
build:clear→build:script→build:declaration - Input tracking: Each task specifies which files invalidate its cache
lint: Source files +biome.jsonctest:unit: Source/test files +vitest.config.tstype-check: Source files +tsconfig.json
- Output tracking: Build tasks declare
dist/**as output - Caching: All tasks cached except
build:clear(always runs)
- Framework: Vitest
- Configuration:
vitest.config.ts - Test pattern:
test/**/*.test.tsandsrc/**/*.test.ts - Globals enabled: No need to import
describe,it,expect - Path alias
@configured for imports in tests - Watch mode available:
vitest --watchor append--watchto test commands
Uses Changesets for version management:
- Create changeset:
bunx changeset - Changesets committed to
.changeset/directory - CI automatically creates version PRs via GitHub Actions
- Merge version PR to trigger release workflow
- Release workflow builds and publishes to npm
- Run Tests (
run-tests.yml): Runs on push/PR to main - Release (
release.yml): Publishes to npm on push to main (requiresNPM_TOKENsecret) - Changesets Renovate (
changesets-renovate.yml): Automatically creates changesets for Renovate PRs
Renovate configuration (renovate.json):
- Auto-merges major versions (consider changing to minor/patch only)
- Groups all updates together
- 3-day minimum release age for stability
- Auto-merge scheduled for early Mondays
When using this template to create a new npm module:
- Update
package.json: name, description, author, repository, homepage - Replace
src/index.tswith your module code - Add tests to
test/directory - Update
README.mdwith module-specific documentation - Configure npm publishing: Add
NPM_TOKENto GitHub secrets - Run
bun run checkbefore commits to ensure quality