Skip to content

Commit

Permalink
Change lodash to es
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Nov 3, 2021
1 parent 7ea7bd2 commit e022e38
Show file tree
Hide file tree
Showing 61 changed files with 155 additions and 137 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = {
{
paths: [
{
name: 'lodash',
name: 'lodash-es',
importNames: [
// 'compact', // TODO: TS doesn't make Boolean a narrowing function yet, so filter(Boolean) is problematic type-wise
'filter',
Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = {
},
},
{
files: ['*.js'],
files: ['*.js', '*.cjs'],
rules: {
// Make JS code directly runnable in Node.
'@typescript-eslint/no-var-requires': OFF,
Expand Down
6 changes: 0 additions & 6 deletions babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ module.exports = {
'@babel/react',
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
],
};
2 changes: 1 addition & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
testPathIgnorePatterns: ignorePatterns,
coveragePathIgnorePatterns: ignorePatterns,
transform: {
'^.+\\.[jt]sx?$': 'babel-jest',
'^.+\\.[cm]?[jt]sx?$': 'babel-jest',
},
setupFiles: ['./jest/stylelint-rule-test.js', './jest/polyfills.js'],
moduleNameMapper: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/loader-utils": "^2.0.3",
"@types/lodash": "^4.14.168",
"@types/lodash-es": "^4.17.5",
"@types/node": "^14.14.22",
"@types/prismjs": "^1.16.2",
"@types/prompts": "^2.0.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"chalk": "^4.1.2",
"commander": "^5.1.0",
"fs-extra": "^10.0.0",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"prompts": "^2.4.1",
"semver": "^7.3.4",
"shelljs": "^0.8.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-docusaurus/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, sortBy} from 'lodash';
import {kebabCase, sortBy} from 'lodash-es';
import supportsColor from 'supports-color';

const RecommendedTemplate = 'classic';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eta": "^1.12.3",
"fs-extra": "^10.0.0",
"globby": "^11.0.2",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"tslib": "^2.3.1"
},
"peerDependencies": {
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 {uniqBy, difference, groupBy} from 'lodash';
import {uniqBy, difference, groupBy} from 'lodash-es';
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-es';

type CreateRedirectPageOptions = {
toUrl: string;
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-es';

import {PluginContext, RedirectMetadata} from './types';
import createRedirectPageContent from './createRedirectPageContent';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"globby": "^11.0.2",
"js-yaml": "^4.0.0",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"reading-time": "^1.5.0",
"remark-admonitions": "^1.2.1",
"tslib": "^2.3.1",
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 @@ -9,7 +9,7 @@ import fs from 'fs-extra';
import chalk from 'chalk';
import path from 'path';
import readingTime from 'reading-time';
import {keyBy, mapValues} from 'lodash';
import {keyBy, mapValues} from 'lodash-es';
import {
PluginOptions,
BlogPost,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"import-fresh": "^3.2.2",
"js-yaml": "^4.0.0",
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"remark-admonitions": "^1.2.1",
"shelljs": "^0.8.4",
"tslib": "^2.3.1",
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, orderBy} from 'lodash';
import {kebabCase, orderBy} from 'lodash-es';

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-es';

describe('docsClientUtils', () => {
test('getActivePlugin', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import path from 'path';
import fs from 'fs-extra';
import chalk from 'chalk';
import {keyBy} from 'lodash';
import {keyBy} from 'lodash-es';
import {
aliasedSitePath,
getEditUrl,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import {RuleSetRule} from 'webpack';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
import {keyBy, mapValues} from 'lodash';
import {keyBy, mapValues} from 'lodash-es';
import {toGlobalDataVersion} from './globalData';
import {toTagDocListProp, toVersionMetadataProp} from './props';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
PropTagDocList,
PropTagDocListDoc,
} from '@docusaurus/plugin-content-docs-types';
import {compact, keyBy, mapValues} from 'lodash';
import {compact, keyBy, mapValues} from 'lodash-es';

export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
const docsById = keyBy(loadedVersion.docs, (doc) => doc.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
SidebarItemsGenerator,
SidebarItemsGeneratorDoc,
} from './types';
import {keyBy, sortBy} from 'lodash';
import {keyBy, sortBy} from 'lodash-es';
import {addTrailingSlash, posixPath} from '@docusaurus/utils';
import {Joi} from '@docusaurus/utils-validation';
import chalk from 'chalk';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
SidebarsConfig,
isCategoriesShorthand,
} from './types';
import {mapValues} from 'lodash';
import {mapValues} from 'lodash-es';

function normalizeCategoriesShorthand(
sidebar: SidebarCategoriesShorthand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
} from './types';
import {transformSidebarItems} from './utils';
import {DefaultSidebarItemsGenerator} from './generator';
import {mapValues, memoize, pick} from 'lodash';
import {mapValues, memoize, pick} from 'lodash-es';
import combinePromises from 'combine-promises';

export type SidebarProcessorProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
SidebarItemDoc,
SidebarItemType,
} from './types';
import {mapValues, difference} from 'lodash';
import {mapValues, difference} from 'lodash-es';
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';

export function transformSidebarItems(
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {groupTaggedItems} from '@docusaurus/utils';
import {VersionTags, DocMetadata} from './types';
import {mapValues} from 'lodash';
import {mapValues} from 'lodash-es';

export function getVersionTags(docs: DocMetadata[]): VersionTags {
const groups = groupTaggedItems(docs, (doc) => doc.tags);
Expand Down
26 changes: 14 additions & 12 deletions packages/docusaurus-plugin-content-docs/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import type {LoadedVersion, LoadedContent} from './types';
import type {Sidebar, Sidebars} from './sidebars/types';

import {chain, mapValues, keyBy} from 'lodash';
import {mapValues, keyBy} from 'lodash-es';
import {
collectSidebarCategories,
transformSidebarItems,
Expand Down Expand Up @@ -97,22 +96,25 @@ function getSidebarTranslationFileContent(
sidebarName: string,
): TranslationFileContent {
const categories = collectSidebarCategories(sidebar);
const categoryContent: TranslationFileContent = chain(categories)
.keyBy((category) => `sidebar.${sidebarName}.category.${category.label}`)
.mapValues((category) => ({
const categoryContent: TranslationFileContent = mapValues(
keyBy(
categories,
(category) => `sidebar.${sidebarName}.category.${category.label}`,
),
(category) => ({
message: category.label,
description: `The label for category ${category.label} in sidebar ${sidebarName}`,
}))
.value();
}),
);

const links = collectSidebarLinks(sidebar);
const linksContent: TranslationFileContent = chain(links)
.keyBy((link) => `sidebar.${sidebarName}.link.${link.label}`)
.mapValues((link) => ({
const linksContent: TranslationFileContent = mapValues(
keyBy(links, (link) => `sidebar.${sidebarName}.link.${link.label}`),
(link) => ({
message: link.label,
description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
}))
.value();
}),
);

return mergeTranslations([categoryContent, linksContent]);
}
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 @@ -24,7 +24,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-es';
import {resolveSidebarPathOption} from './sidebars';

// retro-compatibility: no prefix for the default plugin id
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@docusaurus/utils": "2.0.0-beta.9",
"@docusaurus/utils-validation": "2.0.0-beta.9",
"globby": "^11.0.2",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"remark-admonitions": "^1.2.1",
"tslib": "^2.3.1",
"webpack": "^5.61.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"babel:lib": "cross-env BABEL_ENV=lib babel src -d lib --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
"prettier": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"**/*.{js,ts,jsx,tsc}\"",
"prettier:lib": "prettier --config ../../.prettierrc --write \"lib/**/*.{js,ts,jsx,tsx}\"",
"update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
"update-code-translations": "node -e 'require(\"./update-code-translations.cjs\").run()' --es-module-specifier-resolution=node"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.9",
Expand All @@ -40,7 +40,7 @@
"fs-extra": "^10.0.0",
"globby": "^11.0.2",
"infima": "0.2.0-alpha.34",
"lodash": "^4.17.20",
"lodash-es": "^4.17.20",
"parse-numeric-range": "^1.3.0",
"postcss": "^8.3.7",
"prism-react-renderer": "^1.2.1",
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 {merge} from 'lodash';
import {merge} from 'lodash-es';

const {ThemeConfigSchema, DEFAULT_CONFIG} = require('../validateThemeConfig');

Expand Down
50 changes: 26 additions & 24 deletions packages/docusaurus-theme-classic/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
NavbarItem,
Footer,
} from '@docusaurus/theme-common';

import {keyBy, chain} from 'lodash';
import {keyBy, mapValues} from 'lodash-es';
import {mergeTranslations} from '@docusaurus/utils';

function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {
Expand All @@ -28,15 +27,16 @@ function getNavbarTranslationFile(navbar: Navbar): TranslationFileContent {

const allNavbarItems = flattenNavbarItems(navbar.items);

const navbarItemsTranslations: TranslationFileContent = chain(
allNavbarItems.filter((navbarItem) => !!navbarItem.label),
)
.keyBy((navbarItem) => `item.label.${navbarItem.label}`)
.mapValues((navbarItem) => ({
const navbarItemsTranslations: TranslationFileContent = mapValues(
keyBy(
allNavbarItems.filter((navbarItem) => !!navbarItem.label),
(navbarItem) => `item.label.${navbarItem.label}`,
),
(navbarItem) => ({
message: navbarItem.label!,
description: `Navbar item with label ${navbarItem.label}`,
}))
.value();
}),
);

const titleTranslations: TranslationFileContent = navbar.title
? {title: {message: navbar.title, description: 'The title in the navbar'}}
Expand Down Expand Up @@ -71,27 +71,29 @@ function translateNavbar(

function getFooterTranslationFile(footer: Footer): TranslationFileContent {
// TODO POC code
const footerLinkTitles: TranslationFileContent = chain(
footer.links.filter((link) => !!link.title),
)
.keyBy((link) => `link.title.${link.title}`)
.mapValues((link) => ({
const footerLinkTitles: TranslationFileContent = mapValues(
keyBy(
footer.links.filter((link) => !!link.title),
(link) => `link.title.${link.title}`,
),
(link) => ({
message: link.title!,
description: `The title of the footer links column with title=${link.title} in the footer`,
}))
.value();

const footerLinkLabels: TranslationFileContent = chain(
footer.links.flatMap((link) => link.items).filter((link) => !!link.label),
)
.keyBy((linkItem) => `link.item.label.${linkItem.label}`)
.mapValues((linkItem) => ({
}),
);

const footerLinkLabels: TranslationFileContent = mapValues(
keyBy(
footer.links.flatMap((link) => link.items).filter((link) => !!link.label),
(linkItem) => `link.item.label.${linkItem.label}`,
),
(linkItem) => ({
message: linkItem.label!,
description: `The label of footer link with label=${
linkItem.label
} linking to ${linkItem.to ?? linkItem.href}`,
}))
.value();
}),
);

const copyright: TranslationFileContent = footer.copyright
? {
Expand Down

0 comments on commit e022e38

Please sign in to comment.