chore: forbid rc deep imports#54
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 总体描述该PR强制规范包导入方式、升级核心依赖至新的兼容版本、迁移源代码导入路径从内部目录改为包根路径,并提升React最低版本要求至18.0.0。 改动导入路径规范化与依赖升级
估计的代码审查工作量🎯 2 (简单) | ⏱️ ~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 |
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new ESLint rule to restrict imports from package internals and refactors existing imports in the source files to use package roots. Additionally, it updates several dependencies, most notably increasing the minimum required version for React and React-DOM in peerDependencies to 18.0.0. Feedback was provided highlighting that this change to peerDependencies is a breaking change and should be verified to ensure it aligns with the project's versioning and release strategy.
| "react": ">=18.0.0", | ||
| "react-dom": ">=18.0.0" |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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`:
- Line 38: Update package.json to use the actual published version of
`@rc-component/util` (change the dependency from "^1.11.0" to "^1.10.0"), and
update all imports that assume root exports: replace root imports of supportRef,
isEqual, useEvent and useLayoutEffect with the package's nested paths (e.g.
import useEvent from "@rc-component/util/lib/hooks/useEvent", import
useLayoutEffect from "@rc-component/util/lib/hooks/useLayoutEffect", and import
isEqual/supportRef from their correct lib locations) so the code references the
real exported modules and the dependency version matches the published release.
- Around line 48-49: The project ESLint config fails because
eslint-config-prettier is missing; add "eslint-config-prettier" to package.json
devDependencies (paired with the existing "@umijs/fabric" dependency) and choose
a version compatible with `@umijs/fabric` (check `@umijs/fabric` ^4.0.0
requirements), then reinstall dev deps; update the devDependencies entry for
eslint-config-prettier in package.json and run your package manager to install
so .eslintrc.js can extend `@umijs/fabric` without the "prettier" config error.
🪄 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: a8fdbea7-54ba-4763-9700-3f10af08a33c
📒 Files selected for processing (4)
.eslintrc.jspackage.jsonsrc/Immutable.tsxsrc/context.tsx
| }, | ||
| "dependencies": { | ||
| "@rc-component/util": "^1.3.0" | ||
| "@rc-component/util": "^1.11.0" |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does @rc-component/util version 1.11.0 export supportRef, isEqual, useEvent, and useLayoutEffect from the package root?
💡 Result:
No, @rc-component/util does not export supportRef, isEqual, useEvent, or useLayoutEffect directly from the package root [1][2]. These utilities are located within subdirectories of the package and must be imported via specific paths [1][2][3]. Based on the package structure, they are typically found under the lib/hooks/ or lib/Dom/ directories [1][2]. For example: - useEvent and useLayoutEffect are located in lib/hooks/ [1][2]. - Other utilities like supportRef or isEqual are similarly nested within the package's internal structure rather than being exposed at the top level [1][2]. To use these utilities, you should use path-based imports, such as: import { useEvent } from '@rc-component/util/lib/hooks/useEvent'; import { useLayoutEffect } from '@rc-component/util/lib/hooks/useLayoutEffect'; Note that as of May 15, 2026, the latest stable version of @rc-component/util is 1.10.0 [4][5]. Version 1.11.0 has not been released [1][4].
Citations:
- 1: https://registry.npmjs.org/%40rc-component%2Futil
- 2: https://registry.npmjs.org/@rc-component/util
- 3: https://github.com/react-component/virtual-list/blob/master/src/List.tsx
- 4: https://github.com/react-component/util/releases/tag/%40rc-component%2Futil%401.10.0
- 5: https://github.com/react-component/util/tree/master
@rc-component/util 版本 1.11.0 不存在,且导出结构不支持从根路径导入。
@rc-component/util 的最新稳定版本为 1.10.0(截至 2026 年 5 月),版本 1.11.0 尚未发布。此外,supportRef、isEqual、useEvent 和 useLayoutEffect 不是从包根路径导出的,而是位于嵌套目录中,需要通过特定的路径导入,例如:@rc-component/util/lib/hooks/useEvent 和 @rc-component/util/lib/hooks/useLayoutEffect。请更正依赖版本并根据实际包结构调整导入路径。
🤖 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` at line 38, Update package.json to use the actual published
version of `@rc-component/util` (change the dependency from "^1.11.0" to
"^1.10.0"), and update all imports that assume root exports: replace root
imports of supportRef, isEqual, useEvent and useLayoutEffect with the package's
nested paths (e.g. import useEvent from "@rc-component/util/lib/hooks/useEvent",
import useLayoutEffect from "@rc-component/util/lib/hooks/useLayoutEffect", and
import isEqual/supportRef from their correct lib locations) so the code
references the real exported modules and the dependency version matches the
published release.
| "@typescript-eslint/eslint-plugin": "^5.62.0", | ||
| "@typescript-eslint/parser": "^5.62.0", |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 验证 ESLint 配置是否能正常加载和解析
# 测试 ESLint 能否成功解析配置文件
npx eslint --print-config .eslintrc.js > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "✓ ESLint 配置加载成功"
else
echo "✗ ESLint 配置加载失败"
npx eslint --print-config .eslintrc.js
fiRepository: react-component/context
Length of output: 456
🏁 Script executed:
cat -n package.json | sed -n '40,60p'Repository: react-component/context
Length of output: 859
🏁 Script executed:
cat -n .eslintrc.jsRepository: react-component/context
Length of output: 1023
🏁 Script executed:
rg "prettier|eslint-config" package.jsonRepository: react-component/context
Length of output: 49
🏁 Script executed:
rg "eslint-config-prettier|prettier" . -t js -t json --max-count=5Repository: react-component/context
Length of output: 49
🏁 Script executed:
# 检查 `@umijs/fabric` 的实际依赖
npm info `@umijs/fabric`@4.0.0 peerDependencies 2>/dev/null || echo "检查package-lock或yarn.lock"Repository: react-component/context
Length of output: 92
🏁 Script executed:
# 检查是否存在 package-lock.json 或 yarn.lock
ls -la package-lock.json yarn.lock 2>/dev/null || echo "No lock files found"Repository: react-component/context
Length of output: 87
ESLint 配置加载失败,原因为缺少 eslint-config-prettier 依赖。
ESLint 配置无法加载,错误信息指出缺少 "prettier" 配置。.eslintrc.js 扩展自 @umijs/fabric/dist/eslint,而 @umijs/fabric 依赖 eslint-config-prettier。需要将 eslint-config-prettier 添加到 devDependencies,而非仅依赖版本调整来解决。建议与 @umijs/fabric ^4.0.0 的兼容性要求一并检查。
🤖 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 48 - 49, The project ESLint config fails because
eslint-config-prettier is missing; add "eslint-config-prettier" to package.json
devDependencies (paired with the existing "@umijs/fabric" dependency) and choose
a version compatible with `@umijs/fabric` (check `@umijs/fabric` ^4.0.0
requirements), then reinstall dev deps; update the devDependencies entry for
eslint-config-prettier in package.json and run your package manager to install
so .eslintrc.js can extend `@umijs/fabric` without the "prettier" config error.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #54 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 90 90
Branches 24 24
=========================================
Hits 90 90 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
背景
为避免 rc 包之间依赖其他包的
es/lib构建产物内部路径,本次将@rc-component/context中的 rc 深路径导入统一迁移到包根入口,并补充 lint 规则阻止后续重新引入。改动内容
no-restricted-imports规则,限制@rc-component/*与rc-*包的es/lib深路径导入。@rc-component/util/lib/*导入替换为@rc-component/util根入口导入。@rc-component/util升级到^1.11.0,使用包含所需根入口导出的版本。>=18.0.0,与当前@rc-component/util的 peer 要求保持一致。@typescript-eslintv5 依赖,并将eslint-plugin-jest调整到兼容版本,避免@umijs/fabric规则加载失败。验证
npm run lint:通过,保留既有 2 条react-hooks/exhaustive-depswarning。npm run compile:通过,保留同样 2 条 warning。npm test:通过,2 个 test suites / 10 个 tests。Summary by CodeRabbit