chore(v2): replace few Lodash methods with native counterparts (#2529)

This commit is contained in:
Bartosz Kaszubowski 2020-04-05 06:18:01 +02:00 committed by GitHub
parent 3dd83be988
commit 84baab33b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 32 deletions

View file

@ -10,7 +10,6 @@ import chalk = require('chalk');
import chokidar from 'chokidar'; import chokidar from 'chokidar';
import express from 'express'; import express from 'express';
import HtmlWebpackPlugin from 'html-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin';
import _ from 'lodash';
import path from 'path'; import path from 'path';
import portfinder from 'portfinder'; import portfinder from 'portfinder';
import openBrowser from 'react-dev-utils/openBrowser'; import openBrowser from 'react-dev-utils/openBrowser';
@ -64,11 +63,12 @@ export async function start(
return posixPath(filepath); return posixPath(filepath);
}; };
const pluginPaths: string[] = _.compact( const pluginPaths: string[] = ([] as string[]).concat(
_.flatten<string | undefined>( ...plugins
plugins.map(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch()), .map<any>(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch())
), .filter(Boolean)
).map(normalizeToSiteDir); .map(normalizeToSiteDir),
);
const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], { const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
cwd: siteDir, cwd: siteDir,
ignoreInitial: true, ignoreInitial: true,

View file

@ -5,19 +5,12 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import _ from 'lodash';
import {Plugin} from '@docusaurus/types'; import {Plugin} from '@docusaurus/types';
export function loadClientModules(plugins: Plugin<any>[]): string[] { export function loadClientModules(plugins: Plugin<any>[]): string[] {
return _.compact( return ([] as string[]).concat(
_.flatten<string | null>( ...plugins
plugins.map(plugin => { .map<any>(plugin => plugin.getClientModules && plugin.getClientModules())
if (!plugin.getClientModules) { .filter(Boolean),
return null;
}
return plugin.getClientModules();
}),
),
); );
} }

View file

@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import _ from 'lodash';
import {htmlTagObjectToString} from './htmlTags'; import {htmlTagObjectToString} from './htmlTags';
import { import {
Plugin, Plugin,
@ -19,7 +18,7 @@ function toString(val: string | HtmlTagObject): string {
} }
export function createHtmlTagsString(tags: HtmlTags): string { export function createHtmlTagsString(tags: HtmlTags): string {
return _.isArray(tags) ? tags.map(toString).join('\n') : toString(tags); return Array.isArray(tags) ? tags.map(toString).join('\n') : toString(tags);
} }
export function loadHtmlTags(plugins: Plugin<any>[]): InjectedHtmlTags { export function loadHtmlTags(plugins: Plugin<any>[]): InjectedHtmlTags {

View file

@ -6,7 +6,6 @@
*/ */
import {generate} from '@docusaurus/utils'; import {generate} from '@docusaurus/utils';
import _ from 'lodash';
import path from 'path'; import path from 'path';
import { import {
BUILD_DIR_NAME, BUILD_DIR_NAME,
@ -85,8 +84,10 @@ export async function load(
// Themes. // Themes.
const fallbackTheme = path.resolve(__dirname, '../client/theme-fallback'); const fallbackTheme = path.resolve(__dirname, '../client/theme-fallback');
const pluginThemes = _.compact( const pluginThemes = ([] as string[]).concat(
plugins.map(plugin => plugin.getThemePath && plugin.getThemePath()), ...plugins
.map<any>(plugin => plugin.getThemePath && plugin.getThemePath())
.filter(Boolean),
); );
const userTheme = path.resolve(siteDir, THEME_PATH); const userTheme = path.resolve(siteDir, THEME_PATH);
const alias = loadThemeAlias([fallbackTheme, ...pluginThemes], [userTheme]); const alias = loadThemeAlias([fallbackTheme, ...pluginThemes], [userTheme]);

View file

@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import _ from 'lodash';
import importFresh from 'import-fresh'; import importFresh from 'import-fresh';
import {LoadContext, Plugin, PluginConfig} from '@docusaurus/types'; import {LoadContext, Plugin, PluginConfig} from '@docusaurus/types';
@ -16,8 +15,8 @@ export function initPlugins({
pluginConfigs: PluginConfig[]; pluginConfigs: PluginConfig[];
context: LoadContext; context: LoadContext;
}): Plugin<any>[] { }): Plugin<any>[] {
const plugins: Plugin<any>[] = _.compact( const plugins: Plugin<any>[] = pluginConfigs
pluginConfigs.map(pluginItem => { .map(pluginItem => {
let pluginModuleImport; let pluginModuleImport;
let pluginOptions = {}; let pluginOptions = {};
@ -40,8 +39,8 @@ export function initPlugins({
// module identifier - npm package or locally-resolved path. // module identifier - npm package or locally-resolved path.
const pluginModule: any = importFresh(pluginModuleImport); const pluginModule: any = importFresh(pluginModuleImport);
return (pluginModule.default || pluginModule)(context, pluginOptions); return (pluginModule.default || pluginModule)(context, pluginOptions);
}), })
); .filter(Boolean);
return plugins; return plugins;
} }

View file

@ -6,7 +6,6 @@
*/ */
import importFresh from 'import-fresh'; import importFresh from 'import-fresh';
import _ from 'lodash';
import { import {
LoadContext, LoadContext,
PluginConfig, PluginConfig,
@ -47,7 +46,7 @@ export function loadPresets(
}); });
return { return {
plugins: _.compact(_.flatten<PluginConfig>(unflatPlugins)), plugins: ([] as PluginConfig[]).concat(...unflatPlugins).filter(Boolean),
themes: _.compact(_.flatten<PluginConfig>(unflatThemes)), themes: ([] as PluginConfig[]).concat(...unflatThemes).filter(Boolean),
}; };
} }

View file

@ -85,7 +85,7 @@ export async function loadRoutes(
return null; return null;
} }
if (_.isArray(value)) { if (Array.isArray(value)) {
return value.map((val, index) => return value.map((val, index) =>
genRouteChunkNames(val, `${index}`, name), genRouteChunkNames(val, `${index}`, name),
); );
@ -113,7 +113,8 @@ export async function loadRoutes(
return newValue; return newValue;
} }
routesChunkNames[routePath] = _.assign( routesChunkNames[routePath] = Object.assign(
{},
routesChunkNames[routePath], routesChunkNames[routePath],
genRouteChunkNames({component}, 'component', component), genRouteChunkNames({component}, 'component', component),
genRouteChunkNames(modules, 'module', routePath), genRouteChunkNames(modules, 'module', routePath),