Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-lamps-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'starlight-typedoc': patch
---

Fixes a sidebar generation issue when using the [plugin `watch` configuration option](https://starlight-typedoc.vercel.app/configuration/#watch).
26 changes: 16 additions & 10 deletions packages/starlight-typedoc/libs/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ParameterType,
RendererEvent,
type PageDefinition,
type ProjectReflection,
} from 'typedoc'
import type { MarkdownPageEvent, PluginOptions } from 'typedoc-plugin-markdown'

Expand Down Expand Up @@ -65,20 +66,25 @@ export async function generateTypeDoc(
}
})

const reflections = await app.convert()

if (
(!reflections?.groups || reflections.groups.length === 0) &&
!reflections?.children?.some((child) => (child.groups ?? []).length > 0)
) {
throw new NoReflectionsError()
}
let reflections: ProjectReflection | undefined

if (options.watch) {
void app.convertAndWatch(async (reflections) => {
await app.generateOutputs(reflections)
reflections = await new Promise<ProjectReflection>((resolve) => {
void app.convertAndWatch(async (reflections) => {
await app.generateOutputs(reflections)
resolve(reflections)
})
})
} else {
reflections = await app.convert()

if (
(!reflections?.groups || reflections.groups.length === 0) &&
!reflections?.children?.some((child) => (child.groups ?? []).length > 0)
) {
throw new NoReflectionsError()
}

await app.generateOutputs(reflections)
}

Expand Down