Skip to content

Commit

Permalink
fix(core): correctly handle excludeScopesInPaths in windows (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed May 10, 2024
1 parent de93833 commit 7d8a703
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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}`;

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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**
***
Expand Down

0 comments on commit 7d8a703

Please sign in to comment.