Home / Function/ runCompileCommand() — react Function Reference

runCompileCommand() — react Function Reference

Architecture documentation for the runCompileCommand() function in runner.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6["runCompileCommand()"]
  1fd49604_fb16_2568_4971_9eca12fd6a73["runner.ts"]
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6 -->|defined in| 1fd49604_fb16_2568_4971_9eca12fd6a73
  5a048c02_8e86_6fb8_e501_a05c0f563dce["parseLanguage()"]
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6 -->|calls| 5a048c02_8e86_6fb8_e501_a05c0f563dce
  4553e8b5_c1d7_17bf_ec31_bf39f1f5df21["parseSourceType()"]
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6 -->|calls| 4553e8b5_c1d7_17bf_ec31_bf39f1f5df21
  a87dd476_f026_8f78_2fa7_26db794e5375["parseInput()"]
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6 -->|calls| a87dd476_f026_8f78_2fa7_26db794e5375
  e280875d_a772_f261_3d24_55f4118e3e6d["format()"]
  c38ea253_eaec_a82d_bbe8_28e45a28dbf6 -->|calls| e280875d_a772_f261_3d24_55f4118e3e6d
  style c38ea253_eaec_a82d_bbe8_28e45a28dbf6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/snap/src/runner.ts lines 211–331

async function runCompileCommand(opts: CompileOptions): Promise<void> {
  // Resolve the input path
  const inputPath = path.isAbsolute(opts.path)
    ? opts.path
    : path.resolve(PROJECT_ROOT, opts.path);

  // Check if file exists
  if (!fs.existsSync(inputPath)) {
    console.error(`Error: File not found: ${inputPath}`);
    process.exit(1);
  }

  // Read the input file
  const input = fs.readFileSync(inputPath, 'utf-8');
  const filename = path.basename(inputPath);
  const firstLine = input.substring(0, input.indexOf('\n'));
  const language = parseLanguage(firstLine);
  const sourceType = parseSourceType(firstLine);

  // Import the compiler
  const importedCompilerPlugin = require(BABEL_PLUGIN_SRC) as Record<
    string,
    any
  >;
  const BabelPluginReactCompiler = importedCompilerPlugin['default'];
  const parseConfigPragmaForTests =
    importedCompilerPlugin[PARSE_CONFIG_PRAGMA_IMPORT];
  const printFunctionWithOutlined = importedCompilerPlugin[PRINT_HIR_IMPORT];
  const printReactiveFunctionWithOutlined =
    importedCompilerPlugin[PRINT_REACTIVE_IR_IMPORT];
  const EffectEnum = importedCompilerPlugin['Effect'];
  const ValueKindEnum = importedCompilerPlugin['ValueKind'];
  const ValueReasonEnum = importedCompilerPlugin['ValueReason'];

  // Setup debug logger
  let lastLogged: string | null = null;
  const debugIRLogger = opts.debug
    ? (value: any) => {
        let printed: string;
        switch (value.kind) {
          case 'hir':
            printed = printFunctionWithOutlined(value.value);
            break;
          case 'reactive':
            printed = printReactiveFunctionWithOutlined(value.value);
            break;
          case 'debug':
            printed = value.value;
            break;
          case 'ast':
            printed = '(ast)';
            break;
          default:
            printed = String(value);
        }

        if (printed !== lastLogged) {
          lastLogged = printed;
          console.log(`${chalk.green(value.name)}:\n${printed}\n`);
        } else {
          console.log(`${chalk.blue(value.name)}: (no change)\n`);
        }
      }
    : () => {};

  // Parse the input
  let ast;
  try {
    ast = parseInput(input, filename, language, sourceType);
  } catch (e: any) {
    console.error(`Parse error: ${e.message}`);
    process.exit(1);
  }

  // Build plugin options
  const config = parseConfigPragmaForTests(firstLine, {compilationMode: 'all'});
  const options = {
    ...config,
    environment: {
      ...config.environment,
    },

Domain

Subdomains

Frequently Asked Questions

What does runCompileCommand() do?
runCompileCommand() is a function in the react codebase, defined in compiler/packages/snap/src/runner.ts.
Where is runCompileCommand() defined?
runCompileCommand() is defined in compiler/packages/snap/src/runner.ts at line 211.
What does runCompileCommand() call?
runCompileCommand() calls 4 function(s): format, parseInput, parseLanguage, parseSourceType.

Analyze Your Own Codebase

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

Try Supermodel Free