Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .biomeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
lib
dist
**/fixtures/**
src/fixtures
**/*.test.ts
**/*.map
13 changes: 13 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"permissions": {
"allow": [
"Bash(npm test)",
"Bash(npm test:*)",
"Bash(pnpm exec:*)",
"Bash(pnpm lint:*)",
"Bash(pnpm biome:ci:*)",
"Bash(grep:*)"
],
"deny": []
}
}
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

452 changes: 0 additions & 452 deletions .eslintrc.js

This file was deleted.

35 changes: 22 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
name: CI

on:
- push
- pull_request
push:
branches: [ main, modernize-repo ]
pull_request:
branches: [ main ]

jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
- 12
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test
46 changes: 46 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Pre-release

on:
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened]

jobs:
build-and-publish:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test

- name: Get PR commit count
id: pr_commits
run: |
count=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits | length')
echo "commit_count=$count" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}

- name: Update version for pre-release
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
PRERELEASE_VERSION="${PACKAGE_VERSION}-pr${{ github.event.number }}.${{ steps.pr_commits.outputs.commit_count }}"
npm version $PRERELEASE_VERSION --no-git-tag-version
echo "Publishing version: $PRERELEASE_VERSION"

- name: Publish pre-release to npm
run: pnpm publish --tag pr --no-git-checks --no-otp
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v3
with:
version: latest
run_install: true
- run: pnpm typecheck
- run: pnpm lint
- run: pnpm build
- name: Run tests
run: pnpm test
- run: pnpm publish --no-git-checks --no-otp
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules/
.yarnrc


fixutres/main.*
8 changes: 0 additions & 8 deletions .prettierignore

This file was deleted.

114 changes: 114 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Commands

### Installation

```bash
# Install dependencies
pnpm install
```

### Development

```bash
# Start the CLI tool with ts-node (for development)
pnpm start
```

### Build

```bash
# Build the project (outputs to ./lib)
pnpm build
```

### Testing

```bash
# 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 format
```

## Module System

This project uses ECMAScript Modules (ESM). Key implications:

- Import statements require file extensions (e.g., `import { foo } from './bar.js'`)
- The `package.json` includes `"type": "module"` to indicate ESM usage
- TypeScript is configured with `"module": "NodeNext"` and `"moduleResolution": "NodeNext"`

## Project Structure

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.

### Architecture

The project has a modular architecture with these key components:

1. **CLI Interface** (`src/cli/`) - Handles command-line arguments and outputs results
2. **Source Map Loading** (`src/load-source-map/`) - Loads source maps from filesystem or web URLs
3. **File Size Comparison** (`src/compare-file-sizes/`) - Compares file sizes between two source maps
4. **Tree Generation** (`src/generate-tree/`) - Converts comparison data into tree visualizations
5. **Core Module** (`src/source-map-diff.ts`) - Orchestrates the process and exposes the main API

### Core Workflow

1. Load source maps from provided locations (local files or URLs)
2. Parse the source maps to extract file sizes
3. Compare file sizes between the two source maps
4. Generate a tree visualization of the differences
5. Output the results in the requested format (HTML, JSON, or console)

### API Functions

- `sourceMapDiff({ currentSrc, previousSrc })` - Returns raw comparison data
- `sourceMapDiffAsHtml({ currentSrc, previousSrc })` - Returns HTML visualization
- `sourceMapDiffForConsole({ currentSrc, previousSrc })` - Returns console-friendly output

## Usage Examples

### CLI Usage

```bash
# 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 json
```

### API Usage

```typescript
import { 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' });
```
Loading