Open
Conversation
- Refactor client component detection into dedicated `isClientComponent()` function - Read configurable prefix bytes (default 512B, env var `CODEGEN_CLIENT_DIRECTIVE_PREFIX_BYTES`) instead of fixed 12 bytes for better performance - Handle UTF-8 BOM correctly by stripping it before regex matching - Use more robust regex pattern to detect 'use client' directive that allows leading whitespace, comments, and optional trailing semicolon
…ead of createReadStream - Replace fs.createReadStream mocks with fs.promises.open stubs for client component detection tests - Add test cleanup to delete CODEGEN_CLIENT_DIRECTIVE_PREFIX_BYTES env var in afterEach - Add test coverage for 'use client' detection with leading whitespace, comments, BOM, and optional semicolon - Add test coverage for CODEGEN_CLIENT_DIRECTIVE_PREFIX_BYTES environment variable configuration - Simplify mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description / Motivation
This PR improves correctness and maintainability of client component detection used by codegen. It addresses real-world edge cases (UTF-8 BOM, formatting variations) and makes the scanning behavior configurable to balance detection accuracy with performance. Unit tests were expanded to prevent regressions and validate the new detection logic across representative file prefixes and directive formats.
Testing Details
Types of changes