Skip to content

Commit 01f3676

Browse files
committed
chore(deps): externalize lodash-es via shared
Co-Authored-By: Aiden
1 parent 70ac277 commit 01f3676

File tree

10 files changed

+32
-26
lines changed

10 files changed

+32
-26
lines changed

.changeset/tall-walls-matter.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rspress/core': patch
3+
'@rspress/shared': patch
4+
---
5+
6+
Move `lodash-es` behind `@rspress/shared/lodash-es` so it no longer ships as a runtime dependency of `@rspress/core`.

packages/core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"github-slugger": "^2.0.0",
8181
"hast-util-heading-rank": "^3.0.0",
8282
"hast-util-to-jsx-runtime": "^2.3.6",
83-
"lodash-es": "^4.17.23",
8483
"mdast-util-mdx": "^3.0.0",
8584
"mdast-util-mdxjs-esm": "^2.0.1",
8685
"medium-zoom": "1.1.0",
@@ -117,7 +116,6 @@
117116
"@rspress/config": "workspace:*",
118117
"@types/body-scroll-lock": "^3.1.2",
119118
"@types/hast": "^3.0.4",
120-
"@types/lodash-es": "^4.17.12",
121119
"@types/mdast": "^4.0.4",
122120
"@types/node": "^22.8.1",
123121
"@types/nprogress": "^0.2.3",

packages/core/src/node/runtimeModule/pageData/createPageData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type PageData, SEARCH_INDEX_NAME } from '@rspress/shared';
2-
import { groupBy } from 'lodash-es';
2+
import { groupBy } from '@rspress/shared/lodash-es';
33
import { extractPageData } from '../../route/extractPageData';
44
import { createHash } from '../../utils';
55
import type { FactoryContext } from '../types';
@@ -61,7 +61,7 @@ export async function createPageData(context: FactoryContext): Promise<{
6161
typeof userConfig.search !== 'boolean' &&
6262
(userConfig.search?.versioned ?? true);
6363

64-
const groupedPages = groupBy(pages, page => {
64+
const groupedPages = groupBy(pages, (page: (typeof pages)[number]) => {
6565
if (page.frontmatter?.pageType === 'home') {
6666
return 'noindex';
6767
}

packages/core/src/node/ssg/renderPages.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { RouteMeta, UserConfig } from '@rspress/shared';
2+
import { chunk } from '@rspress/shared/lodash-es';
23
import { logger } from '@rspress/shared/logger';
3-
import { chunk } from 'lodash-es';
44
import pMap from 'p-map';
55
import picocolors from 'picocolors';
66

@@ -120,15 +120,17 @@ export async function renderPages(
120120
});
121121

122122
await Promise.all(
123-
chunk(routes, SSGWorkerThreadTaskSize()).map(async routes => {
124-
const htmlList = await pool.run({ routes });
125-
for (let i = 0; i < routes.length; i++) {
126-
const route = routes[i];
127-
const html = htmlList[i];
128-
const fileName = routePath2HtmlFileName(route.routePath);
129-
emitAsset(fileName, html);
130-
}
131-
}),
123+
chunk(routes, SSGWorkerThreadTaskSize()).map(
124+
async (routes: RouteMeta[]) => {
125+
const htmlList = await pool.run({ routes });
126+
for (let i = 0; i < routes.length; i++) {
127+
const route = routes[i];
128+
const html = htmlList[i];
129+
const fileName = routePath2HtmlFileName(route.routePath);
130+
emitAsset(fileName, html);
131+
}
132+
},
133+
),
132134
);
133135

134136
await pool.destroy();

packages/core/src/theme/components/Search/SearchPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Tabs,
99
useLinkNavigate,
1010
} from '@rspress/core/theme';
11-
import { debounce } from 'lodash-es';
11+
import { debounce } from '@rspress/shared/lodash-es';
1212
import { useCallback, useEffect, useRef, useState } from 'react';
1313
import { createPortal } from 'react-dom';
1414
import * as userSearchHooks from 'virtual-search-hooks';

packages/shared/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"./node-utils": {
2525
"types": "./dist/node-utils.d.ts",
2626
"default": "./dist/node-utils.js"
27+
},
28+
"./lodash-es": {
29+
"types": "./dist/lodash-es.d.ts",
30+
"default": "./dist/lodash-es.js"
2731
}
2832
},
2933
"module": "./dist/index.js",
@@ -41,14 +45,14 @@
4145
"@rsbuild/core": "2.0.0-beta.11",
4246
"@shikijs/rehype": "^4.0.2",
4347
"gray-matter": "4.0.3",
44-
"lodash-es": "^4.17.23",
4548
"unified": "^11.0.5"
4649
},
4750
"devDependencies": {
4851
"@rslib/core": "0.20.2",
4952
"@types/lodash-es": "^4.17.12",
5053
"@types/node": "^22.8.1",
5154
"@types/react": "^19.2.14",
55+
"lodash-es": "^4.17.23",
5256
"mdast-util-mdx-jsx": "^3.2.0",
5357
"medium-zoom": "1.1.0",
5458
"rimraf": "^6.1.3",

packages/shared/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineConfig({
2020
logger: 'src/logger.ts',
2121
'node-utils': 'src/node-utils.ts',
2222
constants: 'src/constants.ts',
23+
'lodash-es': 'src/lodash-es.ts',
2324
},
2425
},
2526
plugins: [pluginPublint()],

packages/shared/src/lodash-es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { chunk, debounce, groupBy, mergeWith } from 'lodash-es';

packages/shared/src/node-utils/merge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { mergeWith } from '../lodash-es';
12
import type { UserConfig } from '../types/index';
23

34
const castArray = <T>(value: T | T[]): T[] =>
@@ -6,7 +7,6 @@ const castArray = <T>(value: T | T[]): T[] =>
67
export const mergeDocConfig = async (
78
...configs: UserConfig[]
89
): Promise<UserConfig> => {
9-
const { mergeWith } = await import('lodash-es');
1010
return mergeWith({}, ...configs, (target: UserConfig, source: UserConfig) => {
1111
const pair = [target, source];
1212
if (pair.some(item => item === undefined)) {

pnpm-lock.yaml

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)