Skip to content

Commit

Permalink
fix(utils): always match exclusion root dirs as complete folder paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Aug 1, 2022
1 parent 3a0e90e commit 225c090
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/docusaurus-utils/src/__tests__/globUtils.test.ts
Expand Up @@ -113,4 +113,21 @@ describe('createAbsoluteFilePathMatcher', () => {
`"createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=/bad/path/myDoc.md was not contained in any of the root folders: /_root/docs, /root/_docs/, /__test__/website/src"`,
);
});

it('matches paths with overlapping paths', () => {
const overlapMatcher = createAbsoluteFilePathMatcher(GlobExcludeDefault, [
'/root/docs',
'/root/versioned_docs/version-2.0.0',
'/root/versioned_docs/version-2.0.0-rc.1',
]);
expect(
overlapMatcher('/root/versioned_docs/version-2.0.0-rc.1/_partial.mdx'),
).toBe(true);
expect(
overlapMatcher('/root/versioned_docs/version-2.0.0/_partial.mdx'),
).toBe(true);
expect(
overlapMatcher('/root/versioned_docs/version-2.0.0/no-partial.mdx'),
).toBe(false);
});
});
3 changes: 2 additions & 1 deletion packages/docusaurus-utils/src/globUtils.ts
Expand Up @@ -9,6 +9,7 @@

import path from 'path';
import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby
import {addTrailingSlash} from './urlUtils';

/** A re-export of the globby instance. */
export {default as Globby} from 'globby';
Expand Down Expand Up @@ -68,7 +69,7 @@ export function createAbsoluteFilePathMatcher(

function getRelativeFilePath(absoluteFilePath: string) {
const rootFolder = rootFolders.find((folderPath) =>
absoluteFilePath.startsWith(folderPath),
absoluteFilePath.startsWith(addTrailingSlash(folderPath)),
);
if (!rootFolder) {
throw new Error(
Expand Down

0 comments on commit 225c090

Please sign in to comment.