Home / Function/ ensureRegistriesInConfig() — ui Function Reference

ensureRegistriesInConfig() — ui Function Reference

Architecture documentation for the ensureRegistriesInConfig() function in registries.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  19471747_0228_5cfc_cee8_ee44dfd71f2e["ensureRegistriesInConfig()"]
  a8587e5e_7bec_029e_1748_355416bbd628["registries.ts"]
  19471747_0228_5cfc_cee8_ee44dfd71f2e -->|defined in| a8587e5e_7bec_029e_1748_355416bbd628
  style 19471747_0228_5cfc_cee8_ee44dfd71f2e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/shadcn/src/utils/registries.ts lines 10–101

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"),

Subdomains

Frequently Asked Questions

What does ensureRegistriesInConfig() do?
ensureRegistriesInConfig() is a function in the ui codebase, defined in packages/shadcn/src/utils/registries.ts.
Where is ensureRegistriesInConfig() defined?
ensureRegistriesInConfig() is defined in packages/shadcn/src/utils/registries.ts at line 10.

Analyze Your Own Codebase

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

Try Supermodel Free