Home / Function/ recursivelyResolveFileImports() — ui Function Reference

recursivelyResolveFileImports() — ui Function Reference

Architecture documentation for the recursivelyResolveFileImports() function in utils.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  1c6f4236_a28d_b482_92b7_3da2a29a6be9["recursivelyResolveFileImports()"]
  edc2979a_e040_ab0c_5174_c69f7c8fa905["utils.ts"]
  1c6f4236_a28d_b482_92b7_3da2a29a6be9 -->|defined in| edc2979a_e040_ab0c_5174_c69f7c8fa905
  a952f215_206a_181a_5d99_ff2c8bd1378e["createTempSourceFile()"]
  1c6f4236_a28d_b482_92b7_3da2a29a6be9 -->|calls| a952f215_206a_181a_5d99_ff2c8bd1378e
  8c29518a_8ec2_4c35_3d61_15a1d667b772["determineFileType()"]
  1c6f4236_a28d_b482_92b7_3da2a29a6be9 -->|calls| 8c29518a_8ec2_4c35_3d61_15a1d667b772
  79799d76_cdb2_3542_2249_0f44998edeea["getDependencyFromModuleSpecifier()"]
  1c6f4236_a28d_b482_92b7_3da2a29a6be9 -->|calls| 79799d76_cdb2_3542_2249_0f44998edeea
  style 1c6f4236_a28d_b482_92b7_3da2a29a6be9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/registry/utils.ts lines 59–223

export async function recursivelyResolveFileImports(
  filePath: string,
  config: z.infer<typeof configSchema>,
  projectInfo: ProjectInfo,
  processedFiles: Set<string> = new Set()
): Promise<Pick<z.infer<typeof registryItemSchema>, "files" | "dependencies">> {
  const resolvedFilePath = path.resolve(config.resolvedPaths.cwd, filePath)
  const relativeRegistryFilePath = path.relative(
    config.resolvedPaths.cwd,
    resolvedFilePath
  )

  // Skip if the file is in the skip list
  if (FILE_PATH_SKIP_LIST.includes(relativeRegistryFilePath)) {
    return { dependencies: [], files: [] }
  }

  // Skip if the file extension is not one of the supported extensions
  const fileExtension = path.extname(filePath)
  if (!FILE_EXTENSIONS_FOR_LOOKUP.includes(fileExtension)) {
    return { dependencies: [], files: [] }
  }

  // Prevent infinite loop: skip if already processed
  if (processedFiles.has(relativeRegistryFilePath)) {
    return { dependencies: [], files: [] }
  }
  processedFiles.add(relativeRegistryFilePath)

  const stat = await fs.stat(resolvedFilePath)
  if (!stat.isFile()) {
    // Optionally log or handle this case
    return { dependencies: [], files: [] }
  }

  const content = await fs.readFile(resolvedFilePath, "utf-8")
  const tempFile = await createTempSourceFile(path.basename(resolvedFilePath))
  const sourceFile = project.createSourceFile(tempFile, content, {
    scriptKind: ScriptKind.TSX,
  })
  const tsConfig = await loadConfig(config.resolvedPaths.cwd)
  if (tsConfig.resultType === "failed") {
    return { dependencies: [], files: [] }
  }

  const files: z.infer<typeof registryItemSchema>["files"] = []
  const dependencies = new Set<string>()

  // Add the original file first
  const fileType = determineFileType(filePath)
  const originalFile = {
    path: relativeRegistryFilePath,
    type: fileType,
    target: "",
  }
  files.push(originalFile)

  // 1. Find all import statements in the file.
  const importStatements = sourceFile.getImportDeclarations()
  for (const importStatement of importStatements) {
    const moduleSpecifier = importStatement.getModuleSpecifierValue()

    const isRelativeImport = moduleSpecifier.startsWith(".")
    const isAliasImport = moduleSpecifier.startsWith(
      `${projectInfo.aliasPrefix}/`
    )

    // If not a local import, add to the dependencies array.
    if (!isAliasImport && !isRelativeImport) {
      const dependency = getDependencyFromModuleSpecifier(moduleSpecifier)
      if (dependency) {
        dependencies.add(dependency)
      }
      continue
    }

    let probableImportFilePath = await resolveImport(moduleSpecifier, tsConfig)

    if (isRelativeImport) {
      probableImportFilePath = path.resolve(
        path.dirname(resolvedFilePath),

Subdomains

Frequently Asked Questions

What does recursivelyResolveFileImports() do?
recursivelyResolveFileImports() is a function in the ui codebase, defined in packages/shadcn/src/registry/utils.ts.
Where is recursivelyResolveFileImports() defined?
recursivelyResolveFileImports() is defined in packages/shadcn/src/registry/utils.ts at line 59.
What does recursivelyResolveFileImports() call?
recursivelyResolveFileImports() calls 3 function(s): createTempSourceFile, determineFileType, getDependencyFromModuleSpecifier.

Analyze Your Own Codebase

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

Try Supermodel Free