Skip to content

Avoid util deep imports#689

Merged
zombieJ merged 2 commits into
react-component:masterfrom
QDyanbing:avoid-deep-imports
May 27, 2026
Merged

Avoid util deep imports#689
zombieJ merged 2 commits into
react-component:masterfrom
QDyanbing:avoid-deep-imports

Conversation

@QDyanbing
Copy link
Copy Markdown
Contributor

@QDyanbing QDyanbing commented May 19, 2026

变更内容

  • 升级 @rc-component/util 到当前 latest ^1.11.1
  • 升级 @rc-component/father-plugin^2.2.0,交由插件统一处理 rc 深路径 import 限制。
  • 将源码和测试中对 @rc-component/util/lib/* 的引用改为从 @rc-component/util 根入口导入。
  • 补充 src/locale/index.ts,并从根入口导出 locale,方便下游不再依赖 lib/locale/*

背景

配合 rc 包统一避免依赖其他 rc 包的 es / lib 构建产物内部路径,改为使用公开根入口 API。

验证

  • git diff --check
  • npm test

Summary by CodeRabbit

发布说明

  • Chores
    • 升级核心依赖版本,增强功能兼容性与稳定性
    • 优化模块导出配置,改进包结构可访问性

Review Change Stack

@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

概述

PR 升级了 @rc-component/util 依赖版本,并在 package.json 中新增了 types 字段和 exports 导出映射配置,同时统一调整所有源代码和测试文件中对该工具库的导入方式,从内部 lib/ 路径改为直接从包顶层导入。

变更

@rc-component/util 依赖升级与导入统一

图层 / 文件 摘要
依赖版本升级
package.json
@rc-component/util 升级到 ^1.11.1,@rc-component/father-plugin 升级到 ^2.2.0。
包导出配置
package.json
新增 types 根级字段,并配置 exports 映射以定义主入口和 assets/locale 子路径的 types/import/require 导出路径。
组件导入路径调整
src/Options.tsxsrc/Pagination.tsx
将导入方式从 @rc-component/util/lib/* 路径改为直接从 @rc-component/util 导入 KeyCode、pickAttrs、useControlledState 和 warning 等工具。
测试导入更新
tests/index.test.tsx
调整 resetWarned 的导入源,使其与新的 @rc-component/util 导出位置一致。

估计代码审查工作量

🎯 2 (Simple) | ⏱️ ~12 分钟

可能相关的 PR

  • react-component/pagination#635:主要更新 Options.tsx、Pagination.tsx 和测试中对 KeyCode/pickAttrs/warning(及 resetWarned)的导入,从 @rc-component/util/lib/* 改为从 @rc-component/util 直接导入,与本 PR 的导入路径统一工作直接重叠。

建议的审查者

  • zombieJ

🐰 兔子来敲门,带着新版本的轻盈脚步,
从 lib 的深处,回到包顶的明亮去,
导入整齐,导出清晰,配置好导航牌,
一统天下的工具库,终于找到了家。
✨ 升级升级,路径更清,代码心欢喜!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了主要变更内容,即避免从 @rc-component/util 进行深层导入,改为使用根入口导出。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the @rc-component/util dependency and refactors imports to use named exports from the main package instead of deep imports. It also introduces a centralized locale export file and exposes it through the main index. I have no feedback to provide.

@QDyanbing
Copy link
Copy Markdown
Contributor Author

Refs ant-design/ant-design#58115

antd 侧统一跟踪 rc 包 es/lib 深路径引用问题。

Comment thread src/locale/index.ts Outdated
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Around line 16-38: The package "exports" mapping currently only exposes ".",
"./assets/*", and locale paths which will block historical deep imports like
"./es/*" and "./lib/*" and cause ERR_PACKAGE_PATH_NOT_EXPORTED; to fix, restore
compatibility by adding general export entries for "./es/*" and "./lib/*" (or
equivalent patterns) to the "exports" field so those deep paths are explicitly
exported, or if you intend a breaking change, clearly document and version it as
a breaking release; target the "exports" object in package.json and add mappings
for "./es/*" and "./lib/*" (and their types/import/require variations) to match
your existing locale patterns.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2bb83d50-ed03-4837-88ff-c688293e7be1

📥 Commits

Reviewing files that changed from the base of the PR and between ae92314 and eb5b360.

📒 Files selected for processing (1)
  • package.json

Comment thread package.json
Comment on lines +16 to +38
"exports": {
".": {
"types": "./es/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js"
},
"./assets/*": "./assets/*",
"./locale/*": {
"types": "./es/locale/*.d.ts",
"import": "./es/locale/*.js",
"require": "./lib/locale/*.js"
},
"./lib/locale/*": {
"types": "./es/locale/*.d.ts",
"import": "./es/locale/*.js",
"require": "./lib/locale/*.js"
},
"./es/locale/*": {
"types": "./es/locale/*.d.ts",
"import": "./es/locale/*.js",
"require": "./lib/locale/*.js"
}
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In Node.js package resolution, once a package.json defines an "exports" field, do previously published but unlisted subpaths such as "./es/*" or "./lib/*" become inaccessible with ERR_PACKAGE_PATH_NOT_EXPORTED?

💡 Result:

Yes. Once a package.json defines an

Citations:


兼容性:exports 收紧可能导致未声明的 ./es/* / ./lib/* 深路径失效(ERR_PACKAGE_PATH_NOT_EXPORTED)
package.jsonexports(16-38)中只显式暴露了 ".""./assets/*"、以及各类 locale/*。一旦发布了 exports,任何“历史上可访问但未在该映射中列出”的子路径(例如 @rc-component/pagination/es/...@rc-component/pagination/lib/...)都会变成不可导出,从而引发 ERR_PACKAGE_PATH_NOT_EXPORTED——这相当于一次未声明的 breaking change(除非你就是要收敛 API)。

  • 为保持兼容:补上通用的 ./es/*./lib/* 导出(或等价规则)。
  • 若就是有意收敛/破坏兼容:需要按 breaking change 处理(发布策略/变更说明/版本升级)。
建议的兼容性修正
   "exports": {
     ".": {
       "types": "./es/index.d.ts",
       "import": "./es/index.js",
       "require": "./lib/index.js"
     },
     "./assets/*": "./assets/*",
+    "./es/*": {
+      "types": "./es/*.d.ts",
+      "import": "./es/*.js",
+      "require": "./lib/*.js"
+    },
+    "./lib/*": {
+      "types": "./es/*.d.ts",
+      "import": "./es/*.js",
+      "require": "./lib/*.js"
+    },
     "./locale/*": {
       "types": "./es/locale/*.d.ts",
       "import": "./es/locale/*.js",
       "require": "./lib/locale/*.js"
     },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 16 - 38, The package "exports" mapping currently
only exposes ".", "./assets/*", and locale paths which will block historical
deep imports like "./es/*" and "./lib/*" and cause
ERR_PACKAGE_PATH_NOT_EXPORTED; to fix, restore compatibility by adding general
export entries for "./es/*" and "./lib/*" (or equivalent patterns) to the
"exports" field so those deep paths are explicitly exported, or if you intend a
breaking change, clearly document and version it as a breaking release; target
the "exports" object in package.json and add mappings for "./es/*" and "./lib/*"
(and their types/import/require variations) to match your existing locale
patterns.

@zombieJ zombieJ merged commit e4a608f into react-component:master May 27, 2026
4 of 5 checks passed
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.

2 participants