Skip to content

chore: forbid rc deep imports#54

Merged
zombieJ merged 3 commits into
react-component:masterfrom
QDyanbing:chore/forbid-rc-deep-imports
May 18, 2026
Merged

chore: forbid rc deep imports#54
zombieJ merged 3 commits into
react-component:masterfrom
QDyanbing:chore/forbid-rc-deep-imports

Conversation

@QDyanbing
Copy link
Copy Markdown
Contributor

@QDyanbing QDyanbing commented May 15, 2026

背景

为避免 rc 包之间依赖其他包的 es / lib 构建产物内部路径,本次将 @rc-component/context 中的 rc 深路径导入统一迁移到包根入口,并补充 lint 规则阻止后续重新引入。

改动内容

  • 新增 ESLint no-restricted-imports 规则,限制 @rc-component/*rc-* 包的 es / lib 深路径导入。
  • @rc-component/util/lib/* 导入替换为 @rc-component/util 根入口导入。
  • @rc-component/util 升级到 ^1.11.0,使用包含所需根入口导出的版本。
  • 将 React peer 版本调整为 >=18.0.0,与当前 @rc-component/util 的 peer 要求保持一致。
  • 固定 lint 所需的 @typescript-eslint v5 依赖,并将 eslint-plugin-jest 调整到兼容版本,避免 @umijs/fabric 规则加载失败。

验证

  • npm run lint:通过,保留既有 2 条 react-hooks/exhaustive-deps warning。
  • npm run compile:通过,保留同样 2 条 warning。
  • npm test:通过,2 个 test suites / 10 个 tests。

Summary by CodeRabbit

  • Chores
    • 升级了核心依赖版本以提升兼容性
    • 更新了 TypeScript ESLint 工具链配置
    • 将 React 和 React DOM 最低版本要求提升至 18.0.0
    • 实现更严格的导入规则以规范模块架构
    • 优化了内部模块导入路径

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@QDyanbing has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 60 minutes before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a5d6224f-86f0-450d-9544-1138ddfde2d3

📥 Commits

Reviewing files that changed from the base of the PR and between 7bee061 and d110452.

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

总体描述

该PR强制规范包导入方式、升级核心依赖至新的兼容版本、迁移源代码导入路径从内部目录改为包根路径,并提升React最低版本要求至18.0.0。

改动

导入路径规范化与依赖升级

层 / 文件 摘要
ESLint导入限制规则定义
.eslintrc.js
添加restrictedPackageDirectoryImports列表定义glob模式,在ESLint配置中注册no-restricted-imports规则(错误级别),阻止从@rc-component/*rc-*包的es/lib/子目录导入。
核心依赖与兼容性版本更新
package.json
@rc-component/util^1.3.0升至^1.11.0,新增@typescript-eslint/eslint-plugin@typescript-eslint/parser(均^5.62.0),调整eslint-plugin-jest^27.9.0,React和React DOM同伴依赖最低版本从>=16.9.0提升至>=18.0.0
源代码导入路径迁移
src/Immutable.tsx, src/context.tsx
supportRefisEqualuseEventuseLayoutEffect的导入从@rc-component/util的内部深层路径(如lib/reflib/hooks/*)迁移为从包根路径直接具名导入。

估计的代码审查工作量

🎯 2 (简单) | ⏱️ ~12 分钟

可能相关的PR

  • react-component/context#50:在相同文件中执行了@rc-component/util的导入路径迁移,从深层lib/路径改为包根路径,与本PR的导入规范化目标一致。

兔兔诗

🐰 包的路径要规范,
ESLint来把关,
根路径导入更清爽,
React十八相伴,
依赖升级齐声唱!

🚥 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 标题'chore: forbid rc deep imports'清晰具体地总结了主要变更——防止从rc包的deep paths导入,与代码变更内容完全相关。
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.

@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 15, 2026

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.

View full report

@QDyanbing QDyanbing marked this pull request as ready for review May 15, 2026 06:56
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 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.

Comment thread package.json
Comment on lines +62 to +63
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

reactreact-dompeerDependencies 提升至 >=18.0.0 是一个破坏性变更(Breaking Change)。虽然这是为了与 @rc-component/util 的要求保持一致,但这会影响到仍在使用 React 16 或 17 的用户。建议确认这是否符合当前大版本的发布计划,或者是否应该通过发布新的大版本(Major Version)来引入此变更。

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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between b57ecd0 and 7bee061.

📒 Files selected for processing (4)
  • .eslintrc.js
  • package.json
  • src/Immutable.tsx
  • src/context.tsx

Comment thread package.json
},
"dependencies": {
"@rc-component/util": "^1.3.0"
"@rc-component/util": "^1.11.0"
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 | 🔴 Critical

🧩 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:


@rc-component/util 版本 1.11.0 不存在,且导出结构不支持从根路径导入。

@rc-component/util 的最新稳定版本为 1.10.0(截至 2026 年 5 月),版本 1.11.0 尚未发布。此外,supportRefisEqualuseEventuseLayoutEffect 不是从包根路径导出的,而是位于嵌套目录中,需要通过特定的路径导入,例如:@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.

Comment thread package.json
Comment on lines +48 to +49
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
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 | 🔴 Critical

🧩 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
fi

Repository: 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.js

Repository: react-component/context

Length of output: 1023


🏁 Script executed:

rg "prettier|eslint-config" package.json

Repository: react-component/context

Length of output: 49


🏁 Script executed:

rg "eslint-config-prettier|prettier" . -t js -t json --max-count=5

Repository: 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
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b57ecd0) to head (d110452).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit 1e0abb5 into react-component:master May 18, 2026
6 checks passed
@QDyanbing QDyanbing deleted the chore/forbid-rc-deep-imports branch May 19, 2026 02:09
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