addRegistriesToConfig() — ui Function Reference
Architecture documentation for the addRegistriesToConfig() function in add.ts from the ui codebase.
Entity Profile
Dependency Diagram
graph TD 558f5848_ce45_aac3_5ed4_c4d67da29963["addRegistriesToConfig()"] 670848eb_ec36_f11f_b3df_91f7406ddb11["add.ts"] 558f5848_ce45_aac3_5ed4_c4d67da29963 -->|defined in| 670848eb_ec36_f11f_b3df_91f7406ddb11 6f22aa38_1a2d_7f59_ac01_05f3961c54bd["add()"] 6f22aa38_1a2d_7f59_ac01_05f3961c54bd -->|calls| 558f5848_ce45_aac3_5ed4_c4d67da29963 4157e998_8e83_6174_4bd3_a01e4ca5ce83["pluralize()"] 558f5848_ce45_aac3_5ed4_c4d67da29963 -->|calls| 4157e998_8e83_6174_4bd3_a01e4ca5ce83 style 558f5848_ce45_aac3_5ed4_c4d67da29963 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/shadcn/src/commands/registry/add.ts lines 73–212
async function addRegistriesToConfig(
registryArgs: string[],
cwd: string,
options: { silent?: boolean }
) {
const configPath = path.resolve(cwd, "components.json")
if (!fs.existsSync(configPath)) {
throw new Error(
`No ${highlighter.info("components.json")} found. Run ${highlighter.info(
"shadcn init"
)} first.`
)
}
const parsed = registryArgs.map(parseRegistryArg)
const needsLookup = parsed.filter((p) => !p.url)
let registriesIndex: { name: string; url: string }[] = []
if (needsLookup.length > 0) {
const fetchSpinner = spinner("Fetching registries.", {
silent: options.silent,
}).start()
const registries = await getRegistries()
if (!registries) {
fetchSpinner.fail()
throw new Error("Failed to fetch registries.")
}
fetchSpinner.succeed()
registriesIndex = registries
}
const registriesToAdd: Record<string, string> = {}
for (const { namespace, url } of parsed) {
if (namespace in BUILTIN_REGISTRIES) {
logger.warn(
`${highlighter.info(
namespace
)} is a built-in registry and cannot be added.`
)
continue
}
if (url) {
if (!url.includes("{name}")) {
throw new Error(
`Invalid registry URL for ${highlighter.info(
namespace
)}. URL must include {name} placeholder. Example: ${highlighter.info(
`${namespace}=https://example.com/r/{name}.json`
)}`
)
}
registriesToAdd[namespace] = url
} else {
const registry = registriesIndex.find((r) => r.name === namespace)
if (!registry) {
throw new Error(
`Registry ${highlighter.info(namespace)} not found. ` +
`Provide a URL: ${highlighter.info(
`${namespace}=https://.../{name}.json`
)}`
)
}
registriesToAdd[namespace] = registry.url
}
}
if (Object.keys(registriesToAdd).length === 0) {
return { addedRegistries: [] }
}
const existingConfig = await fs.readJson(configPath)
const existingRegistries = existingConfig.registries || {}
const newRegistries: Record<string, string> = {}
const skipped: string[] = []
for (const [ns, url] of Object.entries(registriesToAdd)) {
if (existingRegistries[ns]) {
skipped.push(ns)
} else {
newRegistries[ns] = url
}
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does addRegistriesToConfig() do?
addRegistriesToConfig() is a function in the ui codebase, defined in packages/shadcn/src/commands/registry/add.ts.
Where is addRegistriesToConfig() defined?
addRegistriesToConfig() is defined in packages/shadcn/src/commands/registry/add.ts at line 73.
What does addRegistriesToConfig() call?
addRegistriesToConfig() calls 1 function(s): pluralize.
What calls addRegistriesToConfig()?
addRegistriesToConfig() is called by 1 function(s): add.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free