Skip to content

Commit ccd5299

Browse files
authored
chore: not use recursive omit (#173)
1 parent 6970c8f commit ccd5299

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

packages/core/src/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
color,
3232
isObject,
3333
nodeBuiltInModules,
34-
omitDeep,
34+
omit,
3535
readPackageJson,
3636
} from './utils/helper';
3737
import { logger } from './utils/logger';
@@ -825,12 +825,13 @@ export async function composeCreateRsbuildConfig(
825825
config: mergeRsbuildConfig(
826826
constantRsbuildConfig,
827827
libRsbuildConfig,
828-
omitDeep(userConfig, [
828+
omit(userConfig, [
829829
'bundle',
830830
'format',
831831
'autoExtension',
832832
'autoExternal',
833833
'syntax',
834+
'externalHelpers',
834835
'dts',
835836
]),
836837
),

packages/core/src/utils/helper.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,19 @@ export const readPackageJson = (rootPath: string): undefined | PkgJson => {
126126
export const isObject = (obj: unknown): obj is Record<string, any> =>
127127
Object.prototype.toString.call(obj) === '[object Object]';
128128

129-
type OmitDeep<T, K extends string[]> = T extends (infer U)[]
130-
? OmitDeep<U, K>[]
131-
: T extends Record<any, any>
132-
? { [P in keyof T as P extends K[number] ? never : P]: OmitDeep<T[P], K> }
133-
: T;
134-
135-
export function omitDeep<T extends object, K extends string[]>(
129+
export function omit<T extends object, U extends keyof T>(
136130
obj: T,
137-
keys: K,
138-
): OmitDeep<T, K> {
139-
if (typeof obj === 'string' || typeof obj !== 'object' || obj === null)
140-
return obj as any;
141-
142-
if (Array.isArray(obj)) {
143-
return obj.map((item) => omitDeep(item, keys)) as any;
144-
}
145-
146-
const clone: any = {};
147-
for (const property in obj) {
148-
if (keys.includes(property as string)) {
149-
continue;
150-
}
151-
const value = obj[property];
152-
if (value && typeof value === 'object') {
153-
clone[property] = omitDeep(value, keys);
154-
} else {
155-
clone[property] = value;
156-
}
157-
}
158-
return clone;
131+
keys: ReadonlyArray<U>,
132+
): Omit<T, U> {
133+
return Object.keys(obj).reduce(
134+
(ret, key) => {
135+
if (!keys.includes(key as U)) {
136+
ret[key as keyof Omit<T, U>] = obj[key as keyof Omit<T, U>];
137+
}
138+
return ret;
139+
},
140+
{} as Omit<T, U>,
141+
);
159142
}
160143

161144
export { color };

0 commit comments

Comments
 (0)