-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
Caution Review failedThe pull request is closed. Walkthrough此拉取请求对多个文件进行了修改,主要集中在 Changes
Possibly related PRs
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 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
📒 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
: 禁用 UMDstring
: 简单的 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 导出配置能够正确地传递到运行时模板。
Codecov ReportAttention: Patch coverage is
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. |
create a issue to trace the config like maybe it's better to handle this case in code generate other than template string |
see https://webpack.js.org/configuration/output/#outputlibraryexport
Summary by CodeRabbit
新特性
umd
配置类型,支持更复杂的结构。umd_export
字段到AppRuntimeTemplate
结构体。createRuntime
函数以支持基于umd_export
的条件导出。文档
umd
类型的详细说明和示例。测试