Home / Function/ useForks() — react Function Reference

useForks() — react Function Reference

Architecture documentation for the useForks() function in use-forks-plugin.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  80622b56_ac3f_33af_8226_d895ca045e41["useForks()"]
  2b09b81c_a42c_2e22_f672_337d29ddc085["use-forks-plugin.js"]
  80622b56_ac3f_33af_8226_d895ca045e41 -->|defined in| 2b09b81c_a42c_2e22_f672_337d29ddc085
  7b40527f_a611_c6a5_db92_10d2eb4e745a["resolveRelatively()"]
  80622b56_ac3f_33af_8226_d895ca045e41 -->|calls| 7b40527f_a611_c6a5_db92_10d2eb4e745a
  style 80622b56_ac3f_33af_8226_d895ca045e41 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

scripts/rollup/plugins/use-forks-plugin.js lines 30–86

function useForks(forks) {
  let resolvedForks = new Map();
  Object.keys(forks).forEach(srcModule => {
    // Fork paths are relative to the project root. They must include the full
    // path, including the extension. We intentionally don't use Node's module
    // resolution algorithm because 1) require.resolve doesn't work with ESM
    // modules, and 2) the behavior is easier to predict.
    const targetModule = forks[srcModule];
    resolvedForks.set(
      path.resolve(process.cwd(), srcModule),
      // targetModule could be a string (a file path),
      // or an error (which we'd throw if it gets used).
      // Don't try to "resolve" errors, but cache
      // resolved file paths.
      typeof targetModule === 'string'
        ? path.resolve(process.cwd(), targetModule)
        : targetModule
    );
  });
  return {
    name: 'scripts/rollup/plugins/use-forks-plugin',
    resolveId(importee, importer) {
      if (!importer || !importee) {
        return null;
      }
      if (importee.startsWith('\u0000')) {
        // Internal Rollup reference, ignore.
        // Passing that to Node file functions can fatal.
        return null;
      }
      let resolvedImportee = null;
      let cacheKey = `${importer}:::${importee}`;
      if (resolveCache.has(cacheKey)) {
        // Avoid hitting file system if possible.
        resolvedImportee = resolveCache.get(cacheKey);
      } else {
        try {
          resolvedImportee = resolveRelatively(importee, importer);
        } catch (err) {
          // Not our fault, let Rollup fail later.
        }
        if (resolvedImportee) {
          resolveCache.set(cacheKey, resolvedImportee);
        }
      }
      if (resolvedImportee && resolvedForks.has(resolvedImportee)) {
        // We found a fork!
        const fork = resolvedForks.get(resolvedImportee);
        if (fork instanceof Error) {
          throw fork;
        }
        return fork;
      }
      return null;
    },
  };
}

Domain

Subdomains

Frequently Asked Questions

What does useForks() do?
useForks() is a function in the react codebase, defined in scripts/rollup/plugins/use-forks-plugin.js.
Where is useForks() defined?
useForks() is defined in scripts/rollup/plugins/use-forks-plugin.js at line 30.
What does useForks() call?
useForks() calls 1 function(s): resolveRelatively.

Analyze Your Own Codebase

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

Try Supermodel Free