Skip to content
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

feat: supports umd export #1723

Merged
merged 5 commits into from
Dec 16, 2024
Merged

feat: supports umd export #1723

merged 5 commits into from
Dec 16, 2024

Conversation

xusd320
Copy link
Contributor

@xusd320 xusd320 commented Dec 13, 2024

see https://webpack.js.org/configuration/output/#outputlibraryexport

Summary by CodeRabbit

  • 新特性

    • 更新了 umd 配置类型,支持更复杂的结构。
    • 新增 umd_export 字段到 AppRuntimeTemplate 结构体。
    • 引入新的 JSON 配置文件以定义 UMD 设置。
    • 修改了 createRuntime 函数以支持基于 umd_export 的条件导出。
  • 文档

    • 更新了配置文档,增加了对 umd 类型的详细说明和示例。
    • 扩展了中文配置文档,改善了对各种配置选项的描述。
  • 测试

    • 新增测试以验证 UMD 导出功能。

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

此拉取请求对多个文件进行了修改,主要集中在BuildParams结构体和Umd类型的更改上。BuildParams中的umd字段类型扩展为支持更复杂的结构。Umd类型从简单的字符串别名更改为包含name和可选export字段的结构体。此外,相关函数的参数类型也进行了相应的更新,以提高类型安全性和灵活性。文档和测试文件也进行了相应更新,以反映这些更改。

Changes

文件路径 更改摘要
crates/binding/src/lib.rs BuildParams中的umd字段类型从`false
crates/mako/src/config/output.rs get_default_chunk_loading_global函数的参数类型从Option<String>更改为Option<Umd>
crates/mako/src/config/umd.rs Umd结构体重新定义,包含name和可选的export字段,且更改了反序列化逻辑。
crates/mako/src/generate/chunk_pot/util.rs runtime_code函数中umd变量处理方式更改,新增umd_export变量。
crates/mako/src/generate/runtime.rs AppRuntimeTemplate结构体中新增umd_export: Vec<String>字段。
crates/mako/templates/app_runtime.stpl createRuntime函数的返回语句根据umd_export的存在与否进行条件修改,增强了错误处理机制。
docs/config.md 更新umd配置类型为`false
docs/config.zh-CN.md 更新umd配置类型为`false
e2e/fixtures/config.umd_export/expect.js 新增测试以验证UMD导出功能。
e2e/fixtures/config.umd_export/mako.config.json 新增UMD配置文件,定义模块的名称和导出项。
e2e/fixtures/config.umd_export/src/index.ts 新增默认导出对象,包含属性x
packages/mako/binding.d.ts BuildParams接口中的umd属性类型从`false

Possibly related PRs

Suggested reviewers

  • sorrycc
  • stormslowly
  • Jinbao1001

Poem

🐰 在兔子洞中我欢呼,
新的结构真是酷!
umd变得更灵活,
导出功能真不愁。
配置文档更清晰,
兔子跳跃乐无比! 🌟

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


📜 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 483d5d1 and 023ee39.

📒 Files selected for processing (4)
  • crates/mako/src/generate/chunk_pot/util.rs (1 hunks)
  • crates/mako/templates/app_runtime.stpl (1 hunks)
  • e2e/fixtures/config.umd_export/mako.config.json (1 hunks)
  • packages/mako/binding.d.ts (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

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. (Beta)
  • @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.

@xusd320 xusd320 requested review from sorrycc and PeachScript and removed request for sorrycc December 13, 2024 03:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
crates/mako/src/config/umd.rs (1)

10-30: 建议为 deserialize_umd 函数添加单元测试

为了确保 deserialize_umd 函数能够正确处理各种输入,建议添加单元测试来覆盖不同的场景,包括字符串类型、对象类型和错误处理。这有助于提高代码的可靠性和可维护性。

docs/config.zh-CN.md (1)

818-820: 建议补充 UMD 配置的使用示例

当前文档仅列出了类型定义,建议添加配置示例来说明新增的 export 选项的具体用法,以帮助用户更好地理解如何使用这个功能。

建议添加如下示例:

### umd

- 类型:`false | string | { name: string, export?: string[] }`
- 默认值:`false`

是否输出 umd 格式。

+例如:
+
+```ts
+{
+  // 简单配置
+  umd: "MyLibrary"
+}
+
+// 或者使用高级配置
+{
+  umd: {
+    name: "MyLibrary",
+    export: ["Component", "utils"]
+  }
+}
+```
docs/config.md (1)

823-825: 建议补充 UMD 配置的使用示例

当前文档仅列出了类型定义,建议添加配置示例来说明新增的 export 选项的具体用法,以帮助用户更好地理解如何使用这个功能。

建议添加如下示例:

### umd

- Type: `false | string | { name: string, export?: string [] }`
- Default: `false`

Whether to output umd format.

+e.g.
+
+```ts
+{
+  // Simple configuration
+  umd: "MyLibrary"
+}
+
+// Or use advanced configuration
+{
+  umd: {
+    name: "MyLibrary",
+    export: ["Component", "utils"]
+  }
+}
+```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68e946c and 07e1fa2.

📒 Files selected for processing (11)
  • crates/binding/src/lib.rs (1 hunks)
  • crates/mako/src/config/output.rs (2 hunks)
  • crates/mako/src/config/umd.rs (1 hunks)
  • crates/mako/src/generate/chunk_pot/util.rs (1 hunks)
  • crates/mako/src/generate/runtime.rs (1 hunks)
  • crates/mako/templates/app_runtime.stpl (1 hunks)
  • docs/config.md (1 hunks)
  • docs/config.zh-CN.md (1 hunks)
  • e2e/fixtures/config.umd_export/expect.js (1 hunks)
  • e2e/fixtures/config.umd_export/mako.config.json (1 hunks)
  • e2e/fixtures/config.umd_export/src/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • e2e/fixtures/config.umd_export/src/index.ts
  • e2e/fixtures/config.umd_export/mako.config.json
🔇 Additional comments (7)
crates/mako/templates/app_runtime.stpl (1)

399-399: 确保访问嵌套属性时的安全性

在导出 exports.<%= umd_export.join(".") %> 时,需要确保 exports 对象中存在指定的嵌套属性,否则可能会导致运行时错误。建议在访问嵌套属性前,添加检查或提供默认值,以防止未定义属性引发的异常。

crates/mako/src/generate/runtime.rs (1)

9-9: 新增字段 umd_export 以支持 UMD 导出

成功添加了 umd_export: Vec<String> 字段,增强了 AppRuntimeTemplate 的功能,使其能够处理 UMD 导出的配置。

crates/mako/src/config/output.rs (2)

8-8: 导入 Umd 类型以增强类型安全性

新增的 Umd 类型导入使代码更加类型安全,与配置结构保持一致。


53-57: 函数签名更新增强了类型安全性和可维护性

函数实现采用了更优雅的 map_or_else 方式处理 Option 类型,同时保持了向后兼容性。

crates/binding/src/lib.rs (1)

129-129: 扩展了 UMD 配置的类型定义

umd 字段的类型定义已更新,现在支持以下格式:

  • false: 禁用 UMD
  • string: 简单的 UMD 名称
  • { name: string, export?: string[] }: 带有可选导出项的复杂配置

这种灵活的类型定义更好地支持了不同的 UMD 使用场景。

crates/mako/src/generate/chunk_pot/util.rs (2)

98-103: 优化了 UMD 配置的处理逻辑

代码改进:

  • 使用 as_ref() 避免了不必要的克隆
  • 通过 map_or 优雅地处理默认值
  • 正确处理了新增的 export 字段

实现更加高效且类型安全。


111-111: 模板参数更新支持 UMD 导出配置

将 umd_export 添加到模板参数中,确保了 UMD 导出配置能够正确地传递到运行时模板。

e2e/fixtures/config.umd_export/expect.js Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 21.42857% with 22 lines in your changes missing coverage. Please review.

Project coverage is 54.83%. Comparing base (68e946c) to head (023ee39).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/config/umd.rs 0.00% 18 Missing ⚠️
crates/mako/src/generate/chunk_pot/util.rs 40.00% 3 Missing ⚠️
crates/mako/src/config/output.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1723      +/-   ##
==========================================
- Coverage   54.89%   54.83%   -0.06%     
==========================================
  Files         178      179       +1     
  Lines       17871    17896      +25     
==========================================
+ Hits         9811     9814       +3     
- Misses       8060     8082      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xusd320 xusd320 requested a review from stormslowly December 13, 2024 03:19
@stormslowly
Copy link
Member

create a issue to trace the config like export: ["a.b", "x's y"]

maybe it's better to handle this case in code generate other than template string

@xusd320 xusd320 merged commit af25d70 into master Dec 16, 2024
15 checks passed
@xusd320 xusd320 deleted the feat/umd-export branch December 16, 2024 07:29
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.

2 participants