taro icon indicating copy to clipboard operation
taro copied to clipboard

chore: add tsdown

Open ianzone opened this issue 7 months ago • 20 comments

这个 PR 做了什么? (简要描述所做更改) 使用 tsdown 对 taro-runtime 进行构建,删除不兼容 node22 的 rollup 插件

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

  • [ ] 错误修复 (Bugfix) issue: fix #
  • [ ] 新功能 (Feature)
  • [ ] 代码重构 (Refactor)
  • [ ] TypeScript 类型定义修改 (Types)
  • [ ] 文档修改 (Docs)
  • [ ] 代码风格更新 (Code style update)
  • [x] 构建优化 (Chore)
  • [ ] 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

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

Summary by CodeRabbit

  • 构建与依赖

    • 构建工具从 Rollup 切换为 tsdown,相关配置和依赖已更新。
    • 移除了 Rollup 相关的脚本和依赖,新增 tsdown 配置文件。
    • @tarojs/runtime 包声明为 ES module,构建脚本和配置已相应调整。
  • 其他变更

    • 优化了部分导出语句顺序,不影响功能和对外接口。
    • Jest 配置文件切换为 ES module 语法,保持测试功能不变。
    • TypeScript 配置调整,移除对已删除 Rollup 配置文件的编译包含,新增模块解析配置。
    • 修正注释中的拼写错误,增强代码注释规范。
    • 替换了部分类型定义方式,提升类型安全性和兼容性。

ianzone avatar May 19 '25 18:05 ianzone

"""

Walkthrough

本次变更主要将 @tarojs/runtime 包的构建工具从 Rollup 迁移到 tsdown,相关配置文件与脚本做了相应调整。涉及 ES module 语法替换、依赖项更新、构建脚本和配置文件的增删,以及部分导出顺序调整。

Changes

文件/路径分组 变更摘要
package.json devDependencies 新增 tsdown,位置在 tslib 之前。
packages/taro-runtime/jest.config.js Jest 配置由 CommonJS 改为 ES module 语法,使用 ES import/export。
packages/taro-runtime/package.json 添加 "type": "module",构建脚本由 rollup 切换为 tsdown,移除 rollup 相关依赖。
packages/taro-runtime/rollup.config.ts 删除 Rollup 配置文件。
packages/taro-runtime/tsdown.config.ts 新增 tsdown 配置文件,导出三个不同配置,支持多格式构建。
packages/taro-runtime/tsconfig.json "include" 移除 rollup.config.ts,添加 "moduleResolution": "bundler"
packages/taro-rn/src/lib/index.ts 调整导出语句顺序,无功能变化。
packages/shared/src/shortcuts.ts 添加关于 const enum 的注释及备选方案代码,修正注释拼写错误。
tests/tests/framework.spec.ts 类型导入路径由相对路径改为包内路径,改为类型导入。
packages/taro-platform-ascf/tsconfig.json 简化 "include" 字段格式,无功能变化。

Sequence Diagram(s)

sequenceDiagram
    participant 开发者
    participant tsdown
    participant 源码(src)
    participant 输出(dist)

    开发者->>tsdown: 执行 tsdown 构建命令 (build/dev)
    tsdown->>源码(src): 读取 TypeScript 源码文件
    tsdown->>输出(dist): 生成多格式构建产物(ESM、CJS),附带 sourcemap

Suggested reviewers

  • yoyo837

Poem

🐇
换下 rollup,迎来 tsdown,
构建流程轻快又轻松。
配置新旧交替转,
源码依旧稳如松。
兔子拍手跳一跳,
新工具上线乐无穷!
"""


📜 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 19107e30a5e6d1dfc8608cb4c2047bad5a64b535 and 2282a811e24ebb61c023bda10f0d993c39a54a41.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/taro-runtime/package.json (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • packages/taro-runtime/package.json
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • 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 WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Testing on Rust

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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[bot] avatar May 19 '25 18:05 coderabbitai[bot]

  1. 混合了其他修改;
  2. tsdown 会不会不够热门?
  3. 改动略大,有没有更保守一点的方案?

yoyo837 avatar May 20 '25 01:05 yoyo837

  1. 混合了其他修改;
  2. tsdown 会不会不够热门?
  3. 改动略大,有没有更保守一点的方案?
  1. 我可以另提PR
  2. tsdown属于尤雨溪的rolldown项目,而rolldown即将代替rollup成为vite的默认打包工具,所以无论从代码质量还是流行程度我认为都不是问题
  3. 我需要明确到底啥能改啥不能改,还请解答一下这里的问题 https://github.com/NervJS/taro/pull/17714#issuecomment-2888258157

ianzone avatar May 20 '25 03:05 ianzone

  1. 混合了其他修改;
  2. tsdown 会不会不够热门?
  3. 改动略大,有没有更保守一点的方案?

第一项帮忙合一下? https://github.com/NervJS/taro/pull/17753

ianzone avatar May 22 '25 07:05 ianzone

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 59.37%. Comparing base (5d19bfa) to head (ff6e8aa). Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #17746    +/-   ##
========================================
  Coverage   59.37%   59.37%            
========================================
  Files         387      387            
  Lines       23417    23417            
  Branches     5141     5145     +4     
========================================
  Hits        13903    13903            
- Misses       8020     8153   +133     
+ Partials     1494     1361   -133     
Flag Coverage Δ
taro-cli 72.37% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

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

see 40 files with indirect coverage changes

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

codecov[bot] avatar May 22 '25 15:05 codecov[bot]

这个合了应该就可以支持node22了

ianzone avatar May 22 '25 16:05 ianzone

@yoyo837 还有啥要改的吗

ianzone avatar May 23 '25 08:05 ianzone

image

能保持原来的结构吗?不要文件hash,作为 lib,dist下的文件应该尽量保持名称不变。

yoyo837 avatar May 23 '25 12:05 yoyo837

@yoyo837 这样如何? image

ianzone avatar May 23 '25 12:05 ianzone

@yoyo837 这样更符合 image

ianzone avatar May 23 '25 13:05 ianzone

image 能保持原来的结构吗?不要文件hash,作为 lib,dist下的文件应该尽量保持名称不变。

已更新

ianzone avatar May 23 '25 14:05 ianzone

image image

差异太大,应保持相同输出,js 里面的 export 也完全不一样了

yoyo837 avatar May 25 '25 12:05 yoyo837

image image 差异太大,应保持相同输出,js 里面的 export 也完全不一样了

cjs输出是否有必要?package.json中并未导出cjs。另外这是个什么软件,我也下一个

ianzone avatar May 25 '25 13:05 ianzone

cjs输出是否有必要?package.json中并未导出cjs package.json没有到处也可以全路径require吧?

我还是倾向于尽量兼容现状,避免一些意外来回 revert 和 fix.

yoyo837 avatar May 25 '25 13:05 yoyo837

另外这是个什么软件,我也下一个

Beyond compare

yoyo837 avatar May 25 '25 13:05 yoyo837

@yoyo837

  1. cjs 已输出
  2. 无导出的 ts 不会产生 d.ts
  3. 由于无法将 @taro/shared中的const enum Shortcuts 内联为字面量,导致下游包无法访问@taro-runtime中的 Shortcuts.Childnodes,故构建时会打包 @taro/shared

ianzone avatar May 25 '25 20:05 ianzone

image

taro-runtime 下有导出名字变了

yoyo837 avatar May 26 '25 03:05 yoyo837

image taro-runtime 下有导出名字变了

已跟踪。 另外这个名字会在 index 中被改回来,所以总的 API 是不变的,除非单独 import 这个文件。

ianzone avatar May 26 '25 03:05 ianzone

已跟踪。 另外这个名字会在 index 中被改回来,所以总的 API 是不变的,除非单独 import 这个文件。

有单独import的情况的

yoyo837 avatar May 26 '25 03:05 yoyo837

已跟踪。 另外这个名字会在 index 中被改回来,所以总的 API 是不变的,除非单独 import 这个文件。

有单独import的情况的

那就等上游更新吧

ianzone avatar May 26 '25 03:05 ianzone

合这个 https://github.com/NervJS/taro/pull/17848

ianzone avatar Jun 22 '25 23:06 ianzone