Skip to content

fix: local cannot run problem #2857

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/rn/update-taro-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ config.nav.map((item) => {
item.packages.forEach((element) => {
const { name, version } = element
if (version !== '3.0.0') return // 未适配不导出
if (specialComponent(name)) return
if (param && specialComponent(name)) return
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

需要对 param 进行空值保护

specialComponent 函数中直接使用 param.split() 会在 paramundefined 时抛出错误。根据代码注释和使用场景,process.env.C 是一个可选参数,用于指定需要处理的组件列表。

建议修改为:

-    if (param && specialComponent(name)) return
+    if (!param) return false
+    if (specialComponent(name)) return true
  • 在 scripts/rn/update-taro-entry.js 中添加对 param 的空值判断
  • 确保在未指定组件列表时的默认行为符合预期
🔗 Analysis chain

条件判断需要更严谨的处理

当前的条件判断 param && specialComponent(name) 可能会在 param 未定义时导致组件选择不符合预期。建议添加更明确的参数验证。

建议修改为:

-    if (param && specialComponent(name)) return
+    if (typeof param === 'string' && param.trim() && specialComponent(name)) return

执行以下脚本验证组件筛选逻辑:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证组件筛选逻辑的使用场景
rg -A 3 "process.env.C" .

Length of output: 312


Script:

#!/bin/bash
# 检查 specialComponent 函数的实现
ast-grep --pattern 'function specialComponent($_) { $$$ }'

# 检查 param 的使用场景
rg -B 2 -A 5 "const param = process.env.C" .

Length of output: 1001

adaptedArray.push({
...element,
lowercaseName: element.name.toLowerCase(),
Expand Down
Loading