Home / File/ registry.ts — ui Source File

registry.ts — ui Source File

Architecture documentation for registry.ts, a typescript file in the ui codebase. 8 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  c2827044_b928_a1b2_3033_3282c0588350["registry.ts"]
  eac8f98f_e40a_7fe8_f505_372c83d20c7a["fs"]
  c2827044_b928_a1b2_3033_3282c0588350 --> eac8f98f_e40a_7fe8_f505_372c83d20c7a
  b80715bf_43eb_b495_f2cf_a439c5eb0e34["os"]
  c2827044_b928_a1b2_3033_3282c0588350 --> b80715bf_43eb_b495_f2cf_a439c5eb0e34
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  c2827044_b928_a1b2_3033_3282c0588350 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  f089de72_fa18_41f0_bbdc_dbd00aa24ef0["__registry__"]
  c2827044_b928_a1b2_3033_3282c0588350 --> f089de72_fa18_41f0_bbdc_dbd00aa24ef0
  ceec689a_1334_a657_3c35_094070222b09["schema"]
  c2827044_b928_a1b2_3033_3282c0588350 --> ceec689a_1334_a657_3c35_094070222b09
  4f6f7e78_23ff_4f5f_c723_474454f64c85["ts-morph"]
  c2827044_b928_a1b2_3033_3282c0588350 --> 4f6f7e78_23ff_4f5f_c723_474454f64c85
  6802ce19_522d_e5fb_e458_8826d9f6952e["zod"]
  c2827044_b928_a1b2_3033_3282c0588350 --> 6802ce19_522d_e5fb_e458_8826d9f6952e
  9798186b_08af_1d79_2ad7_d662300dc0ba["registry-styles"]
  c2827044_b928_a1b2_3033_3282c0588350 --> 9798186b_08af_1d79_2ad7_d662300dc0ba
  style c2827044_b928_a1b2_3033_3282c0588350 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { promises as fs } from "fs"
import { tmpdir } from "os"
import path from "path"
import { Index } from "@/__registry__"
import { registryItemFileSchema, registryItemSchema } from "shadcn/schema"
import { Project, ScriptKind, SourceFile, SyntaxKind } from "ts-morph"
import { z } from "zod"

import { Style } from "@/registry/registry-styles"

export const DEFAULT_REGISTRY_STYLE = "new-york" satisfies Style["name"]

const memoizedIndex: typeof Index = Object.fromEntries(
  Object.entries(Index).map(([style, items]) => [style, { ...items }])
)

export function getRegistryComponent(
  name: string,
  style: Style["name"] = DEFAULT_REGISTRY_STYLE
) {
  return memoizedIndex[style][name]?.component
}

export async function getRegistryItem(
  name: string,
  style: Style["name"] = DEFAULT_REGISTRY_STYLE
) {
  const item = memoizedIndex[style][name]

  if (!item) {
    return null
  }

  // Convert all file paths to object.
  // TODO: remove when we migrate to new registry.
  item.files = item.files.map((file: unknown) =>
    typeof file === "string" ? { path: file } : file
  )

  // Fail early before doing expensive file operations.
  const result = registryItemSchema.safeParse(item)
  if (!result.success) {
    return null
  }

  let files: typeof result.data.files = []
  for (const file of item.files) {
    const content = await getFileContent(file)
    const relativePath = path.relative(process.cwd(), file.path)

    files.push({
      ...file,
      path: relativePath,
      content,
    })
  }

  // Get meta.
  // Assume the first file is the main file.
  // const meta = await getFileMeta(files[0].path)
// ... (215 more lines)

Subdomains

Types

Dependencies

  • __registry__
  • fs
  • os
  • path
  • registry-styles
  • schema
  • ts-morph
  • zod

Frequently Asked Questions

What does registry.ts do?
registry.ts is a source file in the ui codebase, written in typescript. It belongs to the ComponentRegistry domain, ChartRegistry subdomain.
What functions are defined in registry.ts?
registry.ts defines 12 function(s): createFileTreeForRegistryItemFiles, createTempSourceFile, extractVariable, fixFilePaths, fixImport, getFileContent, getFileMeta, getFileTarget, getRegistryComponent, getRegistryItem, and 2 more.
What does registry.ts depend on?
registry.ts imports 8 module(s): __registry__, fs, os, path, registry-styles, schema, ts-morph, zod.
Where is registry.ts in the architecture?
registry.ts is located at deprecated/www/lib/registry.ts (domain: ComponentRegistry, subdomain: ChartRegistry, directory: deprecated/www/lib).

Analyze Your Own Codebase

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

Try Supermodel Free