Skip to content

fix(taro-platform-h5): 修复生成definition.json api为空 #17548

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

Merged
merged 3 commits into from
May 6, 2025

Conversation

ianzone
Copy link
Contributor

@ianzone ianzone commented Apr 14, 2025

这个 PR 做了什么? (简要描述所做更改)

  1. 重放 fix(taro-platform-h5): 修复生成definition.json api为空,导致Taro.xxx未能被转换 #17543 的 revert
  2. 修改taro-h5构建配置,使其生成打包后的 index.esm.d.ts
  3. 撤销了快照更新,旧的快照是对的

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • 修复了CI工作流程中的命名错误和部分覆盖率处理配置。
  • Chores

    • 更新并优化了构建、测试和打包脚本及依赖管理。
    • 简化了TypeScript编译配置,改进了声明文件生成与输出目录设置,提升整体构建效率。
    • 替换并统一了Rollup中TypeScript插件,简化配置文件路径及插件选项。

Copy link

coderabbitai bot commented Apr 14, 2025

"""

Walkthrough

此次更改主要聚焦于更新与优化各包的构建配置。主要包括纠正 GitHub Actions 中任务名称的错别字、移除 Codecov 上传参数以及统一替换 Rollup 中旧的 TypeScript 插件(rollup-plugin-ts)为新的插件(@rollup/plugin-typescript)。同时,各包的配置文件也针对 TypeScript 声明文件生成和调试信息(sourceMap)的开启做了相应调整。

Changes

文件/文件组 变更说明
.github/workflows/nodejs.yml 修改任务名称(从 nodejs-tesing 改为 nodejs-testing),移除 Codecov 上传步骤中的 move_coverage_to_trash 参数。
packages/taro-h5/ (package.json, rollup.config.ts, tsconfig.json) 更新构建与测试脚本;依赖调整:移除 rollup-plugin-ts,新增 @rollup/plugin-typescript 和 rollup-plugin-dts;启用 sourceMap,并调整 Rollup 配置生成声明文件。
packages/taro-platform-harmony-hybrid/ (package.json, rollup.config.ts, tsconfig.json) 升级 @rollup/plugin-typescript 版本,移除 rollup-plugin-ts;简化 Rollup 配置(移除不必要的 path 模块和 tsconfig 配置);新增 declaration 与 outDir 配置。
packages/taro-platform-harmony/ (package.json, rollup.config.ts) 替换 rollup-plugin-ts 为 @rollup/plugin-typescript;移除对 cwd 的依赖,直接使用相对路径,简化配置。
packages/taro-router/package.json 更新 TS 声明文件属性:将 "typings": "dist/index.esm.d.ts" 替换为 "types": "dist/index.d.ts"
packages/taro-runtime/ (package.json, rollup.config.ts) 替换构建脚本中的 rollup-plugin-ts 为 @rollup/plugin-typescript;在 Rollup 配置中增加排除自身配置文件的设置。

Sequence Diagram(s)

sequenceDiagram
    participant Dev as 开发者
    participant Rollup as Rollup 构建
    participant TS as @rollup/plugin-typescript
    participant DTS as rollup-plugin-dts
    Dev->>Rollup: 运行构建命令
    Rollup->>TS: 调用 TypeScript 插件(排除 rollup.config.ts)
    TS-->>Rollup: 返回编译结果
    Rollup->>DTS: 生成 TypeScript 声明文件
    DTS-->>Rollup: 返回声明文件
    Rollup->>Dev: 输出 ESM 模块和声明文件
Loading

Assessment against linked issues

Objective Addressed Explanation
修复生成 definition.json api 为空,导致 Taro.xxx 未能被转换 (#17543)

Suggested reviewers

  • yoyo837

Poem

嗨,我是一只小兔子,跳跃在代码的田野,
错别字消失,新插件来替,
构建流程变得明快流畅,
声明文件绽放如花,
感谢这份更新,我轻轻眨眼😊
(\\_/)\n(o.o) >🥕
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7680d96 and c322c77.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • .github/workflows/nodejs.yml (1 hunks)
  • packages/taro-h5/package.json (3 hunks)
  • packages/taro-h5/rollup.config.ts (3 hunks)
  • packages/taro-h5/tsconfig.json (1 hunks)
  • packages/taro-platform-harmony-hybrid/package.json (1 hunks)
  • packages/taro-platform-harmony-hybrid/rollup.config.ts (4 hunks)
  • packages/taro-platform-harmony-hybrid/tsconfig.json (1 hunks)
  • packages/taro-platform-harmony/package.json (1 hunks)
  • packages/taro-platform-harmony/rollup.config.ts (6 hunks)
  • packages/taro-router/package.json (1 hunks)
  • packages/taro-runtime/package.json (2 hunks)
  • packages/taro-runtime/rollup.config.ts (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • .github/workflows/nodejs.yml
  • packages/taro-runtime/rollup.config.ts
  • packages/taro-runtime/package.json
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/taro-platform-harmony-hybrid/tsconfig.json
  • packages/taro-platform-harmony/package.json
  • packages/taro-h5/tsconfig.json
  • packages/taro-platform-harmony-hybrid/rollup.config.ts
  • packages/taro-router/package.json
  • packages/taro-platform-harmony-hybrid/package.json
  • packages/taro-platform-harmony/rollup.config.ts
  • packages/taro-h5/package.json
🔇 Additional comments (4)
packages/taro-h5/rollup.config.ts (4)

3-3: 从旧的 TypeScript 插件切换到 @rollup/plugin-typescript

此更改将 Rollup 的 TypeScript 插件从先前的插件(可能是 rollup-plugin-ts)更换为官方推荐的 @rollup/plugin-typescript,这有助于保持与最新 TypeScript 版本的兼容性并获得更好的社区支持。


6-6: 添加 rollup-plugin-dts 支持生成 TypeScript 声明文件

新增了 rollup-plugin-dts 插件以支持生成打包的 TypeScript 声明文件(.d.ts),这对于 TypeScript 项目的下游消费者非常重要。


28-28: 优化 TypeScript 插件配置

通过明确排除 rollup.config.ts 文件避免了构建过程中的自引用问题,这是一个良好的实践。


50-62:

❓ Verification inconclusive

重要:修复 definition.json API 生成问题

这些新增的配置是本次 PR 的核心修复点,特别是第二个配置块(第 57-62 行):

  1. 第一个配置生成打包的 ESM 模块(dist/index.esm.js)
  2. 第二个配置生成打包的类型声明文件(dist/index.esm.d.ts)

根据第 59 行的注释,这个声明文件是 taro-platform-h5 生成 API 定义所必需的。缺少这个配置会导致 definition.json 中的 API 为空,正是本 PR 要修复的问题。这个修复有效地恢复了之前在 PR #17543 中移除的功能。


🏁 Script executed:

#!/bin/bash
# 验证构建后是否能正确生成 index.esm.d.ts 文件和 definition.json 文件

# 检查构建输出目录中是否存在这些文件
echo "检查 index.esm.d.ts 和相关文件的存在性:"
fd "index\.esm\.d\.ts|definition\.json" packages/taro-h5/ -t f

# 检查 definition.json 解析器源码,了解它如何依赖 index.esm.d.ts
echo -e "\n解析器代码如何使用 index.esm.d.ts:"
fd "parser\.ts" packages/taro-h5/build -t f | xargs cat

Length of output: 366


为了确认 taro-platform-h5parser.ts 如何依赖生成的 .d.ts,请执行以下脚本来定位并查看该文件的前几行内容:


🏁 Script executed:

#!/bin/bash
# 查找所有 parser.ts 文件的位置
echo "查找 parser.ts 文件位置:"
fd 'parser\.ts' -t f

# 查看 taro-platform-h5 下 parser.ts 的前 30 行
parser_file=$(fd 'taro-platform-h5/build/definition-json/parser.ts' -t f | head -n1)
if [ -n "$parser_file" ]; then
  echo -e "\n查看 $parser_file 前 30 行内容:"
  sed -n '1,30p' "$parser_file"
else
  echo "未找到 taro-platform-h5/build/definition-json/parser.ts 文件。"
fi

Length of output: 568


请再次定位并查看正确路径下的 parser.ts,确认它如何引用生成的 .d.ts 文件。执行:


🏁 Script executed:

#!/bin/bash
# 定位 parser.ts
parser_file=$(fd 'packages/taro-platform-h5/build/definition-json/parser.ts' -t f | head -n1)
if [ -n "$parser_file" ]; then
  echo "找到文件:$parser_file,下面输出前50行内容:"
  sed -n '1,50p' "$parser_file"
else
  echo "未找到 packages/taro-platform-h5/build/definition-json/parser.ts"
fi

Length of output: 244


请执行以下脚本,查看 packages/taro-platform-h5/build/definition-json/parser.ts 的前 200 行内容,以确认它如何引用生成的 .d.ts 文件:


🏁 Script executed:

#!/bin/bash
# 确认 parser.ts 路径并输出前200行
parser_file=$(fd 'packages/taro-platform-h5/build/definition-json/parser.ts' -t f | head -n1)
if [ -n "$parser_file" ]; then
  echo "找到 parser.ts:$parser_file,输出前200行内容:"
  sed -n '1,200p' "$parser_file"
else
  echo "未找到 packages/taro-platform-h5/build/definition-json/parser.ts"
fi

Length of output: 244


重要:修复 definition.json API 生成问题

文件:packages/taro-h5/rollup.config.ts
行号:50–62

variesConfig.push({
  input: 'src/index.ts',
  output: {
    file: 'dist/index.esm.js',
    inlineDynamicImports: true
  }
}, {
  // 需要该配置才能生成打包的 .d.ts 文件供 taro-platform-h5/build/definition-json/parser.ts 生成 apis 配置
  input: 'src/index.ts',
  output: { file: 'dist/index.esm.d.ts' },
  plugins: [dts()]
})

这些新增配置是本次 PR 的核心修复点:

  • 第一块用于打包并输出 ESM 模块(dist/index.esm.js)
  • 第二块用于打包并输出类型声明文件(dist/index.esm.d.ts),供后续生成 definition.json 的解析器使用

⚠️ 请注意:目前在源码中未能直接定位到 packages/taro-platform-h5/build/definition-json/parser.ts,请手动确认该解析器是否已正确读取 dist/index.esm.d.ts,以避免缺少声明文件导致生成的 API 定义为空。

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

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

Support

Need 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)

  • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@coderabbitai coderabbitai bot requested review from Single-Dancer and yoyo837 April 14, 2025 16:07
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.70%. Comparing base (6a5c39e) to head (c322c77).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17548      +/-   ##
==========================================
- Coverage   58.37%   57.70%   -0.68%     
==========================================
  Files         469      469              
  Lines       27230    26550     -680     
  Branches     5998     5875     -123     
==========================================
- Hits        15895    15320     -575     
+ Misses       9960     9725     -235     
- Partials     1375     1505     +130     
Flag Coverage Δ
taro-cli 72.37% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 49.67% <ø> (-3.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 171 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yoyo837 yoyo837 requested a review from tutuxxx April 15, 2025 02:00
This was referenced Apr 19, 2025
@yoyo837 yoyo837 merged commit 7d657e6 into NervJS:main May 6, 2025
24 checks passed
@ianzone ianzone deleted the fix-h5 branch May 6, 2025 16:18
This was referenced May 10, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jun 27, 2025
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants