Home / Function/ resolveFilePath() — ui Function Reference

resolveFilePath() — ui Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/shadcn/src/utils/updaters/update-files.ts lines 336–392

export function resolveFilePath(
  file: z.infer<typeof registryItemFileSchema>,
  config: Config,
  options: {
    isSrcDir?: boolean
    commonRoot?: string
    framework?: ProjectInfo["framework"]["name"]
    path?: string
    fileIndex?: number
  }
) {
  // Handle custom path if provided.
  if (options.path) {
    const resolvedPath = path.isAbsolute(options.path)
      ? options.path
      : path.join(config.resolvedPaths.cwd, options.path)

    const isFilePath = /\.[^/\\]+$/.test(resolvedPath)

    if (isFilePath) {
      // We'll only use the custom path for the first file.
      // This is for registry items with multiple files.
      if (options.fileIndex === 0) {
        return resolvedPath
      }
    } else {
      // If the custom path is a directory,
      // We'll place all files in the directory.
      const fileName = path.basename(file.path)
      return path.join(resolvedPath, fileName)
    }
  }

  if (file.target) {
    if (file.target.startsWith("~/")) {
      return path.join(config.resolvedPaths.cwd, file.target.replace("~/", ""))
    }

    let target = file.target

    if (file.type === "registry:page") {
      target = resolvePageTarget(target, options.framework)
      if (!target) {
        return ""
      }
    }

    return options.isSrcDir
      ? path.join(config.resolvedPaths.cwd, "src", target.replace("src/", ""))
      : path.join(config.resolvedPaths.cwd, target.replace("src/", ""))
  }

  const targetDir = resolveFileTargetDirectory(file, config)

  const relativePath = resolveNestedFilePath(file.path, targetDir)
  return path.join(targetDir, relativePath)
}

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free