From 7d8a703fd8ec6b226ddf535d187b214079042e78 Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Fri, 10 May 2024 08:36:30 +0100 Subject: [PATCH] fix(core): correctly handle excludeScopesInPaths in windows (#610) --- .../src/libs/utils/remove-first-scoped-directory.ts | 6 ++++-- .../src/theme/resources/partials/page.header.ts | 8 +++++++- .../test/specs/__snapshots__/packages.spec.ts.snap | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/remove-first-scoped-directory.ts b/packages/typedoc-plugin-markdown/src/libs/utils/remove-first-scoped-directory.ts index fcefae041..52cae853f 100644 --- a/packages/typedoc-plugin-markdown/src/libs/utils/remove-first-scoped-directory.ts +++ b/packages/typedoc-plugin-markdown/src/libs/utils/remove-first-scoped-directory.ts @@ -1,10 +1,12 @@ +import * as path from 'path'; + export function removeFirstScopedDirectory(urlString: string): string { - const pathParts = urlString.split('/'); + const pathParts = urlString.replace(/\//g, path.sep).split(path.sep); const scopedDirectoryIndex = pathParts.findIndex((part) => part.startsWith('@'), ); if (scopedDirectoryIndex !== -1) { pathParts.splice(scopedDirectoryIndex, 1); } - return pathParts.join('/'); + return pathParts.join(path.sep); } diff --git a/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.header.ts b/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.header.ts index c3faf6c6c..36ea1d77c 100644 --- a/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.header.ts +++ b/packages/typedoc-plugin-markdown/src/theme/resources/partials/page.header.ts @@ -1,4 +1,5 @@ import { bold, link } from '@plugin/libs/markdown'; +import { removeFirstScopedDirectory } from '@plugin/libs/utils'; import { MarkdownThemeContext } from '@plugin/theme'; import * as path from 'path'; import { @@ -94,6 +95,7 @@ export function header(this: MarkdownThemeContext): string { const indexLabel = this.getText('header.docs'); + const ignoreScopes = this.options.getValue('excludeScopesInPaths'); const fileExtension = this.options.getValue('fileExtension'); const entryFileName = `${path.parse(this.options.getValue('entryFileName')).name}${fileExtension}`; @@ -103,7 +105,11 @@ export function header(this: MarkdownThemeContext): string { const packagesMeta = this.getPackageMetaData(packageItem.name); const entryModule = packagesMeta.options?.getValue('entryModule'); - const packageEntryFile = `${packageItem.name}/${entryFileName}`; + const packageEntryFile = ignoreScopes + ? removeFirstScopedDirectory( + `${packageItem.name}${path.sep}${entryFileName}`, + ) + : `${packageItem.name}${path.sep}${entryFileName}`; if (this.page.url === packageEntryFile || Boolean(entryModule)) { md.push(bold(packageItemName)); diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/packages.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/packages.spec.ts.snap index 2bdae7bb6..ae4f13b8a 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/packages.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/packages.spec.ts.snap @@ -112,7 +112,7 @@ exports[`Packages should compile member page for packages: (Output File Strategy `; exports[`Packages should compile member page for packages: (Output File Strategy "members") (Option Group "2") 1`] = ` -"[**@scope/package-1 v1.0.0**](../../@scope/package-1/README.md) • **Docs** +"[**@scope/package-1 v1.0.0**](../README.md) • **Docs** ***