Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): replace Lodash with single methods packages in core #2535

Merged
merged 1 commit into from
Apr 5, 2020
Merged
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
4 changes: 3 additions & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -57,7 +57,7 @@ export function loadConfig(siteDir: string): DocusaurusConfig {

const loadedConfig = importFresh(configPath) as Partial<DocusaurusConfig>;
const missingFields = REQUIRED_FIELDS.filter(
field => !_.has(loadedConfig, field),
field => !has(loadedConfig, field),
);

if (missingFields.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/server/html-tags/htmlTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
14 changes: 6 additions & 8 deletions packages/docusaurus/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down