From 6e8acb12b040a040b5e633468cc98fe59f40071d Mon Sep 17 00:00:00 2001 From: Bartosz Kaszubowski Date: Sun, 5 Apr 2020 11:36:01 +0200 Subject: [PATCH] refactor(v2): replace Lodash with single methods packages in core --- packages/docusaurus/package.json | 4 +++- packages/docusaurus/src/server/config.ts | 4 ++-- .../docusaurus/src/server/html-tags/htmlTags.ts | 4 ++-- packages/docusaurus/src/server/routes.ts | 14 ++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index f81d1e9fb2a6..e659101a16ea 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -60,7 +60,9 @@ "html-tags": "^3.1.0", "html-webpack-plugin": "^4.0.4", "import-fresh": "^3.2.1", - "lodash": "^4.17.15", + "lodash.has": "^4.5.2", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", "mini-css-extract-plugin": "^0.8.0", "nprogress": "^0.2.0", "null-loader": "^3.0.0", diff --git a/packages/docusaurus/src/server/config.ts b/packages/docusaurus/src/server/config.ts index ab631f6b96d9..309f0b9c9337 100644 --- a/packages/docusaurus/src/server/config.ts +++ b/packages/docusaurus/src/server/config.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import importFresh from 'import-fresh'; -import _ from 'lodash'; +import has from 'lodash.has'; import path from 'path'; import {CONFIG_FILE_NAME} from '../constants'; import {DocusaurusConfig, PluginConfig} from '@docusaurus/types'; @@ -57,7 +57,7 @@ export function loadConfig(siteDir: string): DocusaurusConfig { const loadedConfig = importFresh(configPath) as Partial; const missingFields = REQUIRED_FIELDS.filter( - field => !_.has(loadedConfig, field), + field => !has(loadedConfig, field), ); if (missingFields.length > 0) { diff --git a/packages/docusaurus/src/server/html-tags/htmlTags.ts b/packages/docusaurus/src/server/html-tags/htmlTags.ts index 87357d1e726d..fc0b33571133 100644 --- a/packages/docusaurus/src/server/html-tags/htmlTags.ts +++ b/packages/docusaurus/src/server/html-tags/htmlTags.ts @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -import _ from 'lodash'; +import isPlainObject from 'lodash.isplainobject'; import {HtmlTagObject} from '@docusaurus/types'; import htmlTags from 'html-tags'; import voidHtmlTags from 'html-tags/void'; function assertIsHtmlTagObject(val: any): asserts val is HtmlTagObject { - if (!_.isPlainObject(val)) { + if (!isPlainObject(val)) { throw new Error(`"${val}" is not a valid HTML tag object`); } if (typeof val.tagName !== 'string') { diff --git a/packages/docusaurus/src/server/routes.ts b/packages/docusaurus/src/server/routes.ts index 1e3586c6d1fb..46497b9053ee 100644 --- a/packages/docusaurus/src/server/routes.ts +++ b/packages/docusaurus/src/server/routes.ts @@ -6,7 +6,9 @@ */ import {genChunkName, normalizeUrl} from '@docusaurus/utils'; -import _ from 'lodash'; +import has from 'lodash.has'; +import isPlainObject from 'lodash.isplainobject'; +import isString from 'lodash.isstring'; import {stringify} from 'querystring'; import { ChunkRegistry, @@ -17,14 +19,10 @@ import { } from '@docusaurus/types'; function isModule(value: any): value is Module { - if (_.isString(value)) { + if (isString(value)) { return true; } - if ( - _.isPlainObject(value) && - _.has(value, '__import') && - _.has(value, 'path') - ) { + if (isPlainObject(value) && has(value, '__import') && has(value, 'path')) { return true; } return false; @@ -64,7 +62,7 @@ export async function loadRoutes( exact, } = routeConfig; - if (!_.isString(routePath) || !component) { + if (!isString(routePath) || !component) { throw new Error( `Invalid routeConfig (Path must be a string and component is required) \n${JSON.stringify( routeConfig,