Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shared): mergeDocConfig should dynamic import lodash-es #1656

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/shared/src/node-utils/merge.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { mergeWith } from 'lodash-es';
import type { UserConfig } from '@/types';

const castArray = <T>(value: T | T[]): T[] =>
Array.isArray(value) ? value : [value];

export const mergeDocConfig = (...configs: UserConfig[]): UserConfig =>
mergeWith({}, ...configs, (target: UserConfig, source: UserConfig) => {
export const mergeDocConfig = async (
...configs: UserConfig[]
): Promise<UserConfig> => {
const { mergeWith } = await import('lodash-es');
return mergeWith({}, ...configs, (target: UserConfig, source: UserConfig) => {
const pair = [target, source];
if (pair.some(item => item === undefined)) {
// fallback to lodash default merge behavior
Expand All @@ -17,3 +19,4 @@ export const mergeDocConfig = (...configs: UserConfig[]): UserConfig =>
// fallback to lodash default merge behavior
return undefined;
});
};
Loading