-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat(cli): 添加获取@jdtaro相关依赖包的功能 #18106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough本次更改在 Changes
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: 输出环境信息
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 分钟 Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
: 考虑处理空值情况当前代码假设
dependencies
和devDependencies
存在时不为null
,但在某些情况下这些字段可能为null
。建议使用更安全的合并方式:
- const dependencies = Object.assign({}, packageJson.dependencies || {}, packageJson.devDependencies || {}) + const dependencies = { + ...(packageJson.dependencies || {}), + ...(packageJson.devDependencies || {}) + }
53-56
: 改进错误处理和日志记录当前的错误处理可以进一步改进:
- 使用
ctx.helper.chalk
来保持日志样式一致性- 考虑是否需要记录完整的错误信息用于调试
} 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
📒 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
相关包的逻辑实现正确,能够动态获取项目依赖中的相关包并合并到现有的包列表中。
// 单独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 [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
添加类型注解并改进函数实现
新增的 getJdtaroPackages
函数存在以下问题:
- 缺少参数和返回值的 TypeScript 类型注解
- 函数命名和注释风格与项目不一致
- 可以使用更简洁的实现方式
应用以下差异来改进函数实现:
-// 单独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.
新增getJdtaroPackages函数用于从package.json中筛选出@jdtaro/开头的依赖包,并将其合并到info命令的输出中
78efff2
to
8711c41
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
新增getJdtaroPackages函数用于从package.json中筛选出@jdtaro/开头的依赖包,并将其合并到info命令的输出中,并添加trycatch
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
@jdtaro/
开头的依赖包,无需手动配置。