diff --git a/examples/normal/.dumirc.ts b/examples/normal/.dumirc.ts index b5a7c1c952..dbf84ad3f9 100644 --- a/examples/normal/.dumirc.ts +++ b/examples/normal/.dumirc.ts @@ -1,3 +1,8 @@ +const names = [ + 'skipProps1', + 'skipProps2' +]; + export default { locales: [ { id: 'zh-CN', name: '中文' }, @@ -5,6 +10,10 @@ export default { ], themeConfig: { name: '示例' }, mfsu: false, - apiParser: {}, + apiParser: { + propFilter: { + skipPropsWithName: names + } + }, resolve: { entryFile: './src/index.ts' }, }; diff --git a/examples/normal/src/Foo/index.tsx b/examples/normal/src/Foo/index.tsx index a98bad9848..3df8e58f7f 100644 --- a/examples/normal/src/Foo/index.tsx +++ b/examples/normal/src/Foo/index.tsx @@ -4,6 +4,11 @@ interface A { a: string; } +interface SkipProps { + skipProps1: string; + skipProps2: number; +} + const Foo: FC<{ /** * @description 标题 @@ -24,7 +29,7 @@ const Foo: FC<{ children: React.ReactNode; onConfirm: (output: { children: any[] }) => void; dom: HTMLElement; -}> = (props) => { +} & SkipProps> = (props) => { return <>{props.title}; }; diff --git a/src/assetParsers/atom.ts b/src/assetParsers/atom.ts index 169ab4bed0..be452158ef 100644 --- a/src/assetParsers/atom.ts +++ b/src/assetParsers/atom.ts @@ -32,6 +32,7 @@ class AtomAssetsParser { paths: string | string[]; options: chokidar.WatchOptions; }; + private skipPropsWithName: string[] = []; constructor(opts: { entryFile: string; @@ -40,11 +41,15 @@ class AtomAssetsParser { unpkgHost?: string; watch?: boolean; parseOptions?: object; + propFilter?: { + skipPropsWithName?: string[]; + }; }) { const absEntryFile = path.resolve(opts.resolveDir, opts.entryFile); this.resolveDir = opts.resolveDir; this.resolveFilter = opts.resolveFilter || (() => true); + this.skipPropsWithName = opts.propFilter?.skipPropsWithName || []; this.entryDir = path.relative(opts.resolveDir, path.dirname(absEntryFile)); this.parser = new SchemaParser({ entryPath: absEntryFile, @@ -107,6 +112,17 @@ class AtomAssetsParser { let propsConfig = needResolve ? (await resolver.getComponent(id)).props : fallbackProps; + + if (this.skipPropsWithName.length > 0) { + const filteredProperties = Object.keys(propsConfig.properties) + .filter((key) => !this.skipPropsWithName.includes(key)) + .reduce((obj, key) => { + obj[key] = propsConfig.properties[key]; + return obj; + }, {} as Record); + propsConfig.properties = filteredProperties; + } + const size = Buffer.byteLength(JSON.stringify(propsConfig)); if (size > MAX_PARSE_SIZE) { diff --git a/src/features/parser.ts b/src/features/parser.ts index c571cb0bce..28970bb0d8 100644 --- a/src/features/parser.ts +++ b/src/features/parser.ts @@ -26,6 +26,7 @@ export default (api: IApi) => { unpkgHost: Joi.string().uri().optional(), resolveFilter: Joi.function().optional(), parseOptions: Joi.object().optional(), + propFilter: Joi.object().optional(), }), }, }); @@ -56,6 +57,7 @@ export default (api: IApi) => { unpkgHost: api.config.apiParser!.unpkgHost, resolveFilter: api.config.apiParser!.resolveFilter, parseOptions: api.config.apiParser!.parseOptions, + propFilter: api.config.apiParser!.propFilter, }); });