mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 18:32:52 +02:00
chore(v2): replace few Lodash methods with native counterparts (#2529)
This commit is contained in:
parent
3dd83be988
commit
84baab33b4
7 changed files with 24 additions and 32 deletions
|
@ -10,7 +10,6 @@ import chalk = require('chalk');
|
|||
import chokidar from 'chokidar';
|
||||
import express from 'express';
|
||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||
import _ from 'lodash';
|
||||
import path from 'path';
|
||||
import portfinder from 'portfinder';
|
||||
import openBrowser from 'react-dev-utils/openBrowser';
|
||||
|
@ -64,11 +63,12 @@ export async function start(
|
|||
return posixPath(filepath);
|
||||
};
|
||||
|
||||
const pluginPaths: string[] = _.compact(
|
||||
_.flatten<string | undefined>(
|
||||
plugins.map(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch()),
|
||||
),
|
||||
).map(normalizeToSiteDir);
|
||||
const pluginPaths: string[] = ([] as string[]).concat(
|
||||
...plugins
|
||||
.map<any>(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch())
|
||||
.filter(Boolean)
|
||||
.map(normalizeToSiteDir),
|
||||
);
|
||||
const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
|
||||
cwd: siteDir,
|
||||
ignoreInitial: true,
|
||||
|
|
|
@ -5,19 +5,12 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import {Plugin} from '@docusaurus/types';
|
||||
|
||||
export function loadClientModules(plugins: Plugin<any>[]): string[] {
|
||||
return _.compact(
|
||||
_.flatten<string | null>(
|
||||
plugins.map(plugin => {
|
||||
if (!plugin.getClientModules) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return plugin.getClientModules();
|
||||
}),
|
||||
),
|
||||
return ([] as string[]).concat(
|
||||
...plugins
|
||||
.map<any>(plugin => plugin.getClientModules && plugin.getClientModules())
|
||||
.filter(Boolean),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import {htmlTagObjectToString} from './htmlTags';
|
||||
import {
|
||||
Plugin,
|
||||
|
@ -19,7 +18,7 @@ function toString(val: string | HtmlTagObject): 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 {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import {generate} from '@docusaurus/utils';
|
||||
import _ from 'lodash';
|
||||
import path from 'path';
|
||||
import {
|
||||
BUILD_DIR_NAME,
|
||||
|
@ -85,8 +84,10 @@ export async function load(
|
|||
|
||||
// Themes.
|
||||
const fallbackTheme = path.resolve(__dirname, '../client/theme-fallback');
|
||||
const pluginThemes = _.compact(
|
||||
plugins.map(plugin => plugin.getThemePath && plugin.getThemePath()),
|
||||
const pluginThemes = ([] as string[]).concat(
|
||||
...plugins
|
||||
.map<any>(plugin => plugin.getThemePath && plugin.getThemePath())
|
||||
.filter(Boolean),
|
||||
);
|
||||
const userTheme = path.resolve(siteDir, THEME_PATH);
|
||||
const alias = loadThemeAlias([fallbackTheme, ...pluginThemes], [userTheme]);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import importFresh from 'import-fresh';
|
||||
import {LoadContext, Plugin, PluginConfig} from '@docusaurus/types';
|
||||
|
||||
|
@ -16,8 +15,8 @@ export function initPlugins({
|
|||
pluginConfigs: PluginConfig[];
|
||||
context: LoadContext;
|
||||
}): Plugin<any>[] {
|
||||
const plugins: Plugin<any>[] = _.compact(
|
||||
pluginConfigs.map(pluginItem => {
|
||||
const plugins: Plugin<any>[] = pluginConfigs
|
||||
.map(pluginItem => {
|
||||
let pluginModuleImport;
|
||||
let pluginOptions = {};
|
||||
|
||||
|
@ -40,8 +39,8 @@ export function initPlugins({
|
|||
// module identifier - npm package or locally-resolved path.
|
||||
const pluginModule: any = importFresh(pluginModuleImport);
|
||||
return (pluginModule.default || pluginModule)(context, pluginOptions);
|
||||
}),
|
||||
);
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import importFresh from 'import-fresh';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
LoadContext,
|
||||
PluginConfig,
|
||||
|
@ -47,7 +46,7 @@ export function loadPresets(
|
|||
});
|
||||
|
||||
return {
|
||||
plugins: _.compact(_.flatten<PluginConfig>(unflatPlugins)),
|
||||
themes: _.compact(_.flatten<PluginConfig>(unflatThemes)),
|
||||
plugins: ([] as PluginConfig[]).concat(...unflatPlugins).filter(Boolean),
|
||||
themes: ([] as PluginConfig[]).concat(...unflatThemes).filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ export async function loadRoutes(
|
|||
return null;
|
||||
}
|
||||
|
||||
if (_.isArray(value)) {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((val, index) =>
|
||||
genRouteChunkNames(val, `${index}`, name),
|
||||
);
|
||||
|
@ -113,7 +113,8 @@ export async function loadRoutes(
|
|||
return newValue;
|
||||
}
|
||||
|
||||
routesChunkNames[routePath] = _.assign(
|
||||
routesChunkNames[routePath] = Object.assign(
|
||||
{},
|
||||
routesChunkNames[routePath],
|
||||
genRouteChunkNames({component}, 'component', component),
|
||||
genRouteChunkNames(modules, 'module', routePath),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue