-
Notifications
You must be signed in to change notification settings - Fork 262
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
chore: adjust strategies to reduce the build time of HarmonyOS #2727
Conversation
Walkthrough此次变更主要集中在 Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## V3.0 #2727 +/- ##
=======================================
Coverage 83.98% 83.98%
=======================================
Files 221 221
Lines 17867 17867
Branches 2676 2676
=======================================
Hits 15005 15005
Misses 2857 2857
Partials 5 5 ☔ View full report in Codecov by Sentry. |
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: 2
🧹 Outside diff range and nitpick comments (3)
scripts/rn/update-taro-entry.js (3)
7-10
: 移除调试日志并完善环境变量文档
- 请移除非生产环境的调试日志
- 建议为环境变量
C
添加更详细的注释说明,包括其用途和格式要求建议修改如下:
-const param = process.env.C - -console.log('xxxxxxxxxxxxxxxxxxxxxxx-------x-x-x-x-x-x-x-x-x', param) - +/** + * 组件名称环境变量,用于指定需要构建的组件 + * @example C=radio pnpm dev:taro:jdharmonycpp + */ +const param = process.env.C
13-15
: 优化组件名称匹配函数的健壮性当前实现缺少必要的参数验证和错误处理机制。
建议改进如下:
function specialComponent(name) { + if (!name) { + return false + } + if (param && typeof param !== 'string') { + console.warn('环境变量 C 的值必须是字符串类型') + return false + } return param && name.toLowerCase() == param.toLowerCase() }
Line range hint
1-140
: 考虑添加缓存机制优化构建性能当前实现在每次构建时都会重新生成配置文件。建议考虑以下优化方案:
- 实现配置文件的缓存机制,只在组件发生变化时重新生成
- 将组件列表的处理结果缓存到临时文件中
- 添加增量更新支持,只处理发生变化的组件
这些优化可以进一步减少构建时间。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
package.json
(1 hunks)scripts/rn/update-taro-entry.js
(2 hunks)
🔇 Additional comments (1)
package.json (1)
60-64
: 验证组件特定构建功能的实现
根据PR目标,应该支持通过环境变量C=componentName
来指定构建特定组件。但在当前的脚本中没有看到相关的实现。
请运行以下脚本来验证实现:
✅ Verification successful
组件特定构建功能已正确实现
代码中已经实现了通过环境变量C=componentName
来构建特定组件的功能:
- 在
specialComponent
函数中处理环境变量C
的值 - 在生成配置时,如果指定了组件名称,只会包含该特定组件的页面
- 在生成入口文件时,会排除不需要的组件
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证update-taro-entry脚本是否正确处理组件环境变量
# 测试:检查update-taro-entry脚本中是否包含对环境变量C的处理
rg -A 5 "process.env.C" ./scripts/rn/update-taro-entry.js
Length of output: 196
Script:
#!/bin/bash
# 检查update-taro-entry.js的完整实现以了解组件环境变量的处理逻辑
cat ./scripts/rn/update-taro-entry.js
Length of output: 3217
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
🧹 Outside diff range and nitpick comments (5)
scripts/rn/update-taro-entry.js (4)
7-9
: 建议改进调试日志的可读性调试日志的格式不够清晰,建议使用更具描述性的格式。
建议修改为:
const param = process.env.C -console.log('xxxxxxxxxxxxxxxxxxxxxxx-------x-x-x-x-x-x-x-x-x', param) +console.log('[update-taro-entry] 指定构建组件:', param || '全部组件')
11-12
: 建议添加使用说明注释当前注释仅提供了一个示例,建议添加更详细的使用说明。
建议修改为:
-// C=radio pnpm dev:taro:jdharmonycpp +/** + * 使用环境变量 C 指定要构建的组件 + * + * 用法: + * C=组件名称 pnpm dev:taro:jdharmonycpp + * + * 示例: + * C=radio pnpm dev:taro:jdharmonycpp + * + * 注意:组件名称不区分大小写 + */
13-15
: 建议优化组件名称匹配函数当前实现在组件名称为空时可能存在问题。
建议修改为:
function specialComponent(name) { - return param && name.toLowerCase() == param.toLowerCase() + if (!param || !name) return false + return name.toLowerCase() === param.toLowerCase() }
56-62
: 建议重构条件逻辑以提高可读性当前的嵌套条件判断可以简化,使代码更易理解。
建议修改为:
- if (param) { - if (specialComponent(it.name)) { - co.pages.push(`pages/${it.name.toLowerCase()}/index`) - } - } else { - co.pages.push(`pages/${it.name.toLowerCase()}/index`) - } + const shouldInclude = !param || specialComponent(it.name) + if (shouldInclude) { + co.pages.push(`pages/${it.name.toLowerCase()}/index`) + }package.json (1)
60-64
: 建议统一脚本命令格式目前脚本命令的格式不统一,有的使用
pnpm run
,有的直接使用pnpm
。建议统一使用一种格式,推荐使用简短的pnpm
形式:- "dev:taro:weapp": "pnpm update:taro:entry && pnpm run update:taro:entry && pnpm --dir ./packages/nutui-taro-demo dev:weapp", + "dev:taro:weapp": "pnpm update:taro:entry && pnpm --dir ./packages/nutui-taro-demo dev:weapp",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
package.json
(1 hunks)scripts/rn/update-taro-entry.js
(2 hunks)
🔇 Additional comments (2)
scripts/rn/update-taro-entry.js (1)
23-24
: 验证组件过滤逻辑的正确性
需要验证当指定组件构建时,是否正确过滤了其他组件。
✅ Verification successful
Let me gather more information about the component filtering logic by examining the specific implementation.
组件过滤逻辑已验证完成,运行正常
根据代码分析,组件过滤逻辑通过 specialComponent
函数实现,其工作原理是:
- 当环境变量
C
指定了特定组件时,只构建该组件 - 过滤逻辑正确处理了大小写匹配问题
- 过滤后的组件会被正确添加到
adaptedArray
和应用配置中
该实现符合预期的组件过滤需求。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证组件过滤逻辑是否正确工作
# 测试:检查是否存在组件依赖关系
echo "检查组件依赖关系..."
rg -l "import.*from.*@/packages" packages/nutui-taro-demo/src
# 测试:检查组件是否有子组件依赖
echo "检查子组件依赖..."
ast-grep --pattern 'import { $_ } from "@nutui/nutui-react-taro"'
Length of output: 413
Script:
#!/bin/bash
# 检查 specialComponent 函数的实现
rg -A 5 "function specialComponent" scripts/rn/
# 检查 update-taro-entry.js 的完整实现以理解上下文
cat scripts/rn/update-taro-entry.js
# 检查组件引用的具体内容
rg -A 3 "import.*from.*@/packages" packages/nutui-taro-demo/src/pages/index/index.tsx
Length of output: 3840
package.json (1)
60-64
: 验证组件构建功能的正确性
这些脚本已经集成了组件筛选功能,请确认以下几点:
- 使用
C=componentName
参数时是否能正确筛选指定组件 - 大小写是否不敏感,如文档所述
- 在不指定组件时是否正常构建所有组件
✅ Verification successful
Let me check the content of the update-taro-entry.js script to understand how the component filtering logic is implemented.
让我检查一下配置文件以确认完整的组件筛选逻辑。
根据已获取的信息,我可以生成最终响应了。
组件筛选功能已正确实现
通过检查 update-taro-entry.js
的源码,确认以下几点:
- 支持通过
C=componentName
参数筛选指定组件 - 使用
toLowerCase()
实现了大小写不敏感的匹配 - 当不指定组件时(无
C
参数),会构建所有已适配的组件
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 验证 update:taro:entry 脚本的存在性和执行权限
echo "检查 update:taro:entry 脚本..."
ls -l ./scripts/rn/update-taro-entry.js
# 检查脚本中是否包含组件筛选逻辑
echo "检查组件筛选逻辑..."
grep -r "process.env.C" ./scripts/rn/
Length of output: 409
Script:
#!/bin/bash
# 查看 update-taro-entry.js 的具体实现
cat ./scripts/rn/update-taro-entry.js
# 检查是否有相关的测试用例
fd -e test.js -e spec.js update-taro-entry
# 查找可能的组件筛选相关的配置文件
fd -e json -e js config | grep -i component
Length of output: 3308
Script:
#!/bin/bash
# 检查配置文件内容
cat ./src/config.json
# 验证实际的组件目录结构
fd -t d "packages/nutui-taro-demo/src" -d 2
# 检查 package.json 中的 update:taro:entry 脚本定义
grep "update:taro:entry" package.json
Length of output: 32194
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
🧹 Outside diff range and nitpick comments (2)
scripts/rn/update-taro-entry.js (2)
7-12
: 建议增强环境变量处理的健壮性当前实现缺少输入验证和错误处理机制。建议添加以下改进:
- 对环境变量进行类型检查和验证
- 添加更详细的使用说明文档
- 处理无效输入的情况
建议修改如下:
-const param = process.env.C +const param = process.env.C ? process.env.C.trim() : undefined + +if (param === '') { + console.warn('组件名称不能为空,将构建所有组件') +} -// C=radio pnpm dev:taro:jdharmonycpp +/** + * 检查组件名称是否匹配环境变量指定的组件 + * @example + * // 使用方式:C=radio pnpm dev:taro:jdharmonycpp + * @param {string} name - 组件名称 + * @returns {boolean} 是否匹配 + */ function specialComponent(name) { - return param && name.toLowerCase() == param.toLowerCase() + return param && param !== '' && name.toLowerCase() === param.toLowerCase() }
19-20
: 优化组件过滤逻辑的可读性当前的过滤条件可能会影响代码的可读性。建议将过滤逻辑提取为独立的条件判断。
建议修改如下:
- if (version !== '3.0.0') return // 未适配不导出 - if (specialComponent(name)) return + // 跳过未适配的组件 + if (version !== '3.0.0') return + + // 如果指定了特定组件,则跳过其他组件 + const isTargetComponent = specialComponent(name) + if (param && !isTargetComponent) return
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
package.json
(1 hunks)scripts/rn/update-taro-entry.js
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- package.json
🔇 Additional comments (2)
scripts/rn/update-taro-entry.js (2)
53-55
: 代码逻辑清晰,符合需求
条件判断已经过优化,当前实现简洁且符合预期功能。
Line range hint 7-55
: 建议验证环境变量功能的完整性
为确保新增的组件筛选功能正常工作,建议进行以下验证:
✅ Verification successful
Let me gather more information about the environment variable usage and component configuration.
Let me check one more aspect about the build commands and environment variable usage.
环境变量筛选功能验证通过,实现符合预期
根据代码分析和验证结果,环境变量 C
的功能实现完整且正确:
- 通过
process.env.C
正确获取组件名称参数 - 在
dev:taro:jdharmonycpp
等命令中可以使用C=组件名
进行筛选 - 筛选逻辑会同时更新
app.config.ts
的路由配置和组件入口文件 - 大小写处理已考虑(使用
toLowerCase()
进行比较) - 未指定组件名时会导出所有已适配的组件
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查组件名称的处理逻辑
# 测试1:检查是否存在使用环境变量的相关命令
echo "检查构建命令中是否正确使用环境变量 C="
rg "C=[a-zA-Z]+" package.json
# 测试2:检查组件名称在代码中的使用情况
echo "检查现有组件名称的引用"
rg -l "pages/[a-zA-Z]+/index" packages/nutui-taro-demo/src/app.config.ts
Length of output: 355
Script:
#!/bin/bash
# 检查 package.json 中的具体命令内容
echo "检查 package.json 中的构建命令:"
cat package.json | jq -r '.scripts | to_entries | .[] | select(.value | contains("C="))'
# 检查 app.config.ts 中的页面配置
echo -e "\n检查现有的页面配置:"
cat packages/nutui-taro-demo/src/app.config.ts
# 检查是否有其他使用环境变量 C 的地方
echo -e "\n检查其他使用环境变量 C 的位置:"
rg "process.env.C" -A 2
Length of output: 3750
Script:
#!/bin/bash
# 检查所有与 Taro 相关的构建命令
echo "检查 Taro 相关的构建命令:"
cat package.json | jq -r '.scripts | to_entries | .[] | select(.key | contains("taro")) | "\(.key): \(.value)"'
# 检查 update-taro-entry.js 的完整内容
echo -e "\n检查 update-taro-entry.js 的实现:"
cat scripts/rn/update-taro-entry.js
Length of output: 5279
通过增加环境变量,来指定构建哪个组件。这样在鸿蒙编译的时候可以降低编译时长。
命令形式:
C=componentName pnpm dev:taro:jdharmonycpp
, componentName 是组件的名称且忽略大小写。Summary by CodeRabbit
新功能
修复