Skip to content

Conversation

ianzone
Copy link
Contributor

@ianzone ianzone commented Apr 14, 2025

这个 PR 做了什么? (简要描述所做更改)
taro-h5的构建中生成打包后的index.esm.d.ts

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

这个 PR 涉及以下平台:

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

Summary by CodeRabbit

  • 新功能
    • 优化了构建配置,现在支持生成ES模块和对应的TypeScript声明文件,提升了模块兼容性与开发体验。
    • 更新了API定义的引用路径,确保与最新构建输出保持一致。

Copy link

coderabbitai bot commented Apr 14, 2025

Walkthrough

该 PR 对构建流程做出调整,主要在 @tarojs/taro-h5 包中添加了 rollup-plugin-dts 依赖,并在 Rollup 配置中新增生成 ES 模块和 TypeScript 声明文件的输出设置。同时,更新了 parseDefinitionJSON 方法中默认的 apisPath 参数,由原先的 index.d.ts 改为 index.esm.d.ts,以适应新的构建输出。

Changes

文件 更改情况
packages/taro-h5/package.json
packages/taro-h5/rollup.config.ts
devDependencies 中新增 rollup-plugin-dts 依赖,并更新 Rollup 配置,新增生成 ES 模块(index.esm.js)和声明文件(index.esm.d.ts)的流程。
packages/taro-platform-h5/.../parser.ts 修改 parseDefinitionJSON 函数中默认 apisPath 参数,将路径从 index.d.ts 更新为 index.esm.d.ts

Sequence Diagram(s)

sequenceDiagram
    participant Input as index.ts
    participant Rollup
    participant Plugin as dts Plugin
    participant OutputJS as index.esm.js
    participant OutputDTS as index.esm.d.ts

    Input->>Rollup: 读取入口文件
    Rollup->>Rollup: 执行打包 (ES模块)
    Rollup->>OutputJS: 输出ES模块
    Rollup->>Plugin: 调用dts插件生成声明文件
    Plugin->>OutputDTS: 输出 .d.ts 文件
Loading

Possibly related PRs

Suggested Reviewers

  • Single-Dancer
  • yoyo837

Poem

我是一只快乐的小兔子,跳跃在代码间,
Rollup欢快奏响新调,声明文件闪耀如星。
依赖添新,路径改新,
构建路上春风得意,
共庆这轻盈变动,🐰✨笑看未来!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 500c102 and c507e70.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/taro-h5/package.json (1 hunks)
  • packages/taro-h5/rollup.config.ts (2 hunks)
  • packages/taro-platform-h5/build/definition-json/parser.ts (1 hunks)
🔇 Additional comments (4)
packages/taro-h5/package.json (1)

74-75: 添加必要的开发依赖

添加了 @rollup/plugin-node-resolverollup-plugin-dts 这两个开发依赖是解决当前问题的关键。其中 rollup-plugin-dts 将用于生成 TypeScript 类型声明文件,这对于解决 API 定义生成为空的问题至关重要。

packages/taro-h5/rollup.config.ts (2)

6-6: 正确导入 dts 插件

rollup-plugin-dts 中导入 dts 插件,用于后续生成 TypeScript 声明文件。


50-62: 完善 ES 模块和类型声明文件的构建配置

此处添加了两项关键配置:

  1. 生成 ES 模块输出文件 dist/index.esm.js
  2. 利用 dts 插件生成 TypeScript 声明文件 dist/index.esm.d.ts

第二项配置尤为重要,注释明确指出这对于让 taro-platform-h5/build/definition-json/parser.ts 能够正确生成 API 配置是必要的。

packages/taro-platform-h5/build/definition-json/parser.ts (1)

97-97: 更新 API 路径指向新的类型声明文件

parseDefinitionJSON 函数中 apisPath 参数的默认值从 @tarojs/taro-h5/dist/index.d.ts 更改为 @tarojs/taro-h5/dist/index.esm.d.ts,使其与新的 Rollup 配置生成的文件路径保持一致。此更改确保了 API 定义能够正确解析,解决了之前 API 为空的问题。

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 15:08
@ianzone ianzone closed this Apr 14, 2025
@ianzone ianzone deleted the fixh5 branch April 14, 2025 16:01
This was referenced Apr 19, 2025
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.

1 participant