Home / Function/ findCommonRoot() — ui Function Reference

findCommonRoot() — ui Function Reference

Architecture documentation for the findCommonRoot() function in get-config.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  899ff813_0123_0ae5_7384_eeb962021d55["findCommonRoot()"]
  913f04e7_90de_d0b5_5068_4dacd40de96e["get-config.ts"]
  899ff813_0123_0ae5_7384_eeb962021d55 -->|defined in| 913f04e7_90de_d0b5_5068_4dacd40de96e
  25c9631d_53ea_f96a_1e58_7ff09c87a03d["findPackageRoot()"]
  25c9631d_53ea_f96a_1e58_7ff09c87a03d -->|calls| 899ff813_0123_0ae5_7384_eeb962021d55
  style 899ff813_0123_0ae5_7384_eeb962021d55 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/utils/get-config.ts lines 198–211

export function findCommonRoot(cwd: string, resolvedPath: string) {
  const parts1 = cwd.split(path.sep)
  const parts2 = resolvedPath.split(path.sep)
  const commonParts = []

  for (let i = 0; i < Math.min(parts1.length, parts2.length); i++) {
    if (parts1[i] !== parts2[i]) {
      break
    }
    commonParts.push(parts1[i])
  }

  return commonParts.join(path.sep)
}

Subdomains

Called By

Frequently Asked Questions

What does findCommonRoot() do?
findCommonRoot() is a function in the ui codebase, defined in packages/shadcn/src/utils/get-config.ts.
Where is findCommonRoot() defined?
findCommonRoot() is defined in packages/shadcn/src/utils/get-config.ts at line 198.
What calls findCommonRoot()?
findCommonRoot() is called by 1 function(s): findPackageRoot.

Analyze Your Own Codebase

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

Try Supermodel Free