Home / Function/ resolveNestedFilePath() — ui Function Reference

resolveNestedFilePath() — ui Function Reference

Architecture documentation for the resolveNestedFilePath() function in update-files.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  4986011c_e945_83d0_6884_3ab38bf394a1["resolveNestedFilePath()"]
  3efb2c23_7931_d244_b4e1_85acab69298c["update-files.ts"]
  4986011c_e945_83d0_6884_3ab38bf394a1 -->|defined in| 3efb2c23_7931_d244_b4e1_85acab69298c
  ff8d1a68_3ace_911d_7cb3_0e0a0d30e24f["resolveFilePath()"]
  ff8d1a68_3ace_911d_7cb3_0e0a0d30e24f -->|calls| 4986011c_e945_83d0_6884_3ab38bf394a1
  style 4986011c_e945_83d0_6884_3ab38bf394a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/utils/updaters/update-files.ts lines 449–474

export function resolveNestedFilePath(
  filePath: string,
  targetDir: string
): string {
  // Normalize paths by removing leading/trailing slashes
  const normalizedFilePath = filePath.replace(/^\/|\/$/g, "")
  const normalizedTargetDir = targetDir.replace(/^\/|\/$/g, "")

  // Split paths into segments
  const fileSegments = normalizedFilePath.split("/")
  const targetSegments = normalizedTargetDir.split("/")

  // Find the last matching segment from targetDir in filePath
  const lastTargetSegment = targetSegments[targetSegments.length - 1]
  const commonDirIndex = fileSegments.findIndex(
    (segment) => segment === lastTargetSegment
  )

  if (commonDirIndex === -1) {
    // Return just the filename if no common directory is found
    return fileSegments[fileSegments.length - 1]
  }

  // Return everything after the common directory
  return fileSegments.slice(commonDirIndex + 1).join("/")
}

Subdomains

Called By

Frequently Asked Questions

What does resolveNestedFilePath() do?
resolveNestedFilePath() is a function in the ui codebase, defined in packages/shadcn/src/utils/updaters/update-files.ts.
Where is resolveNestedFilePath() defined?
resolveNestedFilePath() is defined in packages/shadcn/src/utils/updaters/update-files.ts at line 449.
What calls resolveNestedFilePath()?
resolveNestedFilePath() is called by 1 function(s): resolveFilePath.

Analyze Your Own Codebase

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

Try Supermodel Free