Skip to content

Migrate to TypeScript and modernize build tooling#2

Open
codeKonami wants to merge 1 commit intomasterfrom
claude/explain-codebase-mlxz6j1jubrj7hau-jYm5a
Open

Migrate to TypeScript and modernize build tooling#2
codeKonami wants to merge 1 commit intomasterfrom
claude/explain-codebase-mlxz6j1jubrj7hau-jYm5a

Conversation

@codeKonami
Copy link
Owner

Summary

This PR modernizes the poker hand evaluator by migrating the codebase from JavaScript to TypeScript, replacing the webpack/babel build system with Vite, and updating the test framework from Jest to Vitest.

Key Changes

  • Language Migration: Converted all source files from JavaScript to TypeScript with full type safety

    • src/pokerhand.jssrc/poker-hand.ts with proper type annotations
    • Utility modules reorganized into src/evaluate/ directory with typed implementations
    • Added comprehensive type definitions in src/types.ts (HandRank and CompareResult enums, card types)
  • Build System Modernization:

    • Replaced webpack + babel with Vite for faster builds and better ES module support
    • Updated package.json to export both ESM and CommonJS formats with proper entry points
    • Added TypeScript configuration with strict mode enabled
    • Removed old build configuration files (webpack.config.js, .babelrc)
  • Testing Framework: Migrated from Jest to Vitest

    • Updated all test files to use Vitest syntax and imports
    • Tests now use ES module imports instead of CommonJS requires
  • Code Organization:

    • Consolidated lookup tables into src/tables/ directory with TypeScript exports
    • Separated concerns: evaluate/card.ts, evaluate/validate.ts, evaluate/rank.ts, evaluate/evaluate.ts
    • Added src/bench.ts as TypeScript replacement for the benchmark script
  • API Improvements:

    • compareWith() now returns typed CompareResult enum instead of magic numbers (1, 2, 3)
    • getRank() returns typed HandRank enum instead of string literals
    • Better error handling with more descriptive validation messages
    • Added src/index.ts as clean public API export
  • HTML/Demo Updates:

    • Updated index.html to use ES module imports
    • Improved HTML semantics (added lang attribute, self-closing tags)
    • Updated demo to use typed CompareResult enum for result comparison
  • Development Experience:

    • Added npm run dev for local development with Vite
    • Added npm run bench for running benchmarks with tsx
    • Added npm run test:watch for watch mode testing

Notable Implementation Details

  • Maintained full backward compatibility with the Cactus Kev algorithm implementation
  • All lookup tables remain unchanged, only converted to TypeScript exports
  • Type-safe card validation with literal types for Rank and Suit
  • Proper TypeScript strict mode compliance throughout

https://claude.ai/code/session_015nKLAdA1Gva9Yg4Rnfu2vR

Replace legacy Babel 6 / Webpack 3 / Jest toolchain with a modern stack:
- TypeScript (strict mode) for type safety and shipped .d.ts declarations
- Vite 5 in library mode for ESM + CJS output (replaces Webpack + UglifyJS)
- Vitest for unit testing (replaces Jest)

Architecture improvements:
- src/types.ts: HandRank/CompareResult enums, Card/Rank/Suit types
- src/tables/: typed lookup tables (was src/arrays/)
- src/evaluate/: pure evaluation functions (was src/utils/)
- src/poker-hand.ts: PokerHand class with full type annotations
- src/index.ts: clean public API entry point

All 28 original tests ported and passing. Public API preserved.

https://claude.ai/code/session_015nKLAdA1Gva9Yg4Rnfu2vR
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.

2 participants