buildRegistry
On this page

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 26de7be8.

Syntax

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

Parameters

entries readonly RegistryEntry[]

every module the caller’s scan discovered.

optsoptional 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 per module, and writes the returned source to a file.

// `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

Source

src/core/registry.ts, line 99, at commit 26de7be8

Edit this page Report a problem