Home / File/ registries.ts — ui Source File

registries.ts — ui Source File

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

Entity Profile

Dependency Diagram

graph LR
  a8587e5e_7bec_029e_1748_355416bbd628["registries.ts"]
  d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5["path"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> d05ec4ea_7a68_3a36_bfa4_9ba7f8409ee5
  81c8b1a1_346a_8b27_dd1e_b8bbb29008b8["api"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> 81c8b1a1_346a_8b27_dd1e_b8bbb29008b8
  2ae56314_aa15_5495_52a2_137787e7b210["constants"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> 2ae56314_aa15_5495_52a2_137787e7b210
  27c043ed_bb82_cb21_dd36_43234ff1fcb5["namespaces"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> 27c043ed_bb82_cb21_dd36_43234ff1fcb5
  889ef9cd_bc40_3de2_281d_ca62c5417b57["schema"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> 889ef9cd_bc40_3de2_281d_ca62c5417b57
  b2895591_2a74_d518_deda_2f26be766dcb["get-config"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> b2895591_2a74_d518_deda_2f26be766dcb
  a3e9bc4e_1faf_6261_a1db_396981c7761d["spinner"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> a3e9bc4e_1faf_6261_a1db_396981c7761d
  f9f5e551_eb59_1a6b_8bf2_b97e73eb13de["fs-extra"]
  a8587e5e_7bec_029e_1748_355416bbd628 --> f9f5e551_eb59_1a6b_8bf2_b97e73eb13de
  style a8587e5e_7bec_029e_1748_355416bbd628 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from "path"
import { getRegistriesIndex } from "@/src/registry/api"
import { BUILTIN_REGISTRIES } from "@/src/registry/constants"
import { resolveRegistryNamespaces } from "@/src/registry/namespaces"
import { rawConfigSchema } from "@/src/registry/schema"
import { Config } from "@/src/utils/get-config"
import { spinner } from "@/src/utils/spinner"
import fs from "fs-extra"

export async function ensureRegistriesInConfig(
  components: string[],
  config: Config,
  options: {
    silent?: boolean
    writeFile?: boolean
  } = {}
) {
  options = {
    silent: false,
    writeFile: true,
    ...options,
  }

  // Use resolveRegistryNamespaces to discover all namespaces including dependencies.
  const registryNames = await resolveRegistryNamespaces(components, config)

  const missingRegistries = registryNames.filter(
    (registry) =>
      !config.registries?.[registry] &&
      !Object.keys(BUILTIN_REGISTRIES).includes(registry)
  )

  if (missingRegistries.length === 0) {
    return {
      config,
      newRegistries: [],
    }
  }

  // We'll fail silently if we can't fetch the registry index.
  // The error handling by caller will guide user to add the missing registries.
  const registryIndex = await getRegistriesIndex({
    useCache: process.env.NODE_ENV !== "development",
  })

  if (!registryIndex) {
    return {
      config,
      newRegistries: [],
    }
  }

  const foundRegistries: Record<string, string> = {}
  for (const registry of missingRegistries) {
    if (registryIndex[registry]) {
      foundRegistries[registry] = registryIndex[registry]
    }
  }

  if (Object.keys(foundRegistries).length === 0) {
    return {
      config,
      newRegistries: [],
    }
  }

  // Filter out built-in registries from existing config before merging
  const existingRegistries = Object.fromEntries(
    Object.entries(config.registries || {}).filter(
      ([key]) => !Object.keys(BUILTIN_REGISTRIES).includes(key)
    )
  )

  const newConfigWithRegistries = {
    ...config,
    registries: {
      ...existingRegistries,
      ...foundRegistries,
    },
  }

  if (options.writeFile) {
    const { resolvedPaths, ...configWithoutResolvedPaths } =
      newConfigWithRegistries
    const configSpinner = spinner("Updating components.json.", {
      silent: options.silent,
    }).start()
    const updatedConfig = rawConfigSchema.parse(configWithoutResolvedPaths)
    await fs.writeFile(
      path.resolve(config.resolvedPaths.cwd, "components.json"),
      JSON.stringify(updatedConfig, null, 2) + "\n",
      "utf-8"
    )
    configSpinner.succeed()
  }

  return {
    config: newConfigWithRegistries,
    newRegistries: Object.keys(foundRegistries),
  }
}

Subdomains

Dependencies

  • api
  • constants
  • fs-extra
  • get-config
  • namespaces
  • path
  • schema
  • spinner

Frequently Asked Questions

What does registries.ts do?
registries.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, TemplateSync subdomain.
What functions are defined in registries.ts?
registries.ts defines 1 function(s): ensureRegistriesInConfig.
What does registries.ts depend on?
registries.ts imports 8 module(s): api, constants, fs-extra, get-config, namespaces, path, schema, spinner.
Where is registries.ts in the architecture?
registries.ts is located at packages/shadcn/src/utils/registries.ts (domain: FrameworkTooling, subdomain: TemplateSync, directory: packages/shadcn/src/utils).

Analyze Your Own Codebase

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

Try Supermodel Free