Skip to content

Commit 51d3e37

Browse files
authored
fix: sidebar watch mode (#85)
1 parent 89840cd commit 51d3e37

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

.changeset/smooth-lamps-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'starlight-typedoc': patch
3+
---
4+
5+
Fixes a sidebar generation issue when using the [plugin `watch` configuration option](https://starlight-typedoc.vercel.app/configuration/#watch).

packages/starlight-typedoc/libs/typedoc.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ParameterType,
1313
RendererEvent,
1414
type PageDefinition,
15+
type ProjectReflection,
1516
} from 'typedoc'
1617
import type { MarkdownPageEvent, PluginOptions } from 'typedoc-plugin-markdown'
1718

@@ -65,20 +66,25 @@ export async function generateTypeDoc(
6566
}
6667
})
6768

68-
const reflections = await app.convert()
69-
70-
if (
71-
(!reflections?.groups || reflections.groups.length === 0) &&
72-
!reflections?.children?.some((child) => (child.groups ?? []).length > 0)
73-
) {
74-
throw new NoReflectionsError()
75-
}
69+
let reflections: ProjectReflection | undefined
7670

7771
if (options.watch) {
78-
void app.convertAndWatch(async (reflections) => {
79-
await app.generateOutputs(reflections)
72+
reflections = await new Promise<ProjectReflection>((resolve) => {
73+
void app.convertAndWatch(async (reflections) => {
74+
await app.generateOutputs(reflections)
75+
resolve(reflections)
76+
})
8077
})
8178
} else {
79+
reflections = await app.convert()
80+
81+
if (
82+
(!reflections?.groups || reflections.groups.length === 0) &&
83+
!reflections?.children?.some((child) => (child.groups ?? []).length > 0)
84+
) {
85+
throw new NoReflectionsError()
86+
}
87+
8288
await app.generateOutputs(reflections)
8389
}
8490

0 commit comments

Comments
 (0)