-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Chore: 更新 taro info,添加 @jdtaro 相关包 #18105
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 分钟 Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ 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)
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
📒 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/ 相关包的实现逻辑正确:
- 检查 package.json 是否存在
- 读取并解析依赖信息
- 合并 dependencies 和 devDependencies
- 筛选出以 @jdtaro/ 开头的包
- 添加到 npmPackages 列表中
这个实现很好地满足了 PR 目标,使
taro info命令能够动态报告 @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) | ||
| } |
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
添加错误处理以提高健壮性
当前的 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.
| 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.
5219be0 to
1cd09b5
Compare
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: 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
📒 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 |
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.
1、相关逻辑建议抽成一个单独的function
2、反序列化这些要trycatch一下
这个 PR 做了什么? (简要描述所做更改)
在taro cli:命令中更新taro info,新增@jdtaro 相关包相关版本信息
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
@jdtaro/开头的依赖包,提升了报告的完整性和针对性。