chore: add nx
这个 PR 做了什么? (简要描述所做更改) 利用 nx 缓存加快本地构建及测试过程
这个 PR 是什么类型? (至少选择一个)
- [x] 构建优化 (Chore)
Summary by CodeRabbit
-
新功能
- 引入 Nx 工作区配置文件,支持更高效的构建与测试流程。
- 增加 Harmony 平台新组件声明,包括 list 和 list-item。
- 新增开发和 CI 指南文档,优化 Nx 与 pnpm 的协作说明。
- VSCode 配置支持 Nx MCP 服务器与 AI agent 规则自动生成。
- 新增 babel-plugin-transform-taroapi H5 平台 API 与组件的详细模拟定义。
-
功能优化
- 构建、测试与快照脚本切换为 Nx 并行任务,提升执行效率。
- .gitignore 增加 Nx 相关缓存目录的忽略规则。
-
依赖调整
- 移除 taro-components 包对 @tarojs/components-advanced 的依赖及相关 virtual-list 组件导出。
-
持续集成
- GitHub Actions 升级 pnpm setup 动作为 v4,集成 Nx 缓存与并发控制。
- 优化 Node.js 测试流程,合并构建与测试步骤,提升 CI 性能。
-
其他
- 移除部分 Jest 配置中的快照序列化器。
- 仅调整部分导出顺序,无功能变更。
- 调整 rollup-plugin-copy 包的构建输出目录及入口文件路径。
- 删除部分无额外逻辑的导出入口文件,简化包结构。
Walkthrough
本次变更主要围绕引入和配置 Nx 构建系统,包括新增 nx.json、调整 package.json 脚本、添加 nx 依赖、完善 .gitignore 及 VSCode 配置,并对 GitHub Actions 工作流进行优化,增加缓存机制和合并后自动上传缓存的流程。同时引入了用于修复 Nx 缓存的脚本,并对部分平台定义和依赖进行了细微调整。
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Nx 配置与脚本支持nx.json, package.json, .gitignore, .vscode/settings.json, scripts/fix-nx-cache.mjs |
新增 Nx 配置文件 nx.json,package.json 脚本切换为 nx run-many,增加 nx 依赖;.gitignore 增加 Nx 相关缓存目录;VSCode 增加 nxConsole 配置;新增 fix-nx-cache.mjs 脚本用于修复 Nx 缓存数据库。 |
GitHub Actions 工作流优化.github/workflows/nodejs.yml, .github/workflows/build-rust-binding.yml, .github/workflows/merged.yml |
nodejs.yml 增加并发控制、缓存处理、合并构建测试步骤,移除 lint;build-rust-binding.yml Node 版本号格式调整;新增 merged.yml,合并 PR 后上传 Nx 缓存。 |
平台定义文件调整packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json, packages/babel-plugin-transform-taroapi/__tests__/__mocks__/h5-definition.json |
Harmony hybrid 平台 cover-view 组件新增 marker-id 和 slot 属性;Taro H5 平台 scroll-view 组件 mock 定义新增 enhanced 和 showScrollbar 属性。 |
依赖调整packages/taro-runtime/package.json |
移除 rollup-plugin-ts 开发依赖。 |
Sequence Diagram(s)
sequenceDiagram
participant Developer
participant Nx CLI
participant fix-nx-cache.mjs
participant Nx Daemon
participant FileSystem
Developer->>Nx CLI: 运行 build/test/updateSnapshot 脚本
Nx CLI->>FileSystem: 读取 nx.json 配置
Nx CLI->>Nx Daemon: 启动/停止 Daemon
Nx CLI->>FileSystem: 读写 .nx 缓存
Developer->>fix-nx-cache.mjs: 执行缓存修复脚本
fix-nx-cache.mjs->>Nx Daemon: 停止 Daemon
fix-nx-cache.mjs->>FileSystem: 备份 .db 文件
fix-nx-cache.mjs->>Nx CLI: 执行 clean 生成新 db
fix-nx-cache.mjs->>Nx Daemon: 再次停止 Daemon
fix-nx-cache.mjs->>FileSystem: 删除新 .db,恢复旧 .db
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~15-25 minutes
Suggested reviewers
- yoyo837
- tutuxxx
Poem
🐇
Nx 新舞台,缓存巧安排,
工作流并发,缓存随风来。
脚本轻轻修,依赖悄悄裁,
配置更精细,构建效率快。
代码小兔笑,协作步步高!
[!NOTE]
🔌 MCP (Model Context Protocol) integration is now available in Early Access!
Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 03d26f05259c74d3c7633e3ad941ff8b3e7326f7 and 4e642e406098a8fdce2d86797314a9e3e2180b73.
📒 Files selected for processing (1)
.github/workflows/merged.yml(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- .github/workflows/merged.yml
✨ Finishing Touches
🧪 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.
🪧 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
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.
- PR comments: Tag
@coderabbitaiin 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.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai generate unit teststo generate unit tests for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
Codecov Report
Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
Project coverage is 56.72%. Comparing base (
d93fa03) to head (e2e9010). Report is 6 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| packages/taro-cli/src/presets/commands/build.ts | 0.00% | 1 Missing :warning: |
:x: Your project check has failed because the head coverage (56.72%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files
@@ Coverage Diff @@
## main #17842 +/- ##
==========================================
+ Coverage 55.90% 56.72% +0.82%
==========================================
Files 417 197 -220
Lines 21693 5682 -16011
Branches 5376 1236 -4140
==========================================
- Hits 12127 3223 -8904
+ Misses 7935 2270 -5665
+ Partials 1631 189 -1442
| Flag | Coverage Δ | |
|---|---|---|
| taro-runner | ? |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| ...-cli/src/__tests__/fixtures/default/config/prod.js | 100.00% <ø> (ø) |
|
| packages/taro-cli/src/presets/commands/info.ts | 85.71% <100.00%> (ø) |
|
| packages/taro-cli/src/presets/commands/inspect.ts | 100.00% <100.00%> (ø) |
|
| packages/taro-cli/src/presets/commands/update.ts | 90.24% <100.00%> (+2.43%) |
:arrow_up: |
| packages/taro-cli/src/presets/commands/build.ts | 39.72% <0.00%> (ø) |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@tutuxxx hi,距离 https://github.com/NervJS/taro/pull/17390 已经过去三个多月了,不知是否可以确认至少采纳 NX?lefthook 和 biome 的引入我会分开提PR。
Taro的大佬们都去弄鸿蒙了😂 您提的PR质量都好高啊
npmjs 居然宕机了。
这个日志就比 pnpm 整洁多了
利用 NX 缓存,将原先十几分钟的测试缩短为了三分多钟
如果缓存全中,甚至可以缩短到 1 分多钟
@yoyo837 Hi,我觉得这是一个较大的构建优化,强烈推荐合并,可否帮忙审核一下🙏
及时审下哈,避免积累合并冲突,谢谢
nx 的安装看上去还需要控制台交互? CI会不会有些场景有问题?
nx 的安装看上去还需要控制台交互? CI会不会有些场景有问题?
控制台交互是可选的,CI场景不会出现,可以看看CI日志
还是有一些包由commonjs改esm了,这个是必须的吗?
还是有一些包由commonjs改esm了,这个是必须的吗?
rollup-plugin-copy 改为了 esm,原因是下游 @tarojs/plugin-react-devtools 和 @tarojs/plugin-vue-devtools 的 rollup.config.mjs 是 esm
@tarojs/components-library-react、@tarojs/components-library-solid、@tarojs/components-library-vue3 改为了 esm,原因是它们原本的构建产物就是 esm
其他没有改 esm 的了
还是有一些包由commonjs改esm了,这个是必须的吗?
rollup-plugin-copy 改为了 esm,原因是下游 @tarojs/plugin-react-devtools 和 @tarojs/plugin-vue-devtools 的 rollup.config.mjs 是 esm
@tarojs/components-library-react、@tarojs/components-library-solid、@tarojs/components-library-vue3 改为了 esm,原因是它们原本的构建产物就是 esm
其他没有改 esm 的了
如果不改esm也能让当前PR落地,我个人就建议先保持现状。
还是有一些包由commonjs改esm了,这个是必须的吗?
rollup-plugin-copy 改为了 esm,原因是下游 @tarojs/plugin-react-devtools 和 @tarojs/plugin-vue-devtools 的 rollup.config.mjs 是 esm @tarojs/components-library-react、@tarojs/components-library-solid、@tarojs/components-library-vue3 改为了 esm,原因是它们原本的构建产物就是 esm 其他没有改 esm 的了
如果不改esm也能让当前PR落地,我个人就建议先保持现状。
咱们一个个讨论:
- 如果将 rollup-plugin-copy 改为 commonjs,需要修改相应的 rollup.config.*s
否则会报如下错误
[!] TypeError: copy is not a function
at file:///D:/osc/taro2/packages/taro-platform-harmony/rollup.config-1750678767501.mjs:33:9
at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
at ModuleLoader.import (node:internal/modules/esm/loader:540:24)
at loadConfigFromWrittenFile (D:\osc\taro2\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\loadConfigFile.js:525:17)
at getConfigFileExport (D:\osc\taro2\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\loadConfigFile.js:447:20)
at Object.loadConfigFile (D:\osc\taro2\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\shared\loadConfigFile.js:428:59)
at getConfigs (D:\osc\taro2\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\bin\rollup:1684:39)
at runRollup (D:\osc\taro2\node_modules\.pnpm\[email protected]\node_modules\rollup\dist\bin\rollup:1661:43)
这个改动是否值得?
- @tarojs/components-library-react、@tarojs/components-library-solid、@tarojs/components-library-vue3 的实际产物只有 esm,这个PR之前就是,而且产物都被输出到了 taro-components/lib 目录下,本身的 package.json private 字段是 true,所以它的 type 字段原本是没有意义的,此时改为 module 我认为是正确的。
@yoyo837 哥们咋说?要不发个 beta?
还是有一些包由commonjs改esm了,这个是必须的吗?
改回来了
@yoyo837 还有什么需要改的吗?没有的话就合了吧
还是觉得改动有点大,有些东西应该拆PR来处理
还是觉得改动有点大,有些东西应该拆PR来处理
好!
该PR依赖于 https://github.com/NervJS/taro/pull/18150
还是先确定一下,NX 这个东西是必须的吗?
还是先确定一下,NX 这个东西是必须的吗?
对于一个大型单仓,我认为NX是必须的
- NX可以大幅缩短构建和测试时间,缓存命中时可从20多分钟缩短至3分钟以内
- NX提供了清晰的依赖视图,有助于项目重构
- NX提供了MCP服务,有助于AI辅助
- NX提供了更清晰且容易交互的日志,参阅之前的截图