Skip to content

Commit

Permalink
fix: fixes various Windows path and links related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo committed Jun 4, 2024
1 parent 875d341 commit 6514c65
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/starlight-typedoc/libs/starlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function getSidebarGroupFromReflections(

// The groups generated using the `@group` tag do not have an associated directory on disk.
const isGroupWithDirectory = group.children.some((child) =>
path.posix.join(baseOutputDirectory, child.url ?? '').startsWith(directory),
path.posix.join(baseOutputDirectory, child.url?.replace('\\', '/') ?? '').startsWith(directory),
)

if (!isGroupWithDirectory) {
Expand Down Expand Up @@ -212,7 +212,7 @@ export function getRelativeURL(url: string, baseUrl: string, pageUrl?: string):
const filePath = path.parse(relativeUrl)
const [, anchor] = filePath.base.split('#')
const segments = filePath.dir
.split('/')
.split(/[/\\]/)
.map((segment) => slug(segment))
.filter((segment) => segment !== '')

Expand Down
2 changes: 1 addition & 1 deletion packages/starlight-typedoc/libs/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function bootstrapApp(
function onRendererPageEnd(event: PageEvent<DeclarationReflection>, pagination: boolean) {
if (!event.contents) {
return
} else if (/^.+\/README\.md$/.test(event.url)) {
} else if (/^.+[/\\]README\.md$/.test(event.url)) {
// Do not save `README.md` files for multiple entry points.
event.preventDefault()
return
Expand Down
7 changes: 4 additions & 3 deletions packages/starlight-typedoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"test": "pnpm test:unit && pnpm test:e2e",
"test:unit": "vitest",
"test:e2e": "pnpm run test:e2e:basics && pnpm run test:e2e:packages && pnpm run test:e2e:plugins",
"test:e2e:basics": "TEST_TYPE=basics pnpm run playwright",
"test:e2e:packages": "TEST_TYPE=packages pnpm run playwright",
"test:e2e:plugins": "TEST_TYPE=plugins pnpm run playwright",
"test:e2e:basics": "cross-env TEST_TYPE=basics pnpm run playwright",
"test:e2e:packages": "cross-env TEST_TYPE=packages pnpm run playwright",
"test:e2e:plugins": "cross-env TEST_TYPE=plugins pnpm run playwright",
"playwright": "playwright install --with-deps chromium && playwright test",
"lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
},
Expand All @@ -30,6 +30,7 @@
"@playwright/test": "1.35.0",
"@types/node": "18.16.16",
"astro": "4.0.6",
"cross-env": "7.0.3",
"typescript": "5.1.6",
"vitest": "1.0.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('should not include pagination links by default', async ({ docPage }) => {
await expect(prev).not.toBeVisible()
})

test('should not include pagination links if configured to do so', async ({ docPage }) => {
test('should include pagination links if configured to do so', async ({ docPage }) => {
docPage.useMultipleEntryPoints()

await docPage.goto('bar/classes/bar')
Expand Down
6 changes: 4 additions & 2 deletions packages/starlight-typedoc/tests/unit/typedoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test('should generate the doc in `src/content/docs/api` by default', async () =>
const mkdirSyncSpy = vi.mocked(fs.mkdirSync)

expect(mkdirSyncSpy).toHaveBeenCalled()
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString().endsWith(`src/content/docs/api`)).toBe(true)
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString()).toMatch(/src[/\\]content[/\\]docs[/\\]api$/)
})

test('should generate the doc in a custom output directory relative to `src/content/docs/`', async () => {
Expand All @@ -78,7 +78,9 @@ test('should generate the doc in a custom output directory relative to `src/cont
const mkdirSyncSpy = vi.mocked(fs.mkdirSync)

expect(mkdirSyncSpy).toHaveBeenCalled()
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString().endsWith(`src/content/docs/${output}`)).toBe(true)
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString()).toMatch(
new RegExp(`src[/\\\\]content[/\\\\]docs[/\\\\]${output}$`),
)
})

test('should not add `README.md` module files for multiple entry points', async () => {
Expand Down
12 changes: 12 additions & 0 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 6514c65

Please sign in to comment.