Skip to content

Commit d2b2b52

Browse files
authored
modernize repo - esm, vitest, biome (#246)
migrate to esm, use vitest, biome, speed everything up. API is still the same.
1 parent 45ceab0 commit d2b2b52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+9834
-7009
lines changed

.biomeignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
lib
3+
dist
4+
**/fixtures/**
5+
src/fixtures
6+
**/*.test.ts
7+
**/*.map

.claude/settings.local.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(npm test)",
5+
"Bash(npm test:*)",
6+
"Bash(pnpm exec:*)",
7+
"Bash(pnpm lint:*)",
8+
"Bash(pnpm biome:ci:*)",
9+
"Bash(grep:*)"
10+
],
11+
"deny": []
12+
}
13+
}

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 452 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
name: CI
2+
23
on:
3-
- push
4-
- pull_request
4+
push:
5+
branches: [ main, modernize-repo ]
6+
pull_request:
7+
branches: [ main ]
8+
59
jobs:
610
test:
7-
name: Node.js ${{ matrix.node-version }}
811
runs-on: ubuntu-latest
912
strategy:
10-
fail-fast: false
1113
matrix:
12-
node-version:
13-
- 14
14-
- 12
14+
node-version: [20.x, 22.x, 24.x]
15+
1516
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v1
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
- run: npm install
21-
- run: npm test
17+
- uses: actions/checkout@v4
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- uses: pnpm/action-setup@v3
23+
with:
24+
version: latest
25+
run_install: true
26+
- run: pnpm typecheck
27+
- run: pnpm lint
28+
- run: pnpm build
29+
- name: Run tests
30+
run: pnpm test

.github/workflows/prerelease.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish Pre-release
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
- uses: pnpm/action-setup@v3
19+
with:
20+
version: latest
21+
run_install: true
22+
- run: pnpm typecheck
23+
- run: pnpm lint
24+
- run: pnpm build
25+
- name: Run tests
26+
run: pnpm test
27+
28+
- name: Get PR commit count
29+
id: pr_commits
30+
run: |
31+
count=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits | length')
32+
echo "commit_count=$count" >> "$GITHUB_OUTPUT"
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
36+
- name: Update version for pre-release
37+
run: |
38+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
39+
PRERELEASE_VERSION="${PACKAGE_VERSION}-pr${{ github.event.number }}.${{ steps.pr_commits.outputs.commit_count }}"
40+
npm version $PRERELEASE_VERSION --no-git-tag-version
41+
echo "Publishing version: $PRERELEASE_VERSION"
42+
43+
- name: Publish pre-release to npm
44+
run: pnpm publish --tag pr --no-git-checks --no-otp
45+
env:
46+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: '20.x'
15+
registry-url: 'https://registry.npmjs.org'
16+
- uses: pnpm/action-setup@v3
17+
with:
18+
version: latest
19+
run_install: true
20+
- run: pnpm typecheck
21+
- run: pnpm lint
22+
- run: pnpm build
23+
- name: Run tests
24+
run: pnpm test
25+
- run: pnpm publish --no-git-checks --no-otp
26+
env:
27+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ node_modules/
1212
.yarnrc
1313

1414

15+
fixutres/main.*

.prettierignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

CLAUDE.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Commands
6+
7+
### Installation
8+
9+
```bash
10+
# Install dependencies
11+
pnpm install
12+
```
13+
14+
### Development
15+
16+
```bash
17+
# Start the CLI tool with ts-node (for development)
18+
pnpm start
19+
```
20+
21+
### Build
22+
23+
```bash
24+
# Build the project (outputs to ./lib)
25+
pnpm build
26+
```
27+
28+
### Testing
29+
30+
```bash
31+
# Run all tests and linting
32+
pnpm test
33+
34+
# Run tests in watch mode
35+
pnpm test:watch
36+
37+
# Run specific test file
38+
pnpm vitest run path/to/test-file.test.ts
39+
40+
# Run tests with coverage
41+
pnpm vitest run --coverage
42+
43+
# Run linting
44+
pnpm lint
45+
46+
# Format code
47+
pnpm format
48+
```
49+
50+
## Module System
51+
52+
This project uses ECMAScript Modules (ESM). Key implications:
53+
54+
- Import statements require file extensions (e.g., `import { foo } from './bar.js'`)
55+
- The `package.json` includes `"type": "module"` to indicate ESM usage
56+
- TypeScript is configured with `"module": "NodeNext"` and `"moduleResolution": "NodeNext"`
57+
58+
## Project Structure
59+
60+
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.
61+
62+
### Architecture
63+
64+
The project has a modular architecture with these key components:
65+
66+
1. **CLI Interface** (`src/cli/`) - Handles command-line arguments and outputs results
67+
2. **Source Map Loading** (`src/load-source-map/`) - Loads source maps from filesystem or web URLs
68+
3. **File Size Comparison** (`src/compare-file-sizes/`) - Compares file sizes between two source maps
69+
4. **Tree Generation** (`src/generate-tree/`) - Converts comparison data into tree visualizations
70+
5. **Core Module** (`src/source-map-diff.ts`) - Orchestrates the process and exposes the main API
71+
72+
### Core Workflow
73+
74+
1. Load source maps from provided locations (local files or URLs)
75+
2. Parse the source maps to extract file sizes
76+
3. Compare file sizes between the two source maps
77+
4. Generate a tree visualization of the differences
78+
5. Output the results in the requested format (HTML, JSON, or console)
79+
80+
### API Functions
81+
82+
- `sourceMapDiff({ currentSrc, previousSrc })` - Returns raw comparison data
83+
- `sourceMapDiffAsHtml({ currentSrc, previousSrc })` - Returns HTML visualization
84+
- `sourceMapDiffForConsole({ currentSrc, previousSrc })` - Returns console-friendly output
85+
86+
## Usage Examples
87+
88+
### CLI Usage
89+
90+
```bash
91+
# Compare two local source maps
92+
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js
93+
94+
# Compare with HTML output format
95+
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js --format html
96+
97+
# Compare with JSON output format
98+
pnpm run start --previousSrc path/to/old-file.js --currentSrc path/to/new-file.js --format json
99+
```
100+
101+
### API Usage
102+
103+
```typescript
104+
import { sourceMapDiff, sourceMapDiffAsHtml, sourceMapDiffForConsole } from 'source-map-diff';
105+
106+
// Get raw comparison data
107+
const data = await sourceMapDiff({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });
108+
109+
// Get HTML output
110+
const html = await sourceMapDiffAsHtml({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });
111+
112+
// Get console-friendly output
113+
const consoleOutput = await sourceMapDiffForConsole({ previousSrc: 'path/to/old-file.js', currentSrc: 'path/to/new-file.js' });
114+
```

0 commit comments

Comments
 (0)