Skip to content

Commit cef5b3e

Browse files
w8rclaudeCopilot
authored
Migrate from JavaScript to TypeScript with Vite + Vitest (#160)
* Migrate from JavaScript to TypeScript with Vite + Vitest - Convert all JavaScript source files to TypeScript with proper typing - Replace Rollup build system with Vite for faster development - Replace tape test runner with Vitest for modern testing - Bundle TypeScript declarations into single file - Update demo to work with new build system - Maintain backward compatibility with existing API New build outputs: - dist/martinez.js (ES module) - dist/martinez.cjs (CommonJS) - dist/index.d.ts (bundled TypeScript declarations) Scripts: - npm run build: Build library - npm run test: Run tests with Vitest - npm run dev: Start dev server with demo - npm run typecheck: Type checking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Replace ESLint with oxlint for faster linting - Remove ESLint, TypeScript ESLint plugins, and related dependencies - Add oxlint (Rust-based linter) for significantly faster performance - Configure oxlint with TypeScript support and reasonable rule set - Maintain code quality standards while improving build speed Performance improvement: - ESLint: ~2-3 seconds on 18 files - oxlint: 9ms on 18 files with 96 rules using 8 threads 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix TypeScript build errors in core library files TypeScript fixes: - Fix BBox type from interface to tuple [number, number, number, number] - Fix connectEdges function call signature (remove unused operation parameter) - Fix variable type conflicts in connect_edges.ts (separate tmpEvent and tmpPos) - Add proper null assertion operators for guaranteed non-null properties Build verification: - ✅ Build completes successfully: dist/martinez.js, dist/martinez.cjs, dist/index.d.ts - ✅ All 22 tests pass with Vitest - ✅ Library functions correctly - ✅ Main TypeScript errors resolved Remaining errors are only in debug utilities and test files, not in core library. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Convert all remaining tests from tape to Vitest ✅ Successfully converted 7 additional test files: - compute_fields.test.js → compute_fields.test.ts (1 test) - featureTypes.test.js → featureTypes.test.ts (16 tests) - genericTestCases.test.js → genericTestCases.test.ts (27 tests) - index.test.js → index.test.ts (14 tests) - segment_intersection.test.js → segment_intersection.test.ts (11 tests) - sweep_event.test.js → sweep_event.test.ts (6 tests) - sweep_line.test.js → sweep_line.test.ts (1 test) 🎯 Test migration results: - **Before**: 22 tests passing (4 converted files) - **After**: 98 tests passing (11 converted files) - **Improvement**: 76 additional tests (+345% increase) 🔧 Key changes: - Converted complex nested tape test structures to proper Vitest describe/it blocks - Updated all assertions from tape to Vitest expect syntax - Added TypeScript support with proper type assertions - Added glob dependency for file system test discovery - Fixed import statements for modern package versions - Maintained all original test logic and fixtures All tests now run with Vitest and provide comprehensive coverage of the martinez polygon clipping library functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update vite.config.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/compare_segments.test.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/genericTestCases.test.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/genericTestCases.test.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Tests, benchmarks * New demo * Nojekyll * Packages * More tests from #156 * npmrc * Stricter ts * Fixed the queue * Fixed the demo * Bumped the version --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3d55204 commit cef5b3e

File tree

80 files changed

+6404
-9232
lines changed

Some content is hidden

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

80 files changed

+6404
-9232
lines changed

.eslintrc

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

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

bench.js

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

bench/martinez.bench.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, bench } from 'vitest';
2+
import { readFileSync } from 'fs';
3+
import { join } from 'path';
4+
import jstsUnion from '@turf/union';
5+
import * as martinez from '../index';
6+
7+
/**
8+
* Benchmark Results
9+
*
10+
* Previous results with Benchmark.js:
11+
* Hole_Hole x 13,345 ops/sec ±2.13% (91 runs sampled)
12+
* Hole_Hole - JSTS x 1,724 ops/sec ±4.80% (87 runs sampled)
13+
* Asia x 6.32 ops/sec ±3.16% (20 runs sampled)
14+
* Asia - JSTS x 6.62 ops/sec ±2.74% (21 runs sampled)
15+
*/
16+
17+
// Helper to load JSON files
18+
const loadJSON = (filePath: string) => JSON.parse(readFileSync(filePath, 'utf-8'));
19+
20+
// Load test fixtures
21+
const hole_hole = loadJSON(join(__dirname, '../test/fixtures/hole_hole.geojson'));
22+
const asia = loadJSON(join(__dirname, '../test/fixtures/asia.geojson'));
23+
const unionPoly = loadJSON(join(__dirname, '../test/fixtures/asia_unionPoly.geojson'));
24+
const states = loadJSON(join(__dirname, '../test/fixtures/states_source.geojson'));
25+
26+
describe('Hole_Hole union', () => {
27+
bench('Martinez', () => {
28+
martinez.union(
29+
hole_hole.features[0].geometry.coordinates,
30+
hole_hole.features[1].geometry.coordinates
31+
);
32+
});
33+
34+
bench('JSTS', () => {
35+
jstsUnion(hole_hole.features[0], hole_hole.features[1]);
36+
});
37+
});
38+
39+
describe('Asia union', () => {
40+
bench('Martinez', () => {
41+
martinez.union(
42+
asia.features[0].geometry.coordinates,
43+
unionPoly.geometry.coordinates
44+
);
45+
});
46+
47+
bench('JSTS', () => {
48+
jstsUnion(asia.features[0], unionPoly);
49+
});
50+
});
51+
52+
describe('States clip', () => {
53+
bench('Martinez', () => {
54+
martinez.union(
55+
states.features[0].geometry.coordinates,
56+
states.features[1].geometry.coordinates
57+
);
58+
});
59+
60+
bench('JSTS', () => {
61+
jstsUnion(states.features[0], states.features[1]);
62+
});
63+
});

0 commit comments

Comments
 (0)