---
title: "buildRegistry(): function in Tooling, TypeShade API"
description: "buildRegistry, a function in Tooling. Validate a discovered module set against a curated order and render a registry module from it: a union type of the ids…"
url: https://typeshade.dev/api/buildregistry/
language: en
---

# `buildRegistry()`

Function in Tooling

Validate a discovered module set against a curated order and render a registry module from it: a union type of the ids, a record from id to module, and the imports feeding it.

`import { buildRegistry } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
function buildRegistry(
  entries: readonly RegistryEntry[],
  opts?: BuildRegistryOptions,
): BuiltRegistry
```

## Parameters

**`entries` `readonly RegistryEntry[]`**

every module the caller’s scan discovered.

**`opts` optional `BuildRegistryOptions`**

curated order, naming, and banner details.

## Return value

`BuiltRegistry`

the rendered source and the ids in file order.

## Exceptions

**`Error`**

when two entries share an id, when an export name is not an identifier, or when `order` and the discovered set disagree in either direction: a curated id that names no module, or a module that no curated id names. The error message lists both kinds of mismatch, and the `regenerateWith` command when one was given.

## Description

The function does not touch the filesystem. The caller scans its own directories, builds one [`RegistryEntry`](https://typeshade.dev/api/registryentry/) per module, and writes the returned source to a file.

```ts
// `scanExamples` and `CURATED_IDS` are the caller's: a directory walk that returns
// RegistryEntry[], and the hand-written id order it must agree with.
const { source } = buildRegistry(scanExamples('./examples'), {
  order: CURATED_IDS,
  valueType: 'ShaderExample',
  imports: ["import type { ShaderExample } from './_shared.js'"],
  regenerateWith: 'bun scripts/gen-registry.ts > examples/registry.generated.ts',
})
```

## See also

- [`RegistryEntry`](https://typeshade.dev/api/registryentry/)

## Source

[`src/core/registry.ts`, line 99](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/registry.ts#L99), at commit af54ddad5
