UNPKG

@rbac/rbac

Version:

Blazing Fast, Zero dependency, Hierarchical Role-Based Access Control for Node.js

75 lines (57 loc) 3.34 kB
# Implementation Plan: Logger Color Detection ## Overview This implementation plan converts the logger color detection design into discrete coding tasks. The approach focuses on adding color support detection to the existing `defaultLogger` function in `src/helpers.ts` while maintaining backward compatibility. The implementation will be incremental, with testing integrated at each step to catch errors early. ## Tasks - [x] 1. Implement color support detection function - Create `supportsColor()` function that checks environment variables and TTY status - Implement caching mechanism for detection result - Handle FORCE_COLOR, NO_COLOR, and TTY detection with proper precedence - Handle edge cases (undefined stdout, missing env vars) - _Requirements: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 4.1, 4.2, 4.3, 4.4, 5.1, 5.2, 5.3, 5.4, 5.5_ - [ ]* 1.1 Write property test for FORCE_COLOR behavior - **Property 1: FORCE_COLOR enables colors** - **Validates: Requirements 1.5** - [ ]* 1.2 Write property test for NO_COLOR behavior - **Property 2: NO_COLOR disables colors** - **Validates: Requirements 1.6** - [ ]* 1.3 Write property test for safe error handling - **Property 6: Safe error handling** - **Validates: Requirements 4.2** - [ ]* 1.4 Write unit tests for color detection edge cases - Test FORCE_COLOR precedence over NO_COLOR - Test undefined stdout handling - Test error in detection defaults to plain text - Test caching behavior - Test non-TTY with FORCE_COLOR - _Requirements: 1.7, 4.1, 4.3, 4.4, 5.5_ - [x] 2. Implement color formatter utility - Create `colorize()` helper function that conditionally applies ANSI codes - Accept text, color code, and enabled flag as parameters - Return formatted text with ANSI codes when enabled, plain text otherwise - _Requirements: 2.1, 2.2_ - [ ]* 2.1 Write property test for colors when enabled - **Property 3: Colors present when enabled** - **Validates: Requirements 2.1** - [ ]* 2.2 Write property test for no colors when disabled - **Property 4: No colors when disabled** - **Validates: Requirements 2.2** - [x] 3. Refactor defaultLogger to use color detection - Update `defaultLogger` function to call `supportsColor()` at the start - Replace all hardcoded ANSI escape codes with calls to `colorize()` - Maintain identical output structure and information content - Preserve existing function signature and behavior - _Requirements: 2.1, 2.2, 2.3, 2.4, 3.1, 3.2, 3.3, 3.4_ - [ ]* 3.1 Write property test for content preservation - **Property 5: Content preservation** - **Validates: Requirements 2.3, 2.4** - [ ]* 3.2 Write unit test for backward compatibility - Test that output matches expected format in color-supporting environments - _Requirements: 3.4_ - [x] 4. Checkpoint - Ensure all tests pass - Ensure all tests pass, ask the user if questions arise. ## Notes - Tasks marked with `*` are optional and can be skipped for faster MVP - Each task references specific requirements for traceability - Property tests validate universal correctness properties with minimum 100 iterations - Unit tests validate specific examples and edge cases - The implementation maintains full backward compatibility with existing code