This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SmartBundle is a zero-configuration library bundler that builds JavaScript/TypeScript packages for any environment. It automatically generates ESM and CommonJS bundles with TypeScript definitions, React support, and Babel transformations.
pnpm test- Run unit tests for src/ directory using Vitestpnpm test:update-snapshots- Update test snapshots (pnpm test -- -u)pnpm test:e2e- Run end-to-end tests using Docker containerspnpm test:e2e-update-snapshots- Update e2e test snapshots
- Use
pnpmas the package manager (required, specified in engines) - No lint/typecheck commands defined - check directly with TypeScript compiler if needed
The main build function orchestrates a pipeline of tasks:
- Package Analysis - Parse and validate package.json (
src/packageJson.ts) - Module Detection - Identify TypeScript, Babel, React dependencies (
src/detectModules.ts) - Vite Configuration - Generate build config with appropriate plugins (
src/createViteConfig.ts) - Parallel Task Execution - Run multiple build tasks concurrently:
- Static Files - Copy README, LICENSE, etc. (
src/tasks/copyStaticFilesTask.ts) - TypeScript Compilation - Generate .d.ts files (
src/tasks/buildTypesTask/) - JavaScript Bundling - Vite build for ESM/CJS (
src/tasks/viteTask.ts) - Binary Processing - Handle CLI binaries (
src/tasks/binsTask.ts)
- Static Files - Copy README, LICENSE, etc. (
- Imports Plugin - Handles external dependency resolution
- React Plugin - JSX transformations (modern/legacy modes)
- Babel Plugin - Custom Babel transformations when babel.config.js exists
- Detection - Identify pnpm workspace configurations (
src/monorepo/parseMonorepo/) - Link Packages - Create reference packages for bundled outputs (
src/monorepo/link.ts) - Binary:
smartbundle-monorepo-link- Creates link packages for-sbsourcessuffixed packages
- Main CLI:
src/run.ts- Handles errors and pretty printing with Youch - Library API:
src/index.ts- Exportsrun()anddefineViteConfig()functions - Monorepo CLI:
src/monorepo/link.ts- Separate binary for monorepo link management
- Unit Tests - Test individual functions and components with Vitest
- Snapshot Tests - Validate build outputs in
src/__dir_snapshots__/ - E2E Tests - Docker-based tests for different Node.js versions, bundlers (Webpack, Rspack, Metro), and package managers
- Fixtures - Test scenarios in
src/fixtures/cover edge cases and bug reproductions
- Task Pipeline - Uses
src/pipeline.tsfor parallel/sequential task execution - Error Handling - Custom error types (
src/error.ts,src/PrettyErrors.ts) with formatted output - Directory Resolution - Consistent path handling via
src/resolveDirs.ts - Package.json Processing - Strict validation and transformation for build outputs
vitest.config.ts- Uses the same Vite config as the library for consistencytsconfig.json- TypeScript configurationbuildTsconfig.json- Separate config for building type definitions
Read relevant documentation files based on the task at hand:
README.md- Project overview, quick start guide, features, and compatibility matrix. Reference for initial setup and understanding SmartBundle's value proposition.CLAUDE.md- This file. Instructions for AI assistants working with the codebase.
docs/monorepo.md- Comprehensive monorepo support guide with pnpm workspaces,-sbsourcesnaming convention, and link package system. Essential for monorepo setup and troubleshooting.docs/package-json.md- Strict package.json requirements including banned fields (files, main, module) and required fields (private: true, type: module). Critical for package configuration.docs/react.md- React integration with automatic JSX transformation detection (React < 17 uses createElement, >= 17 uses new runtime). Reference for React library builds.docs/ts-guide.md- TypeScript integration requirements, especially mandatoryverbatimModuleSyntax: truesetting. Essential for TypeScript project setup.
docs/issues.md- Known issues documentation, specifically @babel/core installation problems in versions < v0.11.1. Reference when users report issues.
prompts/docs.md- Documentation writing guidelines for consistent SmartBundle documentation with specific structure and GitHub Markdown formatting.prompts/test.md- Testing guidelines using Vitest with vitest-directory-snapshot, fixture structure, and SmartBundle compliance requirements.
src/monorepo/README.md- Technical documentation for monorepo implementation including re-export system, version control strategy, and troubleshooting. Reference for understanding or extending monorepo functionality.