Skip to content

feat(export)!: restrict to only root path import #661

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guoyunhe
Copy link
Contributor

@guoyunhe guoyunhe commented Jul 30, 2025

禁止使用 import xxx from '@rc-component/util/lib/xxx',这样有几个好处:

  1. 避免造成 cjs/esm 混用等问题,影响性能和打包体积
  2. 避免因包内文件名路径变化导致依赖项目构建失败
  3. 避免一些内部方法被暴露出来

这是一个破坏性变更!

Summary by CodeRabbit

  • 新功能

    • 显著扩展和重组了公共 API,新增了大量实用工具函数、React 相关工具、DOM 操作方法及多种自定义 Hook。
    • 优化了包的模块导出结构,增强了对不同模块系统(CommonJS、ESM)的兼容性。
  • 测试

    • 更新了测试用例的导入路径,保持测试代码一致性。

Copy link

vercel bot commented Jul 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
util ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2025 6:09am

Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

本次更改主要包括对 package.json 增加 exports 字段以明确不同模块系统的入口,以及对 src/index.ts 的导出内容进行了大幅扩充和结构化整理,显著增加了对各种工具函数、类型、React 相关工具和 DOM 工具的导出。同时,修正了部分测试文件的导入路径。

Changes

Cohort / File(s) Change Summary
包模块导出配置
package.json
新增 exports 字段,分别为 types、require、import 指定不同的入口文件,支持多模块系统和类型声明。
主入口导出扩展与重组
src/index.ts
大幅扩充并结构化导出内容,新增大量工具函数、类型、React/DOM 工具及 hooks 的导出,重组并分组相关导出项。
测试导入路径修正
tests/isEqual.test.ts
调整 isEqual 和 warning 的导入路径,改为指向 src 目录下的对应文件,无其他测试逻辑变更。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

  • refactor: rm legacy code #617:该 PR 对 src/React/render.tsrenderunmount 方法进行了重构和导出,与本次在 src/index.ts 中新增导出这两个方法直接相关。

Poem

兔子点点头,代码焕新颜,
模块入口明,工具齐上阵。
导出更丰富,结构更分明,
路径小修正,测试也安心。
代码跃进步,欢快蹦蹦跳! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62e1415 and f27b1e4.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
  • tests/isEqual.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (2)
package.json (1)

24-30: 正确实现了导入路径限制

exports 字段的实现完美符合PR目标:

  1. 只暴露根路径 "." 作为入口点,有效阻止了子路径导入
  2. 正确配置了不同模块系统的条件导出:
    • types: TypeScript 声明文件
    • require: CommonJS 模块
    • import: ES 模块
  3. 这将防止用户使用 import xxx from '@rc-component/util/lib/xxx' 等子路径导入
src/index.ts (1)

1-64: 验证通过:所有导出模块存在且路径正确

src/index.ts 中列出的所有导出模块(核心工具、React 相关、DOM 工具、Hooks、测试工具)均已在对应路径下找到,文件名与导出路径一致,无需进一步修改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant