Skip to content
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

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Nov 11, 2024

通过增加环境变量,来指定构建哪个组件。这样在鸿蒙编译的时候可以降低编译时长。

命令形式:
C=componentName pnpm dev:taro:jdharmonycpp, componentName 是组件的名称且忽略大小写。

Summary by CodeRabbit

  • 新功能

    • 更新了开发脚本,以确保在运行 Taro 开发命令之前执行更新命令。
    • 引入条件逻辑以根据环境变量动态适配组件,提升了组件适配的灵活性。
  • 修复

    • 优化了组件适配过程中的控制流,确保只有符合条件的组件被纳入适配。

Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

此次变更主要集中在@nutui/nutui-react-taro包的package.json文件和scripts/rn/update-taro-entry.js文件上。在package.json中,dev:taro相关脚本的命令被修改,以在执行原有命令之前添加pnpm update:taro:entry命令。在scripts/rn/update-taro-entry.js中,引入了新的环境变量C,并根据该变量的值调整了组件的处理逻辑,以便在配置中仅包含特定组件。

Changes

文件路径 更改摘要
package.json 更新dev:taro脚本命令,添加pnpm update:taro:entry命令到多个子命令之前。
scripts/rn/update-taro-entry.js 添加环境变量C的处理,定义specialComponent(name)函数,调整createConfig函数以根据param条件过滤组件。

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • xiaoyatong

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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

@github-actions github-actions bot added the 3.x label Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (ce66f75) to head (fbbbd85).
Report is 1 commits behind head on V3.0.

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.
📢 Have feedback on the report? Share it here.

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: 2

🧹 Outside diff range and nitpick comments (3)
scripts/rn/update-taro-entry.js (3)

7-10: 移除调试日志并完善环境变量文档

  1. 请移除非生产环境的调试日志
  2. 建议为环境变量 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: 考虑添加缓存机制优化构建性能

当前实现在每次构建时都会重新生成配置文件。建议考虑以下优化方案:

  1. 实现配置文件的缓存机制,只在组件发生变化时重新生成
  2. 将组件列表的处理结果缓存到临时文件中
  3. 添加增量更新支持,只处理发生变化的组件

这些优化可以进一步减少构建时间。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ce66f75 and 2b9083f.

📒 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

scripts/rn/update-taro-entry.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between ce66f75 and 2b9083f.

📒 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: 验证组件构建功能的正确性

这些脚本已经集成了组件筛选功能,请确认以下几点:

  1. 使用 C=componentName 参数时是否能正确筛选指定组件
  2. 大小写是否不敏感,如文档所述
  3. 在不指定组件时是否正常构建所有组件
✅ 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

package.json Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (2)
scripts/rn/update-taro-entry.js (2)

7-12: 建议增强环境变量处理的健壮性

当前实现缺少输入验证和错误处理机制。建议添加以下改进:

  1. 对环境变量进行类型检查和验证
  2. 添加更详细的使用说明文档
  3. 处理无效输入的情况

建议修改如下:

-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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b9083f and fbbbd85.

📒 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

@xiaoyatong xiaoyatong merged commit a9eeca5 into jdf2e:V3.0 Nov 11, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants