-
Notifications
You must be signed in to change notification settings - Fork 6
feat: support whitelist and blacklist #21
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
Conversation
📝 Walkthrough""" Walkthrough此次更改升级了 React 及 React DOM 的类型依赖,移除了一些无关的依赖包。核心代码中, Changes
Sequence Diagram(s)sequenceDiagram
participant 调用者
participant extractStyle
participant defaultNode
participant StyleProvider
调用者->>extractStyle: 传入 { customTheme, includes, excludes }
extractStyle->>defaultNode: 传递 includes/excludes
defaultNode->>StyleProvider: 渲染指定组件
StyleProvider-->>extractStyle: 返回样式缓存
extractStyle-->>调用者: 返回提取的样式字符串
Poem
""" 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/index.tsx (1)
89-89: 建议添加类型注解建议为
nodeProps添加明确的类型注解以提高代码可读性。- const nodeProps: NodeProps = { + const nodeProps: NodeProps = {或者可以直接内联传递:
- const nodeProps: NodeProps = { - includes, - excludes, - } - - renderToString( - <StyleProvider cache={cache}> - {customTheme ? customTheme(defaultNode(nodeProps)) : defaultNode(nodeProps)} - </StyleProvider>, - ); + renderToString( + <StyleProvider cache={cache}> + {customTheme ? customTheme(defaultNode({ includes, excludes })) : defaultNode({ includes, excludes })} + </StyleProvider>, + );tests/index.test.tsx (1)
59-73: 建议增加边界情况测试建议添加更多测试用例来覆盖边界情况:
- 同时使用
includes和excludes的情况- 空数组的情况
- 不存在的组件名称
+ it('should handle both includes and excludes', () => { + const cssText = extractStyle({ + includes: ['Button', 'Card'], + excludes: ['Card'] + }); + expect(cssText).toContain('.ant-btn'); + expect(cssText).not.toContain('.ant-card'); + }); + + it('should handle empty arrays', () => { + const cssText = extractStyle({ + includes: [], + excludes: [] + }); + expect(cssText).toContain('.ant-btn'); + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
package.json(2 hunks)src/index.tsx(2 hunks)tests/index.test.tsx(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/index.tsx (1)
src/interface.ts (1)
CustomRender(1-1)
🔇 Additional comments (7)
package.json (2)
43-44: React 类型定义升级看起来不错React 和 React DOM 的类型定义从 16.x 升级到 18.x 是合理的维护更新。
60-60: 依赖清理符合代码重构移除了多个 UI 组件工具包,只保留
@babel/runtime,这与src/index.tsx中的代码简化是一致的。src/index.tsx (3)
38-41: 接口设计简洁明了
NodeProps接口设计合理,使用可选参数支持excludes和includes数组。
43-68: 过滤逻辑实现正确
defaultNode函数的更新很好地支持了组件过滤功能:
- 优先使用
includes白名单,否则使用所有 antd 组件- 正确排除了
defaultBlackList和excludes中的组件- 保持了只包含首字母大写组件的逻辑
70-99: 函数重载设计保持向后兼容
extractStyle函数的参数设计很好地平衡了新功能和向后兼容性:
- 支持传入函数(原有方式)或配置对象(新方式)
- 参数解构处理清晰
- 正确传递参数给
defaultNodetests/index.test.tsx (2)
59-65: 白名单测试覆盖充分测试正确验证了
includes参数的功能:
- 包含指定组件的样式(
.ant-btn)- 排除未指定组件的样式(
.ant-select)
67-73: 黑名单测试逻辑正确测试正确验证了
excludes参数的功能:
- 保留未排除组件的样式(
.ant-btn)- 排除指定组件的样式(
.ant-card)
Summary by CodeRabbit
新功能
测试
其他