Scope TypeDoc metadata by module

Prevent collisions between e.g. `get`, reduce filesize
This commit is contained in:
Oliver Blanthorn 2026-07-19 12:03:05 +02:00
parent 41ef1726f0
commit 187dcf69e3
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 19 additions and 20 deletions

View file

@ -57,11 +57,10 @@ if [ "$QUICK_BUILD" != "1" ]; then
"$(yarn bin)/nearleyc" src/grammars/bracketexpr.ne > \
src/grammars/.bracketexpr.generated.ts
# Generate runtime metadata via typedoc. src/lib/metadata.ts loads the
# JSON and exposes the ProgramMetadata/FileMetadata/Type surface used at
# runtime; the .metadata.generated.ts shim below routes the public
# @src/.metadata.generated import path to that loader.
"$(yarn bin)/typedoc" --json src/.metadata.generated.json --mode file \
# Generate runtime metadata via typedoc. The generated TypeScript shim
# routes the public @src/.metadata.generated import to the JSON loader.
"$(yarn bin)/typedoc" --json src/.metadata.generated.json --mode modules \
--excludeExternals \
--exclude 'src/.excmds_*.generated.ts' --ignoreCompilerErrors \
src/excmds.ts src/lib/config.ts
node scripts/minify_json.js src/.metadata.generated.json

View file

@ -22,15 +22,12 @@ const fileBuckets: Record<
string,
{ functions: Record<string, Node>; classes: Record<string, Node> }
> = {
"src/excmds.ts": { functions: {}, classes: {} },
"src/lib/config.ts": { functions: {}, classes: {} },
excmds: { functions: {}, classes: {} },
"lib/config": { functions: {}, classes: {} },
}
function inTargetFile(node: Node): string | undefined {
for (const src of node.sources || []) {
if (fileBuckets[src.fileName]) return src.fileName
}
return undefined
function moduleName(node: Node): string {
return (node.name || "").replace(/^"|"$/g, "").replace(/\\/g, "/")
}
function walk(node: Node) {
@ -39,22 +36,25 @@ function walk(node: Node) {
for (const v of node) walk(v)
return
}
if (node.kindString === "Function") {
const f = inTargetFile(node)
if (f) fileBuckets[f].functions[node.name] = node
} else if (node.kindString === "Class") {
const f = inTargetFile(node)
if (f) fileBuckets[f].classes[node.name] = node
if (node.kindString === "Module") {
const bucket = fileBuckets[moduleName(node)]
for (const child of bucket ? node.children || [] : []) {
if (child.kindString === "Function") {
bucket.functions[child.name] = child
} else if (child.kindString === "Class") {
bucket.classes[child.name] = child
}
}
}
if (node.children) walk(node.children)
}
walk(metadataJson)
export const excmdsFunctions: Record<string, Node> =
fileBuckets["src/excmds.ts"].functions
fileBuckets.excmds.functions
const defaultConfig: Node | undefined =
fileBuckets["src/lib/config.ts"].classes["default_config"]
fileBuckets["lib/config"].classes["default_config"]
export const defaultConfigMembers: Record<string, Node> = (() => {
const out: Record<string, Node> = {}