Skip to content

Conversation

@Adamlyu-hub
Copy link
Contributor

@Adamlyu-hub Adamlyu-hub commented Aug 1, 2025

这个 PR 做了什么? (简要描述所做更改)

在taro cli:命令中更新taro info,新增@jdtaro 相关包相关版本信息
这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • [✅ ] 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • [✅ ] 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

  • 新功能
    • 环境信息报告现在会自动检测并包含项目中以 @jdtaro/ 开头的依赖包,提升了报告的完整性和针对性。

@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

本次更改对 info 命令进行了增强,使其能够动态检测并报告以 @jdtaro/ 开头的依赖包。通过读取项目根目录下的 package.json 文件,自动收集并追加相关依赖包到原有的 npm 包列表中,提升了环境信息报告的全面性。

Changes

Cohort / File(s) Change Summary
info 命令动态依赖收集
packages/taro-cli/src/presets/commands/info.ts
修改 info 函数,增加读取 package.json 并动态收集以 @jdtaro/ 开头的依赖包,合并进环境报告的 npm 包列表。

Estimated code review effort

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

Suggested reviewers

  • tutuxxx

Poem

🐇
项目信息更聪明,
动态依赖来报明。
@jdtaro/ 包不再漏,
代码小改显神通。
轻松审阅不用愁,
兔子为你鼓掌中!
🎉

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

@coderabbitai coderabbitai bot requested a review from tutuxxx August 1, 2025 05:52
Copy link

@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

🧹 Nitpick comments (2)
packages/taro-cli/src/presets/commands/info.ts (2)

43-43: 修复 ESLint 格式问题

该行存在尾随空格,需要清理。

-  let npmPackages = ctx.helper.UPDATE_PACKAGE_LIST.concat(['react', 'react-native', 'expo', 'taro-ui'])
-  
+  let npmPackages = ctx.helper.UPDATE_PACKAGE_LIST.concat(['react', 'react-native', 'expo', 'taro-ui'])
+

48-48: 修复 ESLint 尾随空格错误

多行存在尾随空格,需要清理以符合代码规范。

     const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
-    
+
     // 筛选出@jdtaro相关的包
     const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
-    
+
     // 将@jdtaro包添加到npmPackages列表中
     npmPackages = npmPackages.concat(jdtaroPackages)
   }
-  
+

Also applies to: 51-51, 55-55

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9772307 and 5219be0.

📒 Files selected for processing (1)
  • packages/taro-cli/src/presets/commands/info.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。...
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
🪛 ESLint
packages/taro-cli/src/presets/commands/info.ts

[error] 43-43: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 48-48: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 51-51: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 55-55: Trailing spaces not allowed.

(no-trailing-spaces)

🔇 Additional comments (2)
packages/taro-cli/src/presets/commands/info.ts (2)

39-42: 变量声明和初始化逻辑正确

变量声明清晰,初始化逻辑符合预期。通过解构获取必要的路径和文件系统工具,为后续的动态包检测做准备。


44-54: 功能实现正确且符合 PR 目标

动态检测 @jdtaro/ 相关包的实现逻辑正确:

  1. 检查 package.json 是否存在
  2. 读取并解析依赖信息
  3. 合并 dependencies 和 devDependencies
  4. 筛选出以 @jdtaro/ 开头的包
  5. 添加到 npmPackages 列表中

这个实现很好地满足了 PR 目标,使 taro info 命令能够动态报告 @jdtaro 相关包的版本信息。

Comment on lines +45 to +54
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})

// 筛选出@jdtaro相关的包
const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))

// 将@jdtaro包添加到npmPackages列表中
npmPackages = npmPackages.concat(jdtaroPackages)
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

添加错误处理以提高健壮性

当前的 JSON 解析逻辑缺乏错误处理,如果 package.json 格式错误会导致程序崩溃。建议添加 try-catch 块来处理潜在的解析错误。

   // 如果package.json存在,则读取并筛选@jdtaro相关包
   if (fs.existsSync(packageJsonPath)) {
-    const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
-    const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
-    
-    // 筛选出@jdtaro相关的包
-    const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
-    
-    // 将@jdtaro包添加到npmPackages列表中
-    npmPackages = npmPackages.concat(jdtaroPackages)
+    try {
+      const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
+      const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
+
+      // 筛选出@jdtaro相关的包
+      const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
+
+      // 将@jdtaro包添加到npmPackages列表中
+      npmPackages = npmPackages.concat(jdtaroPackages)
+    } catch (error) {
+      // 如果解析失败,继续使用默认的包列表
+      console.warn('Warning: Failed to parse package.json, using default package list')
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
// 筛选出@jdtaro相关的包
const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
// 将@jdtaro包添加到npmPackages列表中
npmPackages = npmPackages.concat(jdtaroPackages)
}
if (fs.existsSync(packageJsonPath)) {
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
// 筛选出@jdtaro相关的包
const jdtaroPackages = Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
// 将@jdtaro包添加到npmPackages列表中
npmPackages = npmPackages.concat(jdtaroPackages)
} catch (error) {
// 如果解析失败,继续使用默认的包列表
console.warn('Warning: Failed to parse package.json, using default package list')
}
}
🧰 Tools
🪛 ESLint

[error] 48-48: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 51-51: Trailing spaces not allowed.

(no-trailing-spaces)

🤖 Prompt for AI Agents
In packages/taro-cli/src/presets/commands/info.ts around lines 45 to 54, the
JSON.parse call on package.json content lacks error handling, which can cause
the program to crash if the file is malformed. Wrap the JSON.parse and
subsequent dependency extraction logic inside a try-catch block to catch and
handle any parsing errors gracefully, preventing the program from crashing and
allowing for appropriate error logging or fallback behavior.

Copy link

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

♻️ Duplicate comments (1)
packages/taro-cli/src/presets/commands/info.ts (1)

45-54: 缺少错误处理机制

JSON.parse 调用缺乏错误处理,如果 package.json 格式错误会导致程序崩溃。建议添加 try-catch 块来处理潜在的解析错误。

🧹 Nitpick comments (1)
packages/taro-cli/src/presets/commands/info.ts (1)

43-43: 清理尾随空格

代码中存在尾随空格,建议清理以符合代码风格规范。

-  
+
-    
+
-    
+
-  
+

Also applies to: 48-48, 51-51, 55-55

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5219be0 and 1cd09b5.

📒 Files selected for processing (1)
  • packages/taro-cli/src/presets/commands/info.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。...
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
📚 Learning: 在 taro 的 water-flow 组件中,getrectsizesync 函数如果找不到指定的节点,会一直处于 pending 状态而不是抛出错误。在这种情况下,应该使用 promise.rac...
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 water-flow 组件中,getRectSizeSync 函数如果找不到指定的节点,会一直处于 pending 状态而不是抛出错误。在这种情况下,应该使用 Promise.race 添加超时机制,而不是仅依赖 try/catch 来处理错误。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
📚 Learning: 在 taro 的 getrectsizesync 函数中,如果找不到指定的节点,函数会一直处于 pending 状态而不是抛出错误。在这种情况下,使用 try/catch 处理不够充分,需要添加超时处...
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 getRectSizeSync 函数中,如果找不到指定的节点,函数会一直处于 pending 状态而不是抛出错误。在这种情况下,使用 try/catch 处理不够充分,需要添加超时处理如 Promise.race 来避免无限等待。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
📚 Learning: 在 taro 的 water-flow 组件中,getrectsizesync 函数如果找不到指定的节点并且重试次数用尽,会一直处于 pending 状态而不是抛出错误,因为它在 retrytimes...
Learnt from: Single-Dancer
PR: NervJS/taro#17653
File: packages/taro-components-advanced/src/components/water-flow/node.ts:83-95
Timestamp: 2025-05-06T06:55:44.077Z
Learning: 在 Taro 的 water-flow 组件中,getRectSizeSync 函数如果找不到指定的节点并且重试次数用尽,会一直处于 pending 状态而不是抛出错误,因为它在 retryTimes <= 0 时直接返回而不 resolve 或 reject Promise。应该使用 Promise.race 添加超时机制来解决这个问题。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
📚 Learning: 在 jest-helper 包中,src 目录下没有 __tests__ 测试目录,只包含 resolver.ts、sequencer.ts 和 snapshot 目录。不要假设包中存在测试目录结构。...
Learnt from: ianzone
PR: NervJS/taro#17842
File: packages/jest-helper/tsconfig.json:9-9
Timestamp: 2025-06-23T00:09:31.233Z
Learning: 在 jest-helper 包中,src 目录下没有 __tests__ 测试目录,只包含 resolver.ts、sequencer.ts 和 snapshot 目录。不要假设包中存在测试目录结构。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
📚 Learning: stefanbuck/github-issue-parser@v3 github action 的输出字段名称是 `jsonstring`,不是 `json`。在工作流中应该使用 `${{ steps...
Learnt from: ianzone
PR: NervJS/taro#17937
File: .github/workflows/issue-labeler.yml:31-31
Timestamp: 2025-07-01T15:46:08.457Z
Learning: stefanbuck/github-issue-parser@v3 GitHub Action 的输出字段名称是 `jsonString`,不是 `json`。在工作流中应该使用 `${{ steps.issue-parser.outputs.jsonString }}` 来引用解析后的 JSON 数据。

Applied to files:

  • packages/taro-cli/src/presets/commands/info.ts
🪛 ESLint
packages/taro-cli/src/presets/commands/info.ts

[error] 43-43: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 48-48: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 51-51: Trailing spaces not allowed.

(no-trailing-spaces)


[error] 55-55: Trailing spaces not allowed.

(no-trailing-spaces)

🔇 Additional comments (1)
packages/taro-cli/src/presets/commands/info.ts (1)

39-42: 变量声明和初始化逻辑正确

变量提取和路径构造的实现符合最佳实践,npmPackages 的初始化也很合理。


async function info (options, ctx) {
const npmPackages = ctx.helper.UPDATE_PACKAGE_LIST.concat(['react', 'react-native', 'expo', 'taro-ui'])
const { appPath } = ctx.paths
Copy link
Member

Choose a reason for hiding this comment

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

1、相关逻辑建议抽成一个单独的function
2、反序列化这些要trycatch一下

This was referenced Aug 2, 2025
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.

3 participants