Skip to content

Commit

Permalink
fix: remove duplicated lodash dependencies and optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Mar 8, 2021
1 parent 2a25124 commit 2232ec3
Show file tree
Hide file tree
Showing 37 changed files with 63 additions and 167 deletions.
11 changes: 1 addition & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,7 @@
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/loader-utils": "^1.1.3",
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.flatmap": "^4.5.6",
"@types/lodash.groupby": "^4.6.6",
"@types/lodash.has": "^4.5.6",
"@types/lodash.isplainobject": "^4.0.6",
"@types/lodash.isstring": "^4.0.6",
"@types/lodash.kebabcase": "^4.1.6",
"@types/lodash.pick": "^4.4.6",
"@types/lodash.pickby": "^4.6.6",
"@types/lodash.sortby": "^4.6.6",
"@types/lodash": "^4.6.6",
"@types/node": "^14.14.22",
"@types/prismjs": "^1.16.2",
"@types/prompts": "^2.0.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"chalk": "^4.1.0",
"commander": "^5.1.0",
"fs-extra": "^9.1.0",
"lodash.kebabcase": "^4.1.1",
"lodash": "^4.17.20",
"prompts": "^2.4.0",
"semver": "^7.3.4",
"shelljs": "^0.8.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {execSync} from 'child_process';
import prompts, {Choice} from 'prompts';
import path from 'path';
import shell from 'shelljs';
import kebabCase from 'lodash.kebabcase';
import kebabCase from 'lodash/kebabCase';

function hasYarn(): boolean {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import {flatten, uniqBy, difference, groupBy} from 'lodash';
import flatten from 'lodash/flatten';
import uniqBy from 'lodash/uniqBy';
import difference from 'lodash/difference';
import groupBy from 'lodash/groupBy';
import {
PluginContext,
RedirectMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as eta from 'eta';
import redirectPageTemplate from './templates/redirectPage.template.html';
import {memoize} from 'lodash';
import memoize from 'lodash/memoize';

type CreateRedirectPageOptions = {
toUrl: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {flatten} from 'lodash';
import flatten from 'lodash/flatten';
import {removeSuffix} from '@docusaurus/utils';
import {RedirectMetadata} from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import fs from 'fs-extra';
import path from 'path';
import {memoize} from 'lodash';
import memoize from 'lodash/memoize';

import {PluginContext, RedirectMetadata} from './types';
import createRedirectPageContent from './createRedirectPageContent';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/src/blogUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
getDateTimeFormat,
} from '@docusaurus/utils';
import {LoadContext} from '@docusaurus/types';
import {keyBy} from 'lodash';
import keyBy from 'lodash/keyBy';

export function truncate(fileString: string, truncateMarker: RegExp): string {
return fileString.split(truncateMarker, 1).shift()!;
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import {
DEFAULT_PLUGIN_ID,
} from '@docusaurus/core/lib/constants';
import {ValidationError} from 'joi';
import {flatten, take, kebabCase} from 'lodash';
import flatten from 'lodash/flatten';
import take from 'lodash/take';
import kebabCase from 'lodash/kebabCase';

import {
PluginOptions,
Expand Down
5 changes: 0 additions & 5 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@
"joi": "^17.4.0",
"loader-utils": "^1.2.3",
"lodash": "^4.17.19",
"lodash.flatmap": "^4.5.0",
"lodash.groupby": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.pickby": "^4.6.0",
"lodash.sortby": "^4.6.0",
"remark-admonitions": "^1.2.1",
"shelljs": "^0.8.4",
"utility-types": "^3.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import path from 'path';
import {isMatch} from 'picomatch';
import commander from 'commander';
import {kebabCase} from 'lodash';
import kebabCase from 'lodash/kebabCase';

import fs from 'fs-extra';
import pluginContentDocs from '../index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getDocVersionSuggestions,
} from '../docsClientUtils';
import {GlobalPluginData, GlobalVersion} from '../../types';
import {shuffle} from 'lodash';
import shuffle from 'lodash/shuffle';

describe('docsClientUtils', () => {
test('getActivePlugin', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import {RuleSetRule} from 'webpack';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
import {OptionsSchema} from './options';
import {flatten, keyBy, compact} from 'lodash';
import keyBy from 'lodash/keyBy';
import compact from 'lodash/compact';
import flatten from 'lodash/flatten';
import {toGlobalDataVersion} from './globalData';
import {toVersionMetadataProp} from './props';
import {
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
PropVersionMetadata,
PropSidebarItem,
} from '@docusaurus/plugin-content-docs-types';
import {keyBy, mapValues} from 'lodash';
import keyBy from 'lodash/keyBy';
import mapValues from 'lodash/mapValues';

export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
const docsById = keyBy(loadedVersion.docs, (doc) => doc.id);
Expand Down
6 changes: 4 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import flatMap from 'lodash.flatmap';
import fs from 'fs-extra';
import importFresh from 'import-fresh';
import {
Expand All @@ -18,7 +17,10 @@ import {
SidebarItemCategory,
SidebarItemType,
} from './types';
import {mapValues, flatten, difference} from 'lodash';
import flatMap from 'lodash/flatMap';
import mapValues from 'lodash/mapValues';
import flatten from 'lodash/flatten';
import difference from 'lodash/difference';
import {getElementsAround} from '@docusaurus/utils';

type SidebarItemCategoryJSON = SidebarItemBase & {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
import {LoadContext} from '@docusaurus/types';
import {getPluginI18nPath, normalizeUrl, posixPath} from '@docusaurus/utils';
import {difference} from 'lodash';
import difference from 'lodash/difference';
import chalk from 'chalk';

// retro-compatibility: no prefix for the default plugin id
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-pages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
Metadata,
PagesContentPaths,
} from './types';
import {flatten} from 'lodash';
import flatten from 'lodash/flatten';

export function getContentPathList(contentPaths: PagesContentPaths): string[] {
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
Expand Down
4 changes: 3 additions & 1 deletion packages/docusaurus-theme-classic/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
Footer,
} from '@docusaurus/theme-common';

import {keyBy, chain, flatten} from 'lodash';
import keyBy from 'lodash/keyBy';
import chain from 'lodash/chain';
import flatten from 'lodash/flatten';
import {mergeTranslations} from '@docusaurus/utils';

function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
Expand Down
2 changes: 0 additions & 2 deletions packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"intl": "^1.2.5",
"intl-locales-supported": "^1.8.12",
"lodash": "^4.17.20",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"resolve-pathname": "^3.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
readDefaultCodeTranslationMessages,
parseMarkdownHeadingId,
} from '../index';
import {sum} from 'lodash';
import sum from 'lodash/sum';

describe('load utils', () => {
test('aliasedSitePath', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import chalk from 'chalk';
import path from 'path';
import matter from 'gray-matter';
import {createHash} from 'crypto';
import camelCase from 'lodash.camelcase';
import kebabCase from 'lodash.kebabcase';
import camelCase from 'lodash/camelCase';
import kebabCase from 'lodash/kebabCase';
import escapeStringRegexp from 'escape-string-regexp';
import fs from 'fs-extra';
import {URL} from 'url';
Expand All @@ -22,7 +22,7 @@ import {

// @ts-expect-error: no typedefs :s
import resolvePathnameUnsafe from 'resolve-pathname';
import {mapValues} from 'lodash';
import mapValues from 'lodash/mapValues';
import areIntlLocalesSupported from 'intl-locales-supported';

const fileHash = new Map();
Expand Down
4 changes: 0 additions & 4 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
"joi": "^17.4.0",
"leven": "^3.1.0",
"lodash": "^4.17.20",
"lodash.flatmap": "^4.5.0",
"lodash.has": "^4.5.2",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"mini-css-extract-plugin": "^0.8.0",
"module-alias": "^2.2.2",
"nprogress": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/client/serverEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from './LinksCollector';
import chalk from 'chalk';
// eslint-disable-next-line no-restricted-imports
import {memoize} from 'lodash';
import memoize from 'lodash/memoize';

const getCompiledSSRTemplate = memoize((template) => {
return eta.compile(template.trim(), {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/commands/swizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import importFresh from 'import-fresh';
import path from 'path';
import {Plugin, LoadContext, PluginConfig} from '@docusaurus/types';
import leven from 'leven';
import {partition} from 'lodash';
import partition from 'lodash/partition';
import {THEME_PATH} from '../constants';
import {loadContext, loadPluginConfigs} from '../server';
import initPlugins from '../server/plugins/init';
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus/src/server/brokenLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import {matchRoutes, RouteConfig as RRRouteConfig} from 'react-router-config';
import resolvePathname from 'resolve-pathname';
import fs from 'fs-extra';
import {mapValues, pickBy, flatten, countBy} from 'lodash';
import mapValues from 'lodash/mapValues';
import pickBy from 'lodash/pickBy';
import flatten from 'lodash/flatten';
import countBy from 'lodash/countBy';
import {RouteConfig, ReportingSeverity} from '@docusaurus/types';
import {removePrefix, removeSuffix, reportMessage} from '@docusaurus/utils';
import {getAllFinalRoutes} from './utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/html-tags/htmlTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import isPlainObject from 'lodash.isplainobject';
import isPlainObject from 'lodash/isPlainObject';
import {HtmlTagObject} from '@docusaurus/types';
import htmlTags from 'html-tags';
import voidHtmlTags from 'html-tags/void';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
readCodeTranslationFileContent,
getPluginsDefaultCodeTranslationMessages,
} from './translations/translations';
import {mapValues} from 'lodash';
import mapValues from 'lodash/mapValues';

type LoadContextOptions = {
customOutDir?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/plugins/pluginIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {groupBy} from 'lodash';
import groupBy from 'lodash/groupBy';
import {InitPlugin} from './init';
import {DEFAULT_PLUGIN_ID} from '../../constants';

Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
removeSuffix,
simpleHash,
} from '@docusaurus/utils';
import has from 'lodash.has';
import isPlainObject from 'lodash.isplainobject';
import isString from 'lodash.isstring';
import has from 'lodash/has';
import isPlainObject from 'lodash/isPlainObject';
import isString from 'lodash/isString';
import {stringify} from 'querystring';
import {
ChunkRegistry,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/themes/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import fs from 'fs-extra';
import path from 'path';
import {fileToPath, posixPath, normalizeUrl} from '@docusaurus/utils';
import {ThemeAlias} from '@docusaurus/types';
import {sortBy} from 'lodash';
import sortBy from 'lodash/sortBy';

export default function themeAlias(
themePath: string,
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus/src/server/translations/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import path from 'path';
import fs from 'fs-extra';
import {InitPlugin} from '../plugins/init';
import {mapValues, difference} from 'lodash';
import mapValues from 'lodash/mapValues';
import difference from 'lodash/difference';
import {
TranslationFileContent,
TranslationFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import traverse, {Node} from '@babel/traverse';
import generate from '@babel/generator';
import chalk from 'chalk';
import {parse, types as t, NodePath, TransformOptions} from '@babel/core';
import {flatten} from 'lodash';
import flatten from 'lodash/flatten';
import {TranslationFileContent, TranslationMessage} from '@docusaurus/types';
import globby from 'globby';
import nodePath from 'path';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import flatMap from 'lodash.flatmap';
import flatMap from 'lodash/flatMap';
import {RouteConfig} from '@docusaurus/types';

// Recursively get the final routes (routes with no subroutes)
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/webpack/__tests__/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
createBaseConfig,
} from '../base';
import * as utils from '../utils';
import {mapValues} from 'lodash';
import mapValues from 'lodash/mapValues';
import {posixPath} from '@docusaurus/utils';

describe('babel transpilation exclude logic', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lqip-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"file-loader": "^6.2.0",
"loader-utils": "^1.2.3",
"lodash.sortby": "^4.7.0",
"lodash": "^4.17.21",
"node-vibrant": "^3.1.5",
"sharp": "^0.27.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/lqip-loader/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// @ts-check

const sortBy = require('lodash.sortby');
const sortBy = require('lodash/sortBy');

/**
* toBase64
Expand Down
Loading

0 comments on commit 2232ec3

Please sign in to comment.