-
-
Notifications
You must be signed in to change notification settings - Fork 90
feat(feature-flags): Add two-phase mode support (mark & shake) #580
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
Conversation
Add support for two-phase feature flag transformation: - Mark mode (default): Marks flags with __SWC_FLAGS__ markers for later substitution - Shake mode: Substitutes markers with boolean values and performs DCE This replaces the previous single-phase approach with a clearer two-phase workflow: 1. Phase 1 (mark): Convert flag variables to markers 2. Phase 2 (shake): Substitute markers and eliminate dead code Changes: - Add TransformMode enum with Mark and Shake variants - Add unified FeatureFlagsConfig supporting both modes - Update plugin to dispatch to BuildTimeTransform (mark) or RuntimeTransform (shake) - Add comprehensive WASM integration tests - Update TypeScript types and documentation Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
|
- Change "Transform mode" to "Transformation mode" in config docs - Fix comment saying markerObject is used in shake mode (should be mark mode) - Fix comment saying flagValues is required in transform mode (should be shake mode) - Fix comment saying collectStats is used in transform mode (should be shake mode) Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Code Review: Two-Phase Feature Flag TransformationOverall AssessmentThis is a well-designed PR that adds two-phase mode support to the feature flags plugin. The implementation is clean, maintains backward compatibility, and includes comprehensive tests and documentation. The architectural approach of separating mark and shake phases is sound. Status: ✅ Recommended for approval with minor suggestions Strengths
Issues & Suggestions1. Potential Configuration Validation Issue
|
PR Review: Two-Phase Feature Flag TransformationSummaryThis PR adds a well-designed two-phase approach (mark & shake modes) for feature flag transformation. The implementation is solid with good documentation and test coverage. Below are my detailed findings. ✅ StrengthsArchitecture & Design
Documentation
Testing
🔍 Issues & Suggestions1. Bug: Potential Config Parsing Issue
|
Add build:debug step to test script to ensure WASM file exists before running tests. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
Pull Request Review: feat(feature-flags): Add two-phase mode support (mark & shake)SummaryThis PR adds a unified two-phase transformation system for the feature flags plugin, introducing "mark" and "shake" modes. The implementation is well-structured and maintains backward compatibility while adding significant new functionality. ✅ StrengthsArchitecture & Design
Code Quality
Testing
Documentation
🔍 Issues & Concerns1. Potential Configuration Confusion (Minor)In shake mode, the packages/feature-flags/src/lib.rs:42-51 TransformMode::Shake => {
// Phase 2: Substitute markers and perform DCE
let runtime_config = RuntimeConfig {
flag_values: config.flag_values,
remove_markers: true,
collect_stats: config.collect_stats,
marker_object: config.marker_object,
};
// Note: config.libraries is ignored hereRecommendation: Consider validating configuration and warning/erroring when mode-specific fields are provided incorrectly:
2. Deprecation Notice Inconsistency (Minor)packages/feature-flags/types.d.ts:146 /**
* @deprecated Use FeatureFlagsConfig with mode: "shake" instead
*/
export interface BuildTimeConfigThe deprecation message says "mode: shake" but should say "mode: mark" since 3. Unrelated Code Change (Trivial)contrib/mut-cjs-exports/src/local_export_strip.rs:214-217 The removal of a blank line in an unrelated file should ideally be in a separate commit or explained in the commit message. While harmless, it adds noise to the PR. 4. Missing Validation (Minor)The shake mode doesn't validate that Suggestion: Consider logging a warning or adding documentation about this potential pitfall. 5. Error Messages (Minor)packages/feature-flags/src/lib.rs:57 .expect("invalid config: must be either FeatureFlagsConfig or BuildTimeConfig");This error message could be more helpful by showing what was received or providing a link to documentation. 🎯 Best Practices Assessment✅ Good Practices Observed
|
Summary
Add support for two-phase feature flag transformation with
markandshakemodes.Changes
New Mode System
__SWC_FLAGS__markers for later substitutionThis provides a clearer two-phase workflow:
Implementation
TransformModeenum withMarkandShakevariantsFeatureFlagsConfigsupporting both modesBuildTimeTransform(mark) orRuntimeTransform(shake)TypeScript Types
types.d.tswith newTransformModetypeTests
__tests__/wasm.test.ts)Documentation
Example Usage
Mark Mode (Phase 1)
{ "mode": "mark", "libraries": { "@your/flags": { "functions": ["useFlags"] } } }Shake Mode (Phase 2)
{ "mode": "shake", "flagValues": { "featureA": true, "featureB": false } }Breaking Changes
None - the plugin maintains backward compatibility with the old
BuildTimeConfigformat.Test Results
🤖 Generated with Claude Code