Skip to content

Commit

Permalink
feat!: add support for typedoc-plugin-markdown version `4.0.0-next.…
Browse files Browse the repository at this point in the history
…21` which is now the minimum supported version
  • Loading branch information
HiDeoo committed Sep 26, 2023
1 parent 22db854 commit 2efe1ae
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 46 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"sharp": "0.32.5",
"starlight-typedoc": "workspace:*",
"typedoc": "0.25",
"typedoc-plugin-markdown": "4.0.0-next.20",
"typedoc-plugin-markdown": "4.0.0-next.21",
"typedoc-plugin-mdn-links": "3.0.3"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion example/src/content/docs/guides/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ni starlight-typedoc typedoc typedoc-plugin-markdown@next
</Tabs>

:::note
The Starlight TypeDoc package requires at least the version `4.0.0-next.20` of `typedoc-plugin-markdown`, hence the `@next` tag in the installation command.
The Starlight TypeDoc package requires at least the version `4.0.0-next.21` of `typedoc-plugin-markdown`, hence the `@next` tag in the installation command.
:::

Update your [Astro configuration](https://docs.astro.build/en/guides/configuring-astro/#supported-config-file-types) to generate documentation from your TypeScript code:
Expand Down
2 changes: 1 addition & 1 deletion example/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ hero:
file: ../../assets/houston.webp
actions:
- text: Check Example
link: /api/functions/functiondothingc/
link: /api/functions/dothingc/
icon: right-arrow
variant: primary
- text: Getting Started
Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@astrojs/starlight": ">=0.9.0",
"astro": ">=3.0.0",
"typedoc": ">=0.25.0",
"typedoc-plugin-markdown": ">=4.0.0-next.20"
"typedoc-plugin-markdown": ">=4.0.0-next.21"
},
"engines": {
"node": ">=18.14.1"
Expand Down
1 change: 0 additions & 1 deletion packages/starlight-typedoc/src/libs/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const markdownPluginConfig: TypeDocConfig = {
hideInPageTOC: true,
hidePageHeader: true,
hidePageTitle: true,
skipIndexPage: true,
}

export async function bootstrapApp(
Expand Down
10 changes: 5 additions & 5 deletions packages/starlight-typedoc/tests/e2e/asides.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DocPage } from './fixtures/DocPage'
import { expect, test } from './test'

test('should use an aside for the deprecated tag with no content', async ({ docPage }) => {
await docPage.goto('functions/functiondothingb')
await docPage.goto('functions/dothingb')

const name = 'Deprecated'
const { aside, title, content } = await getAside(docPage, name)
Expand All @@ -13,7 +13,7 @@ test('should use an aside for the deprecated tag with no content', async ({ docP
})

test('should use an aside for the deprecated tag with custom content', async ({ docPage }) => {
await docPage.goto('functions/functiondothingc')
await docPage.goto('functions/dothingc')

const name = 'Deprecated'
const { aside, title, content } = await getAside(docPage, name)
Expand All @@ -24,9 +24,9 @@ test('should use an aside for the deprecated tag with custom content', async ({
})

const releaseStageCases: [releaseStage: string, url: string][] = [
['Alpha', 'classes/classbar'],
['Beta', 'variables/variableanobject'],
['Experimental', 'interfaces/interfacething'],
['Alpha', 'classes/bar'],
['Beta', 'variables/anobject'],
['Experimental', 'interfaces/thing'],
]

for (const [releaseStage, url] of releaseStageCases) {
Expand Down
18 changes: 9 additions & 9 deletions packages/starlight-typedoc/tests/e2e/content.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, test } from './test'

test('should add titles to the frontmatter', async ({ docPage }) => {
await docPage.goto('classes/classfoo')
await docPage.goto('classes/foo')

expect(docPage.title).toBe('Foo')

await docPage.goto('functions/functiondothinga')
await docPage.goto('functions/dothinga')

expect(docPage.title).toBe('doThingA')
})
Expand All @@ -31,25 +31,25 @@ test('should properly format links for multiple entry points', async ({ docPage
})

test('should properly format links with anchors for a single entry point', async ({ docPage }) => {
await docPage.goto('classes/classfoo')
await docPage.goto('classes/foo')

const barConstructorLinkHref = await docPage.content
.getByRole('link', { exact: true, name: 'constructor' })
.getAttribute('href')

expect(barConstructorLinkHref).toEqual('/api/classes/classbar/#constructor')
expect(barConstructorLinkHref).toEqual('/api/classes/bar/#constructors')
})

test('should properly format links with anchors for multiple entry points', async ({ docPage }) => {
docPage.useMultipleEntryPoints()

await docPage.goto('foo/classes/classfoo')
await docPage.goto('foo/classes/foo')

const barConstructorLinkHref = await docPage.content
.getByRole('link', { exact: true, name: 'constructor' })
.getAttribute('href')

expect(barConstructorLinkHref).toEqual('/api-multiple-entrypoints/bar/classes/classbar/#constructor')
expect(barConstructorLinkHref).toEqual('/api-multiple-entrypoints/bar/classes/bar/#constructors')
})

test('should disable edit links', async ({ docPage }) => {
Expand All @@ -63,7 +63,7 @@ test('should disable edit links', async ({ docPage }) => {
})

test('should support TypeDoc plugins', async ({ docPage }) => {
await docPage.goto('classes/classfoo')
await docPage.goto('classes/foo')

const mdnLink = docPage.page.getByRole('link', { exact: true, name: 'HTMLElement' })

Expand All @@ -75,8 +75,8 @@ test('should support TypeDoc plugins', async ({ docPage }) => {
})

test('should properly format links in summary', async ({ docPage }) => {
await docPage.goto('functions/functiondothingfaster')
await docPage.goto('functions/dothingfaster')

await docPage.content.getByRole('link', { exact: true, name: 'doThingB' }).click()
await docPage.page.waitForURL('**/api/functions/functiondothingb/')
await docPage.page.waitForURL('**/api/functions/dothingb/')
})
4 changes: 2 additions & 2 deletions packages/starlight-typedoc/tests/e2e/pagination.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DocPage } from './fixtures/DocPage'
import { expect, test } from './test'

test('should not include pagination links by default', async ({ docPage }) => {
await docPage.goto('classes/classfoo')
await docPage.goto('classes/foo')

const { next, prev } = getPrevNext(docPage)

Expand All @@ -13,7 +13,7 @@ test('should not include pagination links by default', async ({ docPage }) => {
test('should not include pagination links if configured to do so', async ({ docPage }) => {
docPage.useMultipleEntryPoints()

await docPage.goto('bar/classes/classbar')
await docPage.goto('bar/classes/bar')

const { next, prev } = getPrevNext(docPage)

Expand Down
4 changes: 2 additions & 2 deletions packages/starlight-typedoc/tests/e2e/sidebar.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from './test'

const singleEntrypointUrl = 'classes/classfoo'
const multipleEntrypointsUrl = 'bar/classes/classbar'
const singleEntrypointUrl = 'classes/foo'
const multipleEntrypointsUrl = 'bar/classes/bar'

test('should include the TypeDoc sidebar group for a single entry point', async ({ docPage }) => {
await docPage.goto(singleEntrypointUrl)
Expand Down
27 changes: 11 additions & 16 deletions packages/starlight-typedoc/tests/unit/typedoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('should not add `README.md` module files for multiple entry points', async
const filePaths = writeFileSyncSpy.mock.calls.map((call) => call[0].toString())

expect(writeFileSyncSpy).toHaveBeenCalled()
expect(filePaths.some((filePath) => filePath.endsWith('README.md'))).toBe(false)
expect(filePaths.some((filePath) => /\/(?:Bar|Foo)\/README\.md$/.test(filePath))).toBe(false)
})

test('should support overriding typedoc-plugin-markdown readme and index page generation', async () => {
Expand All @@ -98,7 +98,6 @@ test('should support overriding typedoc-plugin-markdown readme and index page ge
typeDoc: {
...starlightTypeDocOptions.typeDoc,
readme: 'README.md',
skipIndexPage: false,
},
entryPoints: ['../../fixtures/src/Bar.ts', '../../fixtures/src/Foo.ts'],
})
Expand All @@ -117,8 +116,6 @@ test('should output modules with index', async () => {
...starlightTypeDocOptions.typeDoc,
outputFileStrategy: 'modules',
entryFileName: 'index.md',
skipIndexPage: false,
flattenOutputFiles: true,
},
entryPoints: ['../../fixtures/src/module.ts'],
})
Expand All @@ -128,11 +125,11 @@ test('should output modules with index', async () => {

expect(filePaths).toEqual([
expect.stringMatching(/index\.md$/),
expect.stringMatching(/Namespace\.bar\.md$/),
expect.stringMatching(/Namespace\.foo\.md$/),
expect.stringMatching(/Namespace\.functions\.md$/),
expect.stringMatching(/Namespace\.shared\.md$/),
expect.stringMatching(/Namespace\.types\.md$/),
expect.stringMatching(/namespaces\/bar\.md$/),
expect.stringMatching(/namespaces\/foo\.md$/),
expect.stringMatching(/namespaces\/functions\.md$/),
expect.stringMatching(/namespaces\/shared\.md$/),
expect.stringMatching(/namespaces\/types\.md$/),
])
})

Expand All @@ -143,8 +140,6 @@ test('should output index with correct module path', async () => {
...starlightTypeDocOptions.typeDoc,
outputFileStrategy: 'modules',
entryFileName: 'index.md',
skipIndexPage: false,
flattenOutputFiles: true,
},
entryPoints: ['../../fixtures/src/module.ts'],
})
Expand All @@ -157,10 +152,10 @@ test('should output index with correct module path', async () => {

expect(
content.includes(`
- [bar](/api/namespacebar/)
- [foo](/api/namespacefoo/)
- [functions](/api/namespacefunctions/)
- [shared](/api/namespaceshared/)
- [types](/api/namespacetypes/)`),
- [bar](/api/namespaces/bar/)
- [foo](/api/namespaces/foo/)
- [functions](/api/namespaces/functions/)
- [shared](/api/namespaces/shared/)
- [types](/api/namespaces/types/)`),
).toBe(true)
})
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2efe1ae

Please sign in to comment.