Skip to content

refactor: Migrate to Biome and TypeScript, Modernize Project Structure #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 3, 2025

Conversation

mikechu-optimizely
Copy link
Collaborator

Changes

This PR introduces several significant improvements to the codebase:

1. Development Environment

  • Migrated from Prettier to Biome for code formatting and linting
  • Added VSCode configuration with recommended extensions
  • Added .nvmrc to standardize Node.js version (v22)

2. TypeScript Migration

  • Converted adapter classes to TypeScript:
    • Properly typed imports for CookieOptions and CDNSettings
    • Removed type prefix from imports where unnecessary
    • Standardized import ordering

3. Project Structure

  • Created a new build system for CDN-specific builds:
    • Added build/cloudflare.ts and build/vercel.ts for targeted builds
    • Configured Vite for ESM output with proper external dependencies

4. Code Quality

  • Updated Biome configuration with standardized rules:
    • Set line width to 100 characters
    • Configured tab-based indentation
    • Enabled single quotes and trailing commas
    • Enabled recommended linting rules

5. Legacy Code Management

  • Moved older adapter implementations to src/legacy/ directory
  • Preserved original functionality while preparing for new TypeScript implementations

Testing

The changes have been tested locally with Biome's formatting and linting tools. Build configurations have been verified to produce correct output for each CDN target.

Migration Notes

  • Developers should install the recommended VSCode extensions
  • Run biome check --apply to format code according to new standards
  • Use Node.js v22 as specified in .nvmrc

- Add tsconfig.json with ES modules and edge worker settings
- Add TypeScript dependencies
- Update all dependencies to latest versions
- Fix mismatched quotes in Cloudflare adapter
- Fix mismatched quotes in Akamai adapter
- Fix mismatched quotes in CloudFront adapter
- Remove npm-specific files and prettier
- Add pnpm as package manager
- Add Biome for formatting and linting
- Update scripts in package.json
- Update schema to latest version 1.9.4
- Disable VCS integration
- Set tab indentation
- Configure JavaScript quote style and trailing comma
- Remove dist ignore as it's handled by .gitignore
- Add ignore patterns for generated and IDE directories
- Apply Biome formatting across the codebase
- Format biome.json configuration
- Set Biome as default formatter for all relevant file types
- Add support for React file extensions (jsx/tsx)
- Enable format on save
- Add recommended extensions:
  - biomejs.biome for formatting and linting
  - eamodio.gitlens for Git integration
  - vitest.explorer for test running
  - jeanp413.open-remote-wsl for WSL support
- Add CDN adapter interfaces for request/response handling
- Add KVStore interface for key-value operations
- Add Optimizely configuration and user context interfaces
- Create types barrel file for clean imports
- Add CDNAdapterFactory with singleton pattern
- Create BaseAdapter with common cookie handling
- Add type-safe adapter registration and creation
- Implement cookie serialization and parsing utilities
- Create CloudflareAdapter class extending BaseAdapter
- Add Cloudflare-specific types for env and context
- Implement cookie handling methods
- Add basic request handling structure
- Export adapter through index files
- Add CDN settings and event batch settings types
- Implement KV-based caching with TTL support
- Add event queuing and batched event dispatch
- Handle caching requests with origin fallback
- Add cache key generation and response serialization
- Add core type definitions for requests, decisions, and settings
- Create CoreLogic class with TypeScript types
- Implement initial set of methods with proper typing
- Add dependency injection pattern for better testability
- Add main request processing pipeline
- Implement visitor ID handling with multiple sources
- Add datafile retrieval with KV storage caching
- Add Optimizely initialization with error handling
- Improve type safety for all methods
- Add response preparation for both origin and local responses
- Add header management for visitor ID and decisions
- Add cookie management with proper security settings
- Add error handling for origin forwarding
- Improve type safety for response handling
- Add flag decision handling with validation
- Add cookie parsing and security measures
- Add error handling utilities
- Add type guards and validation
- Add comprehensive logging
- Add proper type definitions for Optimizely SDK
- Add interfaces for events and decisions
- Add type safety for user profiles and attributes
- Add error handling and logging
- Add UserProfile and CacheData interfaces
- Add type safety for KV store operations
- Add proper return types for all methods
- Add readonly modifiers for immutable properties
- Improve error handling and logging
- Add EventType union type for event names
- Add EventListener type for listener functions
- Add EventListenersMap for type-safe event mapping
- Add new utility methods for event management
- Add improved error handling and type safety
- Add interfaces for event parameters
- Add type safety for all event handlers
- Add proper typing for request and response objects
- Add type definitions for all event listeners
- Add improved error handling and logging
- Add interfaces for CdnProvider, FetchOptions, CookieOptions, and Decision
- Add type safety for all helper functions
- Add proper return types and parameter types
- Add improved error handling with type checking
- Add type guards for JSON parsing and validation
- Add interfaces for CDN providers and headers
- Add type safety for response handling
- Add proper typing for environment variables
- Add type definitions for KV store operations
- Add improved error handling with type checking
- Upgrade @biomejs/biome to 1.9.4
- Upgrade @vercel/edge to 1.2.0
- Upgrade vite to 6.0.7
- Set Node.js version to v22 in .nvmrc
Renamed to better reflect its role as a concrete implementation of IKVStore rather than an interface definition. Updated related imports and documentation.
* Add KVStore exports to all adapter index files
* Implement missing cookie methods in FastlyAdapter
* Add constructor and KVStore initialization to all adapters
* Update adapter class documentation
* Replace forEach with for...of loop in BaseAdapter
@mikechu-optimizely mikechu-optimizely merged commit dda211e into main Jan 3, 2025
1 check failed
@mikechu-optimizely mikechu-optimizely deleted the feature/typescript-initial-setup branch January 3, 2025 18:11
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