Skip to content

Migrate from JavaScript to TypeScript with Vite + Vitest#160

Merged
w8r merged 19 commits intomasterfrom
typescript-vite-migration
Dec 3, 2025
Merged

Migrate from JavaScript to TypeScript with Vite + Vitest#160
w8r merged 19 commits intomasterfrom
typescript-vite-migration

Conversation

@w8r
Copy link
Owner

@w8r w8r commented Jul 21, 2025

Summary

  • Complete migration from JavaScript to TypeScript with modern tooling
  • Vite build system replaces Rollup for faster development and building
  • Vitest test runner replaces tape for modern testing experience
  • Bundled TypeScript declarations in single file for cleaner distribution
  • Working demo updated to use new build system
  • 22 passing tests converted from tape to Vitest format

Key Changes

Build System

  • Before: Rollup + Buble + tape
  • After: Vite + TypeScript + Vitest
  • Result: Faster builds, better DX, modern tooling

Output Files

  • dist/martinez.js - ES module build
  • dist/martinez.cjs - CommonJS build
  • dist/index.d.ts - Single bundled TypeScript declarations file

Scripts

  • npm run build - Build library with Vite
  • npm run test - Run tests in watch mode
  • npm run test:run - Run tests once
  • npm run dev - Start dev server with demo
  • npm run typecheck - Type checking

Source Code

  • All 18 JavaScript files converted to TypeScript with proper typing
  • Maintained 100% API compatibility
  • Added comprehensive type definitions for geometric operations

Testing

  • 4 test files converted from tape to Vitest (22 tests passing)
  • 7 additional test files remain to be converted
  • Modern expect/describe/it syntax

Test Plan

  • Library builds successfully: npm run build
  • Tests pass: npm run test:run ✅ (22/22)
  • Demo works: npm run dev
  • TypeScript declarations generated correctly ✅
  • ES module and CommonJS outputs created ✅
  • No breaking changes to public API ✅

Breaking Changes

None - fully backward compatible API

🤖 Generated with Claude Code

w8r and others added 5 commits July 21, 2025 15:52
- 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 <[email protected]>
- 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 <[email protected]>
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 <[email protected]>
✅ 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 <[email protected]>
@w8r w8r requested a review from Copilot December 3, 2025 06:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the Martinez polygon clipping library from JavaScript to TypeScript with modern tooling. The migration replaces Rollup/Buble/tape with Vite/Vitest while maintaining full API compatibility. All source files have been converted to TypeScript with proper type definitions, and a bundled TypeScript declarations file is now generated for distribution.

Key Changes:

  • Complete TypeScript conversion of 18 source files with comprehensive type definitions
  • Modern build system using Vite for faster development and building
  • Vitest test framework replacing tape with 22 passing tests converted
  • Simplified distribution with bundled TypeScript declarations

Reviewed changes

Copilot reviewed 39 out of 42 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
vite.config.ts Configures Vite build with library mode, ES/CJS outputs, and TypeScript declaration bundling
vitest.config.ts Configures Vitest test runner with Node environment and test file patterns
package.json Updates build scripts, dependencies, and export paths for new tooling
src/types.ts Defines core TypeScript types for geometric operations
src/*.ts TypeScript conversions of all source modules with proper type annotations
test/*.test.ts Converts test files from tape to Vitest format
oxlint.json Configures oxlint for TypeScript and code quality checks
index.ts Updates main entry point with TypeScript types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@w8r
Copy link
Owner Author

w8r commented Dec 3, 2025

closes #156

@w8r w8r merged commit cef5b3e into master Dec 3, 2025
2 checks passed
@w8r w8r deleted the typescript-vite-migration branch December 3, 2025 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments