Avoid util deep imports#689
Conversation
|
@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
概述PR 升级了 变更
估计代码审查工作量🎯 2 (Simple) | ⏱️ ~12 分钟 可能相关的 PR
建议的审查者
诗
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
|
Refs ant-design/ant-design#58115 antd 侧统一跟踪 rc 包 es/lib 深路径引用问题。 |
There was a problem hiding this comment.
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
| "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" | ||
| } | ||
| }, |
There was a problem hiding this comment.
🧩 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:
- 1: https://github.com/nodejs/node/blob/HEAD/doc/api/packages.md
- 2: https://nodejs.org/docs/latest-v22.x/api/packages.html
- 3: https://nodejs.org/api/packages.html
- 4: Special treatment for package.json resolution and exports? nodejs/node#33460
- 5: https://deadends.dev/node/err-package-json-invalid/
兼容性:exports 收紧可能导致未声明的 ./es/* / ./lib/* 深路径失效(ERR_PACKAGE_PATH_NOT_EXPORTED)
在 package.json 的 exports(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.
变更内容
@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 --checknpm testSummary by CodeRabbit
发布说明