Home / Function/ findPackageRoot() — ui Function Reference

findPackageRoot() — ui Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/shadcn/src/utils/get-config.ts lines 172–187

export async function findPackageRoot(cwd: string, resolvedPath: string) {
  const commonRoot = findCommonRoot(cwd, resolvedPath)
  const relativePath = path.relative(commonRoot, resolvedPath)

  const packageRoots = await fg.glob("**/package.json", {
    cwd: commonRoot,
    deep: 3,
    ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/public/**"],
  })

  const matchingPackageRoot = packageRoots
    .map((pkgPath) => path.dirname(pkgPath))
    .find((pkgDir) => relativePath.startsWith(pkgDir))

  return matchingPackageRoot ? path.join(commonRoot, matchingPackageRoot) : null
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free