-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(ascf): 增加Taro -> ascf的方法映射 #18448
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在 initNativeApi 末尾引入并调用 reflectApis,将特定 Taro API 映射到 has 能力;新增 reflect-apis.ts 实现映射与 promisify 处理。在 AscfApp 的 setupTransaction 收尾阶段,于 modifyWebpackConfig 之后新增一次 generateProjectConfig('ascf.config.json', 'ascf.config.json') 调用。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as 应用
participant Init as initNativeApi
participant RA as reflectApis
participant PA as processApis
participant HAS as has(平台能力)
App->>Init: 初始化平台原生 API
Note over Init: 定义 getRenderer 等既有步骤
Init->>RA: reflectApis(taro, has)
RA->>PA: processApis({ needPromiseApis, isOnlyPromisify: true, transformMeta })
PA->>HAS: 调用映射后的能力键(如 navigateToAtomicService)
HAS-->>PA: 返回结果(Promise)
PA-->>RA: 包装后的 Promise API
RA-->>Init: 完成反射封装
sequenceDiagram
autonumber
participant Build as AscfApp 构建
participant TX as setupTransaction(close)
participant MW as modifyWebpackConfig
participant GPC as generateProjectConfig
Build->>TX: 收尾阶段
TX->>MW: 调整 Webpack 配置
MW-->>TX: 完成
TX->>GPC: 生成 ascf.config.json → ascf.config.json
GPC-->>TX: 完成
TX-->>Build: 结束
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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
🧹 Nitpick comments (1)
packages/taro-platform-ascf/src/reflect-apis.ts (1)
12-12: 建议添加类型标注虽然代码逻辑正确,但建议为
needPromiseApis添加显式类型标注以提高可维护性。应用此差异添加类型标注:
-const needPromiseApis = new Set(reflectApisMap.keys()) +const needPromiseApis: Set<string> = new Set(reflectApisMap.keys())
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/taro-platform-ascf/src/apis.ts(2 hunks)packages/taro-platform-ascf/src/program.ts(1 hunks)packages/taro-platform-ascf/src/reflect-apis.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/taro-platform-ascf/src/apis.ts (1)
packages/taro-platform-ascf/src/reflect-apis.ts (1)
reflectApis(14-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (5)
packages/taro-platform-ascf/src/apis.ts (2)
4-4: LGTM!导入语句正确,符合文件结构。
35-35: LGTM!在
initNativeApi末尾调用reflectApis的位置恰当,可以在标准 API 初始化完成后进行反射映射。这遵循了现有的 API 处理模式。packages/taro-platform-ascf/src/reflect-apis.ts (2)
7-10: LGTM!API 映射正确且语义清晰,将小程序导航方法映射到鸿蒙原子化服务的对应方法。
14-25: 确认 ASCF 原子服务 API 并添加运行时校验
- 手动核对 has.navigateToAtomicService 和 has.navigateBackAtomicService 在目标 ASCF 环境中可用,参数/返回值与 Taro.navigateToMiniProgram/navigateBackMiniProgram 保持兼容
- 在 packages/taro-platform-ascf/src/reflect-apis.ts 的 transformMeta 中,调用前通过
if (typeof has[key] !== 'function')输出或抛出友好错误,避免调用不存在的方法时报错- 可在注释或文档中添加官方 API 链接,便于后续维护和验证
packages/taro-platform-ascf/src/program.ts (1)
40-40: 保持ascf.config.json作为源/目标文件一致
与 taro-platform-swan 用法一致,无需改动。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18448 +/- ##
=======================================
Coverage 55.97% 55.97%
=======================================
Files 416 416
Lines 21560 21560
Branches 5305 5251 -54
=======================================
Hits 12069 12069
+ Misses 7879 7873 -6
- Partials 1612 1618 +6
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit