Skip to content

Conversation

Adamlyu-hub
Copy link
Contributor

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

这个 PR 做了什么? (简要描述所做更改)
新增getJdtaroPackages函数用于从package.json中筛选出@jdtaro/开头的依赖包,并将其合并到info命令的输出中,并添加trycatch

这个 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/ 开头的依赖包,无需手动配置。
  • 优化
    • 信息收集流程更健壮,异常情况下不会中断执行。

Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

本次更改在 packages/taro-cli/src/presets/commands/info.ts 文件中新增了一个用于提取项目依赖中所有以 @jdtaro/ 开头包名的辅助函数,并在 info 命令中动态地将这些包名加入环境信息报告。异常处理被加强,确保读取依赖信息时出错不会中断执行。

Changes

Cohort / File(s) Change Summary
Jdtaro 包依赖提取与 info 命令扩展
packages/taro-cli/src/presets/commands/info.ts
新增 getJdtaroPackages(ctx) 函数以安全提取所有 @jdtaro/ 相关依赖,并在 info 命令中动态合并这些依赖到报告列表。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant FS
    participant Envinfo

    User->>CLI: 运行 info 命令
    CLI->>FS: 读取 package.json
    FS-->>CLI: 返回依赖信息或抛出异常
    CLI->>CLI: getJdtaroPackages(ctx) 解析 @jdtaro/ 依赖
    CLI->>Envinfo: 传递扩展后的 npmPackages 列表
    Envinfo-->>CLI: 返回环境信息
    CLI-->>User: 输出环境信息
Loading

Estimated code review effort

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

Poem

兔子跳跃查依赖,
Jdtaro 包全都来。
读取 package.json,
错误日志不慌乱。
info 命令更强大,
环境报告更精彩!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 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 78efff2 and 8711c41.

📒 Files selected for processing (1)
  • packages/taro-cli/src/presets/commands/info.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/taro-cli/src/presets/commands/info.ts
✨ 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.

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)

48-48: 考虑处理空值情况

当前代码假设 dependenciesdevDependencies 存在时不为 null,但在某些情况下这些字段可能为 null

建议使用更安全的合并方式:

-      const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
+      const dependencies = {
+        ...(packageJson.dependencies || {}),
+        ...(packageJson.devDependencies || {})
+      }

53-56: 改进错误处理和日志记录

当前的错误处理可以进一步改进:

  1. 使用 ctx.helper.chalk 来保持日志样式一致性
  2. 考虑是否需要记录完整的错误信息用于调试
   } catch (error) {
-    // 记录错误但不中断程序执行(添加trycatch)
-    console.error('读取或解析package.json时发生错误:', error.message)
+    console.error(ctx.helper.chalk.yellow('读取或解析 package.json 时发生错误:'), error.message)
   }
📜 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 78efff2.

📒 Files selected for processing (1)
  • packages/taro-cli/src/presets/commands/info.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
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 文件。
📚 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
🔇 Additional comments (1)
packages/taro-cli/src/presets/commands/info.ts (1)

62-66: LGTM! 代码逻辑正确

新增 @jdtaro 相关包的逻辑实现正确,能够动态获取项目依赖中的相关包并合并到现有的包列表中。

Comment on lines +38 to +59
// 单独function获取@jdtaro相关的包
function getJdtaroPackages(ctx) {
try {
const { appPath } = ctx.paths
const fs = ctx.helper.fs
const packageJsonPath = path.join(appPath, 'package.json')

if (fs.existsSync(packageJsonPath)) {
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
const packageJson = JSON.parse(packageJsonContent)
const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})

// 筛选出@jdtaro相关的包
return Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
}
} catch (error) {
// 记录错误但不中断程序执行(添加trycatch)
console.error('读取或解析package.json时发生错误:', error.message)
}

return []
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

添加类型注解并改进函数实现

新增的 getJdtaroPackages 函数存在以下问题:

  1. 缺少参数和返回值的 TypeScript 类型注解
  2. 函数命名和注释风格与项目不一致
  3. 可以使用更简洁的实现方式

应用以下差异来改进函数实现:

-// 单独function获取@jdtaro相关的包
-function getJdtaroPackages(ctx) {
+/**
+ * 获取项目中所有 @jdtaro 相关的依赖包
+ */
+function getJdtaroPackages(ctx: IPluginContext): string[] {
   try {
-    const { appPath } = ctx.paths
-    const fs = ctx.helper.fs
+    const { fs } = ctx.helper
+    const { appPath } = ctx.paths
     const packageJsonPath = path.join(appPath, 'package.json')

     if (fs.existsSync(packageJsonPath)) {
       const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
       const packageJson = JSON.parse(packageJsonContent)
-      const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {})
+      const dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies }

-      // 筛选出@jdtaro相关的包
       return Object.keys(dependencies).filter(pkg => pkg.startsWith('@jdtaro/'))
     }
   } catch (error) {
-    // 记录错误但不中断程序执行(添加trycatch)
-    console.error('读取或解析package.json时发生错误:', error.message)
+    console.error('读取或解析 package.json 时发生错误:', error.message)
   }

   return []
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/taro-cli/src/presets/commands/info.ts around lines 38 to 59, the
getJdtaroPackages function lacks TypeScript type annotations for its parameter
and return value, uses inconsistent naming and comment style, and can be
simplified. Add appropriate TypeScript types for the ctx parameter and the
returned array of strings, rename the function and comments to match the
project's naming conventions and style, and refactor the implementation to be
more concise, such as using optional chaining and direct filtering without
intermediate variables.

@Single-Dancer Single-Dancer added this to the 4.1.5 milestone Aug 1, 2025
新增getJdtaroPackages函数用于从package.json中筛选出@jdtaro/开头的依赖包,并将其合并到info命令的输出中
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.95%. Comparing base (ee1b31e) to head (8711c41).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/taro-cli/src/presets/commands/info.ts 86.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18106      +/-   ##
==========================================
+ Coverage   54.93%   54.95%   +0.01%     
==========================================
  Files         419      419              
  Lines       21736    21750      +14     
  Branches     5341     5365      +24     
==========================================
+ Hits        11941    11953      +12     
- Misses       8116     8118       +2     
  Partials     1679     1679              
Flag Coverage Δ
taro-cli 72.85% <86.66%> (+0.29%) ⬆️
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/taro-cli/src/presets/commands/info.ts 85.71% <86.66%> (ø)
🚀 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.

@Single-Dancer Single-Dancer merged commit e217feb into NervJS:main Aug 1, 2025
54 of 57 checks passed
@Single-Dancer Single-Dancer changed the title Chore(cli): 添加获取@jdtaro相关依赖包的功能 feat(cli): 添加获取@jdtaro相关依赖包的功能 Aug 1, 2025
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.

2 participants