This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Install dependencies
pnpm install# Start the CLI tool with ts-node (for development)
pnpm start# Build the project (outputs to ./lib)
pnpm build# Run all tests and linting
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run specific test file
pnpm vitest run path/to/test-file.test.ts
# Run tests with coverage
pnpm vitest run --coverage
# Run linting
pnpm lint
# Format code
pnpm formatThis project uses ECMAScript Modules (ESM). Key implications:
- Import statements require file extensions (e.g.,
import { foo } from './bar.js') - The
package.jsonincludes"type": "module"to indicate ESM usage - TypeScript is configured with
"module": "NodeNext"and"moduleResolution": "NodeNext"
Source Map Diff is a utility that compares JavaScript source maps to understand why a bundle's size changed. It can analyze sourcemaps from local files or web URLs and provides output in HTML, JSON, or console formats.
The project has a modular architecture with these key components:
- CLI Interface (
src/cli/) - Handles command-line arguments and outputs results - Source Map Loading (
src/load-source-map/) - Loads source maps from filesystem or web URLs - File Size Comparison (
src/compare-file-sizes/) - Compares file sizes between two source maps - Tree Generation (
src/generate-tree/) - Converts comparison data into tree visualizations - Core Module (
src/source-map-diff.ts) - Orchestrates the process and exposes the main API
- Load source maps from provided locations (local files or URLs)
- Parse the source maps to extract file sizes
- Compare file sizes between the two source maps
- Generate a tree visualization of the differences
- Output the results in the requested format (HTML, JSON, or console)
sourceMapDiff({ currentSrc, previousSrc })- Returns raw comparison datasourceMapDiffAsHtml({ currentSrc, previousSrc })- Returns HTML visualizationsourceMapDiffForConsole({ currentSrc, previousSrc })- Returns console-friendly output
# Compare two local source maps
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js
# Compare with HTML output format
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js --format html
# Compare with JSON output format
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js --format jsonimport { sourceMapDiff, sourceMapDiffAsHtml, sourceMapDiffForConsole } from 'source-map-diff';
// Get raw comparison data
const data = await sourceMapDiff({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });
// Get HTML output
const html = await sourceMapDiffAsHtml({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });
// Get console-friendly output
const consoleOutput = await sourceMapDiffForConsole({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });