Home / Function/ enableFlagInEnvironment() — react Function Reference

enableFlagInEnvironment() — react Function Reference

Architecture documentation for the enableFlagInEnvironment() function in enable-feature-flag.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  104a1d32_414e_ab5b_d52a_9e300bc4b025["enableFlagInEnvironment()"]
  fdb06a3a_b735_af93_2b10_31380c21c8b7["enable-feature-flag.js"]
  104a1d32_414e_ab5b_d52a_9e300bc4b025 -->|defined in| fdb06a3a_b735_af93_2b10_31380c21c8b7
  ab68ec04_512e_f89e_9e49_ae73608023f0["main()"]
  ab68ec04_512e_f89e_9e49_ae73608023f0 -->|calls| 104a1d32_414e_ab5b_d52a_9e300bc4b025
  e414605a_ef2d_bce2_8f69_637d40825448["escapeRegex()"]
  104a1d32_414e_ab5b_d52a_9e300bc4b025 -->|calls| e414605a_ef2d_bce2_8f69_637d40825448
  style 104a1d32_414e_ab5b_d52a_9e300bc4b025 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/scripts/enable-feature-flag.js lines 56–103

function enableFlagInEnvironment(flagName) {
  console.log(`\nEnabling flag "${flagName}" in Environment.ts...`);

  const content = fs.readFileSync(ENVIRONMENT_TS_PATH, 'utf8');

  // Check if the flag exists with default(false)
  const flagPatternFalse = new RegExp(
    `(${escapeRegex(flagName)}:\\s*z\\.boolean\\(\\)\\.default\\()false(\\))`,
    'g'
  );

  if (!flagPatternFalse.test(content)) {
    // Check if flag exists at all
    const flagExistsPattern = new RegExp(
      `${escapeRegex(flagName)}:\\s*z\\.boolean\\(\\)`,
      'g'
    );
    if (flagExistsPattern.test(content)) {
      // Check if it's already true
      const flagPatternTrue = new RegExp(
        `${escapeRegex(flagName)}:\\s*z\\.boolean\\(\\)\\.default\\(true\\)`,
        'g'
      );
      if (flagPatternTrue.test(content)) {
        console.error(`Error: Flag "${flagName}" already has default(true)`);
        process.exit(1);
      }
      console.error(
        `Error: Flag "${flagName}" exists but doesn't have default(false)`
      );
      process.exit(1);
    }
    console.error(`Error: Flag "${flagName}" not found in Environment.ts`);
    process.exit(1);
  }

  // Perform the replacement
  const newContent = content.replace(flagPatternFalse, '$1true$2');

  // Verify the replacement worked
  if (content === newContent) {
    console.error(`Error: Failed to replace flag "${flagName}"`);
    process.exit(1);
  }

  fs.writeFileSync(ENVIRONMENT_TS_PATH, newContent, 'utf8');
  console.log(`Successfully enabled "${flagName}" in Environment.ts`);
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does enableFlagInEnvironment() do?
enableFlagInEnvironment() is a function in the react codebase, defined in compiler/scripts/enable-feature-flag.js.
Where is enableFlagInEnvironment() defined?
enableFlagInEnvironment() is defined in compiler/scripts/enable-feature-flag.js at line 56.
What does enableFlagInEnvironment() call?
enableFlagInEnvironment() calls 1 function(s): escapeRegex.
What calls enableFlagInEnvironment()?
enableFlagInEnvironment() is called by 1 function(s): main.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free