diff --git a/package.json b/package.json index f7119f623988..6678eb718772 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,11 @@ "@types/jest": "^24.0.23", "@types/loader-utils": "^1.1.3", "@types/lodash": "^4.14.149", + "@types/lodash.flatmap": "^4.5.6", + "@types/lodash.groupby": "^4.6.6", "@types/lodash.kebabcase": "^4.1.6", + "@types/lodash.pick": "^4.4.6", + "@types/lodash.pickby": "^4.6.6", "@types/node": "^12.12.14", "@types/react": "^16.9.13", "@types/react-dev-utils": "^9.0.1", diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index 7126ac68203d..6e92f6a73dad 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -23,7 +23,10 @@ "globby": "^10.0.1", "import-fresh": "^3.2.1", "loader-utils": "^1.2.3", - "lodash": "^4.17.15", + "lodash.flatmap": "^4.5.0", + "lodash.groupby": "^4.6.0", + "lodash.pick": "^4.4.0", + "lodash.pickby": "^4.6.0", "shelljs": "^0.8.3" }, "peerDependencies": { diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 8e1957e5f5bd..964e965d66c8 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -5,7 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -import _ from 'lodash'; +import groupBy from 'lodash.groupby'; +import pick from 'lodash.pick'; +import pickBy from 'lodash.pickby'; import globby from 'globby'; import fs from 'fs-extra'; import path from 'path'; @@ -101,13 +103,13 @@ export default function pluginContentDocs( const {include} = options; let globPattern = include.map(pattern => `${docsDir}/${pattern}`); if (versioning.enabled) { - const docsGlob = _.flatten( - include.map(pattern => + const docsGlob = include + .map(pattern => versionsNames.map( versionName => `${versionedDir}/${versionName}/${pattern}`, ), - ), - ); + ) + .reduce((a, b) => a.concat(b), []); const sidebarsGlob = versionsNames.map( versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`, ); @@ -149,11 +151,11 @@ export default function pluginContentDocs( // Metadata for versioned docs. if (versioning.enabled) { - const versionedGlob = _.flatten( - include.map(pattern => + const versionedGlob = include + .map(pattern => versionsNames.map(versionName => `${versionName}/${pattern}`), - ), - ); + ) + .reduce((a, b) => a.concat(b), []); const versionedFiles = await globby(versionedGlob, { cwd: versionedDir, }); @@ -338,7 +340,7 @@ export default function pluginContentDocs( // If versioning is enabled, we cleverly chunk the generated routes // to be by version and pick only needed base metadata. if (versioning.enabled) { - const docsMetadataByVersion = _.groupBy( + const docsMetadataByVersion = groupBy( Object.values(content.docsMetadata), 'version', ); @@ -358,13 +360,12 @@ export default function pluginContentDocs( const neededSidebars: Set = content.versionToSidebars[version] || new Set(); const docsBaseMetadata: DocsBaseMetadata = { - docsSidebars: _.pick( + docsSidebars: pick( content.docsSidebars, Array.from(neededSidebars), ), - permalinkToSidebar: _.pickBy( - content.permalinkToSidebar, - sidebar => neededSidebars.has(sidebar), + permalinkToSidebar: pickBy(content.permalinkToSidebar, sidebar => + neededSidebars.has(sidebar), ), version, }; diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars.ts b/packages/docusaurus-plugin-content-docs/src/sidebars.ts index 005c095458bb..e3b3a6ee4c86 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import _ from 'lodash'; +import flatMap from 'lodash.flatmap'; import fs from 'fs-extra'; import importFresh from 'import-fresh'; import { @@ -106,12 +106,12 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] { ]; } if (isCategoryShorthand(item)) { - return _.flatMap(normalizeCategoryShorthand(item), normalizeItem); + return flatMap(normalizeCategoryShorthand(item), normalizeItem); } switch (item.type) { case 'category': assertIsCategory(item); - return [{...item, items: _.flatMap(item.items, normalizeItem)}]; + return [{...item, items: flatMap(item.items, normalizeItem)}]; case 'link': assertIsLink(item); return [item]; @@ -134,7 +134,7 @@ function normalizeSidebar(sidebars: SidebarRaw): Sidebar { ? sidebar : normalizeCategoryShorthand(sidebar); - acc[sidebarId] = _.flatMap(normalizedSidebar, normalizeItem); + acc[sidebarId] = flatMap(normalizedSidebar, normalizeItem); return acc; },