Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function resolveSidebarPathOption(
async function readCategoriesMetadata(contentPath: string) {
const categoryFiles = await Globby('**/_category_.{json,yml,yaml}', {
cwd: contentPath,
ignore: ['**/node_modules/**'],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment here: #12129 (comment)

This will make another legit use-case impossible.

We'd like to optimize, without preventing the content path being node_modules/@myCompany/docs. I'd like to see a test covering this edge case that keeps passing after the performance optimization.

});
const categoryToFile = _.groupBy(categoryFiles, path.dirname);
return combinePromises(
Expand Down
17 changes: 16 additions & 1 deletion packages/docusaurus-utils/src/__tests__/globUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ describe('isTranslatableSourceFile', () => {
});

describe('createMatcher', () => {
it('match default exclude node_modules correctly', () => {
const matcher = createMatcher(GlobExcludeDefault);
expect(matcher('node_modules/pkg/doc.md')).toBe(true);
expect(matcher('node_modules/pkg/index.js')).toBe(true);
expect(matcher('category/node_modules/pkg/doc.md')).toBe(true);
expect(matcher('category/node_modules/@scope/pkg/doc.md')).toBe(true);
});

it('match default exclude MD/MDX partials correctly', () => {
const matcher = createMatcher(GlobExcludeDefault);
expect(matcher('doc.md')).toBe(false);
Expand Down Expand Up @@ -115,8 +123,15 @@ describe('createAbsoluteFilePathMatcher', () => {
expect(matcher('/root/_docs/_category/myDoc.mdx')).toBe(true);
});

it('match default exclude node_modules correctly', () => {
expect(matcher('/_root/docs/node_modules/pkg/doc.md')).toBe(true);
expect(matcher('/_root/docs/node_modules/@scope/pkg/doc.md')).toBe(true);
expect(
matcher('/_root/docs/category/node_modules/pkg/index.js'),
).toBe(true);
});

it('match default exclude tests correctly', () => {
expect(matcher('/__test__/website/src/xyz.js')).toBe(false);
expect(matcher('/__test__/website/src/__test__/xyz.js')).toBe(true);
expect(matcher('/__test__/website/src/xyz.test.js')).toBe(true);
});
Expand Down
1 change: 1 addition & 0 deletions packages/docusaurus-utils/src/globUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Globby = Tinyglobby.glob;
* - Ignore tests
*/
export const GlobExcludeDefault = [
'**/node_modules/**',
'**/_*.{js,jsx,ts,tsx,md,mdx}',
'**/_*/**',
'**/*.test.{js,jsx,ts,tsx}',
Expand Down
Loading