-
Notifications
You must be signed in to change notification settings - Fork 108
refactor: napi threadsafe function #1608
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
Conversation
Walkthrough本次更改涉及对多个文件的更新,主要集中在 Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1608 +/- ##
=======================================
Coverage 61.93% 61.93%
=======================================
Files 128 128
Lines 15405 15405
=======================================
Hits 9541 9541
Misses 5864 5864 ☔ View full report in Codecov by Sentry. |
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: 5
Outside diff range and nitpick comments (7)
crates/binding/src/js_plugin.rs (4)
20-23:build_start方法的简化实现是一个很好的改进。新的实现直接调用钩子函数,消除了之前使用通道的复杂性。这种方法更加简洁和直接。
建议:考虑添加一个简短的注释来解释为什么传递一个空元组作为参数。这可能会帮助其他开发者更好地理解这个调用的目的。
考虑添加如下注释:
// 传递空元组作为参数,因为 build_start 钩子不需要任何特定的输入 hook.call(())?
Line range hint
27-45:load方法的重构显著提高了代码的可读性和直观性。新的实现直接调用钩子函数并处理其结果,这种方法更加简洁和高效。对不同内容类型的处理逻辑清晰,错误处理也有所改进。
建议:考虑使用
match语句来替代多个if let和return,这可能会使代码结构更加清晰。考虑如下重构:
fn load(&self, param: &PluginLoadParam, _context: &Arc<Context>) -> Result<Option<Content>> { match &self.hooks.load { Some(hook) => { match hook.call(param.file.path.to_string_lossy().to_string())? { Some(x) => match x.content_type.as_str() { "js" | "ts" => Ok(Some(Content::Js(JsContent { content: x.content, is_jsx: false, }))), "jsx" | "tsx" => Ok(Some(Content::Js(JsContent { content: x.content, is_jsx: true, }))), "css" => Ok(Some(Content::Css(x.content))), _ => Err(anyhow!("Unsupported content type: {}", x.content_type)), }, None => Ok(None), } }, None => Ok(None), } }这种结构可能更容易理解和维护。
52-55:generate_end方法的简化实现是一个很好的改进。新的实现直接调用钩子函数,消除了之前使用通道的复杂性。这种方法更加简洁和直接。
建议:考虑使用
?运算符来简化错误处理,这可能会使代码更加简洁。考虑如下重构:
fn generate_end(&self, param: &PluginGenerateEndParams, _context: &Arc<Context>) -> Result<()> { if let Some(hook) = &self.hooks.generate_end { hook.call(serde_json::to_value(param)?)?; } Ok(()) }这种写法可以减少一层嵌套,使代码更加扁平化。
59-64:before_write_fs方法的重构提高了代码的清晰度。新的实现直接调用钩子函数,消除了之前使用通道的复杂性。使用
WriteFile结构体来传递数据是一个很好的做法,它使得参数的结构更加清晰。建议:考虑将
WriteFile结构的创建提取到一个单独的语句中,这可能会提高代码的可读性。考虑如下重构:
fn before_write_fs(&self, path: &std::path::Path, content: &[u8]) -> Result<()> { if let Some(hook) = &self.hooks._on_generate_file { let write_file = WriteFile { path: path.to_string_lossy().to_string(), content: content.to_vec(), }; hook.call(write_file)?; } Ok(()) }这种结构可能更容易理解,特别是当
WriteFile结构变得更复杂时。packages/mako/binding.d.ts (2)
55-58: 新接口LoadResult看起来不错,但可以考虑进一步改进。新添加的
LoadResult接口很好地定义了加载结果的结构。然而,为了保持一致性,可以考虑将contentType的类型从string更改为更具体的类型,例如'css' | 'js' | string。这样可以与JsHooks接口中load函数的返回类型保持一致,同时还允许其他类型的内容。建议修改如下:
export interface LoadResult { content: string; contentType: 'css' | 'js' | string; }
231-234: 新添加的WriteFile类看起来不错,但可以考虑进一步完善。
WriteFile类很好地封装了要写入的文件的路径和内容。使用Array<number>表示内容是处理二进制数据的好方法。然而,有几点建议可以使这个类更加健壮和易用:
- 考虑添加一个构造函数,以便在创建实例时初始化属性。
- 可以添加一些方法,如
getSize()来获取内容大小,或toBuffer()来将内容转换为 Buffer。- 为了提高类型安全性,可以使用
Uint8Array代替Array<number>。建议修改如下:
export class WriteFile { constructor(public path: string, public content: Uint8Array) {} getSize(): number { return this.content.length; } toBuffer(): Buffer { return Buffer.from(this.content); } }这些改进将使
WriteFile类更加功能完善和类型安全。packages/mako/binding.js (1)
Line range hint
1-311: 总体评估这次更改主要涉及新增
WriteFile方法的导出,这可能表明native binding中新增了文件写入相关的功能。虽然改动较小,但可能对项目的功能有重要影响。建议:
- 确保
WriteFile方法在native binding中已正确实现。- 更新相关文档,包括API参考和使用示例。
- 考虑添加集成测试,以验证
WriteFile方法在不同平台上的行为一致性。考虑以下建议:
- 评估
WriteFile方法对项目整体架构的影响,确保它符合项目的设计原则。- 如果
WriteFile涉及文件系统操作,请确保考虑了权限、安全性和错误处理等方面。- 考虑是否需要为
WriteFile方法添加日志记录或性能监控,以便于后续的维护和优化。
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
Files selected for processing (8)
- crates/binding/Cargo.toml (1 hunks)
- crates/binding/src/js_plugin.rs (3 hunks)
- crates/binding/src/lib.rs (2 hunks)
- crates/binding/src/threadsafe_function.rs (1 hunks)
- crates/binding/src/tsfn.rs (3 hunks)
- crates/mako/src/utils.rs (1 hunks)
- packages/mako/binding.d.ts (2 hunks)
- packages/mako/binding.js (1 hunks)
Additional comments not posted (21)
crates/binding/Cargo.toml (5)
14-14: napi-derive 依赖版本更新napi-derive 依赖已从 2.14.0 更新到 2.16.12。
请确保:
- 此版本与更新后的 napi crate 版本兼容。
- 检查项目中使用的所有 napi 相关的派生宏,确保它们在新版本中仍然有效。
建议查看 napi-derive crate 的更新日志,了解版本 2.14.0 到 2.16.12 之间的重要变更。
17-17: 新增 serde 依赖项目新增了 serde 依赖,使用工作空间配置。
Serde 是 Rust 的序列化和反序列化框架。请确保:
- 此依赖的引入是必要的,符合项目的数据处理需求。
- 检查项目中是否已经开始使用 serde,以及使用方式是否正确。
- 确认工作空间根目录的 Cargo.toml 中已正确定义了 serde 的版本。
#!/bin/bash # 检查项目中是否有使用 serde 的代码 rg --type rust 'serde::|#\[derive\(.*Serialize.*\)|#\[derive\(.*Deserialize.*\)'
15-15: 新增 oneshot 依赖项目新增了 oneshot 0.1.8 依赖。
oneshot crate 提供了一次性通道实现,通常用于线程间的单次通信。请确保:
- 此依赖的引入是有意为之,符合项目的并发模型或线程间通信策略的调整。
- 检查项目中是否已经开始使用 oneshot 通道,以及使用方式是否正确。
#!/bin/bash # 检查项目中是否有使用 oneshot 的代码 rg --type rust 'oneshot::'
16-16: rayon 依赖版本更新rayon 依赖已从 1.7.0 更新到 1.10.0。
Rayon 是 Rust 的数据并行处理库,此重大版本更新可能引入了性能改进或新功能。请确保:
- 检查项目中使用 rayon 的代码,确保与新版本兼容。
- 考虑利用新版本可能带来的性能改进或新特性。
建议查看 rayon crate 的更新日志,了解版本 1.7.0 到 1.10.0 之间的重要变更。
#!/bin/bash # 检查项目中使用 rayon 的代码 rg --type rust 'rayon::'
13-13: napi 依赖版本和特性更新需要注意napi 依赖已从 2.14.0 更新到 2.16.11,并且特性列表有所变化:
- 添加了 "async" 特性,可能改进了异步操作支持
- 移除了 "napi5" 特性,可能影响与 Node.js v14 的兼容性
- 移除了 "tokio_rt" 特性,可能改变了运行时处理方式
请确保这些更改与项目的 Node.js 版本要求和异步处理策略相符。同时,建议查看 napi crate 的更新日志,了解版本 2.14.0 到 2.16.11 之间的重要变更。
Verification successful
napi 依赖的更新已确认无影响
napi 依赖已更新至 2.16.11,移除的特性 "napi5" 和 "tokio_rt" 在项目中未被使用。
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 检查项目中是否有使用被移除的特性的代码 rg --type rust 'napi5|tokio_rt'Length of output: 6630
Script:
#!/bin/bash # 检查项目中是否有使用被移除的特性 `napi5` 或 `tokio_rt` rg --type rust 'napi5|tokio_rt'Length of output: 33
Script:
#!/bin/bash # 检查项目中是否有使用被移除的特性 `napi5` 或 `tokio_rt`,包括所有相关文件类型 rg -i -e 'napi5' -e 'tokio_rt' --glob '*.rs' --glob 'Cargo.toml' --glob '*.toml' --glob '*.md'Length of output: 90
crates/mako/src/utils.rs (1)
7-7: 请验证模块可见性更改的意图和影响。将
thread_pool模块的可见性从pub(crate)更改为pub意味着该模块现在可以从crate外部访问。这可能会带来以下影响:
- 增加了模块的暴露范围,可能会影响代码的封装性。
- 其他crate现在可以使用这个线程池功能,这可能是有意为之的改变。
- 这种更改可能会影响项目的整体架构设计。
请确保这个更改是有意为之的,并且与项目的设计原则相符。同时,考虑是否需要更新相关文档来反映这一变化。
运行以下脚本来验证
thread_pool模块的使用情况:Verification successful
确认
thread_pool模块的可见性更改根据检索结果,
thread_pool模块在多个其他 crate 中被使用。将其可见性从pub(crate)更改为pub是必要的,并且不会影响代码封装性。这一更改支持了内部 crate 之间的功能共享,符合项目的设计原则。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 描述:验证 thread_pool 模块的使用情况 # 测试:搜索 thread_pool 模块的使用。预期:可能会发现在其他 crate 中的新用法。 rg --type rust "use .*thread_pool" -g '!crates/mako/src/utils.rs'Length of output: 396
crates/binding/src/js_plugin.rs (2)
1-3: 导入更改看起来合理且与重构目标一致。新的导入反映了代码从使用
mpsc通道转向更直接的线程安全函数调用。这种变化简化了代码结构,可能提高了性能和可读性。
Arc的引入确保了线程安全的引用计数。LoadResult、TsFnHooks和WriteFile的导入表明我们现在使用这些结构来处理线程安全的函数调用。
Line range hint
1-64: 总体而言,这次重构显著提高了代码的可读性和简洁性。主要改进包括:
- 移除了
mpsc通道,简化了线程间通信。- 直接调用钩子函数,使得代码流程更加直观。
- 使用了新的数据结构(如
WriteFile),提高了参数传递的清晰度。这些变化与 PR 的目标一致,即为 NAPI 线程安全函数提供更简单、更简洁的包装器。代码现在更容易理解和维护,可能会提高开发效率和减少潜在的错误。
建议在合并这个 PR 之前,确保进行全面的测试,特别是在多线程环境下,以确保新的实现保持了原有的线程安全性和功能正确性。
packages/mako/binding.d.ts (1)
230-230:build函数声明的修改是正确的。添加
declare关键字是一个很好的改进。这明确表示该函数是在其他地方实现的,符合 TypeScript 定义文件的最佳实践。这个变更提高了类型定义的准确性和清晰度。crates/binding/src/lib.rs (2)
14-14: 新的导入语句看起来不错。这个新的导入语句引入了内部的线程池实现,这可能是为了替换之前使用的外部线程库。这个改变看起来是为了配合后续在
build函数中的修改。
229-229: 线程池实现的更改看起来合理。将
rayon::spawn替换为thread_pool::spawn与之前添加的导入语句相符。这个改变表明项目正在从 Rayon 库转向内部的线程池实现。建议:
- 确保新的
thread_pool::spawn函数与之前的rayon::spawn具有相似的行为和性能特征。- 考虑添加注释解释为什么要进行这个更改,以及新实现的任何特殊考虑。
请运行以下脚本来验证
thread_pool::spawn的使用情况:packages/mako/binding.js (1)
307-307: 新增 WriteFile 方法导出这些更改引入了一个新的
WriteFile方法导出。这与 PR 的目标一致,即重构 NAPI 线程安全函数。请运行以下脚本以验证
WriteFile方法在代码库中的使用情况:建议:
- 确保在相关文档中更新了
WriteFile方法的用法说明。- 考虑添加单元测试来验证
WriteFile方法的功能。Also applies to: 309-309
Verification successful
WriteFile 方法导出验证通过
根据脚本结果,
WriteFile方法已在packages/mako/binding.js中成功导出,并在类型声明文件binding.d.ts中进行了声明。目前在代码库中未发现其他模块引用或使用该方法。建议:
- 确保在相关文档中添加
WriteFile方法的使用说明。- 添加相应的单元测试以验证
WriteFile方法的功能。Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # 描述:验证 WriteFile 方法的使用情况 # 测试:搜索 WriteFile 方法的使用。预期:找到相关的使用或导入。 rg --type js --type ts 'WriteFile'Length of output: 218
crates/binding/src/threadsafe_function.rs (1)
66-67: 验证手动实现的Send和Sync是否安全在第 66-67 行,手动为
ThreadsafeFunction实现了Send和Sync。需要确保结构体中的所有字段在多线程环境下是安全的。特别地,napi_env和RawThreadsafeFunction是否满足线程安全要求,需要进行仔细验证。请运行以下脚本以检查
RawThreadsafeFunction和napi_env的线程安全性:crates/binding/src/tsfn.rs (8)
2-3: 新增依赖导入引入了
napi::NapiRaw和serde_json::Value,确保在后续代码中正确使用这些新导入的模块。
64-67: 更新 TsFnHooks 结构体字段类型
TsFnHooks结构体中的字段类型已更新为更简洁的泛型类型。请确保在代码的其他部分中,这些字段的使用方式已相应调整,避免类型不匹配或运行时错误。
79-81: 验证 build_start 的 unsafe 块使用在初始化
build_start时使用了unsafe块和from_napi_value方法。请确认此操作是安全的,符合 Rust 的内存安全原则,避免潜在的未定义行为。
83-87: 检查 generate_end 的 ThreadsafeFunction 创建在初始化
generate_end时,使用了泛型类型的ThreadsafeFunction。请确保Value类型在此上下文中适用,并验证unsafe块的正确性,以确保内存安全。
90-92: 验证 load 的 unsafe 块使用在创建
load的ThreadsafeFunction时,使用了unsafe块。请确认使用from_napi_value方法的安全性,并确保String和Option<LoadResult>类型的正确性。
94-96: 检查 _on_generate_file 的 ThreadsafeFunction 初始化在初始化
_on_generate_file时,使用了unsafe块和from_napi_value方法。请确保新结构体WriteFile与此处的泛型类型匹配,并验证内存安全性。
102-104: 新增 WriteFile 结构体添加了
WriteFile结构体,包含path: String和content: Vec<u8>字段。该结构体用于文件写操作,定义清晰,类型合适。
108-111: 更新 LoadResult 结构体以解决关键字冲突在
LoadResult结构体中添加了use_nullable = true属性,并为content_type字段添加了#[napi(js_name = "type")]注解。这解决了 Rust 中关键字type与 JavaScript 字段命名冲突的问题,确保在 JavaScript 侧可以正确访问。
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: 5
Outside diff range and nitpick comments (6)
Cargo.toml (3)
8-8: 考虑使用更灵活的版本约束对
mimalloc-rust的版本进行精确固定("=0.2.1")确保了构建的一致性,但可能会阻止自动更新到包含潜在改进或错误修复的新版本。建议考虑使用更灵活的版本约束,如 "^0.2.1",以允许兼容的小版本更新。
9-9: 检查oneshot是否有更新的版本添加
oneshot依赖对于实现单次使用的通道很有用。然而,指定的版本 0.1.8 相对较旧。建议检查是否有更新的稳定版本可用,以确保获得最新的功能和潜在的性能改进。
12-12: 考虑记录禁用默认特性的原因将
swc_core的版本固定为 "=0.83.22" 确保了构建的一致性,但可能会阻止自动更新到新版本。禁用默认特性允许更精细地控制所包含的功能,这可能是有意为之的。建议在代码注释或文档中说明禁用默认特性的原因,以便其他开发者理解这一决定。crates/binding/src/threadsafe_function.rs (2)
28-36: FromNapiValue 实现是个很好的添加,但可以改进错误处理新增的
FromNapiValue实现使得ThreadsafeFunction能够更容易地与 NAPI 系统集成,这是一个很好的改进。建议:
- 考虑在创建
ThreadsafeFunction时添加更多的错误检查。- 可以使用
?操作符来简化错误处理,例如:let tsfn = Tsfn::from_napi_value(env, napi_val)?; Ok(Self { tsfn, env, _phantom: PhantomData, })这样可以使代码更加简洁和健壮。
66-67: Sync 和 Send 特征实现是必要的,但需要文档说明为
ThreadsafeFunction<T, R>实现Sync和Send特征是正确的,这使得该结构可以在多线程环境中安全使用。然而,使用unsafe意味着实现者需要确保线程安全。建议:
- 添加注释解释为什么这些实现是安全的。
- 说明在哪些情况下可能会违反线程安全,以及用户应该如何正确使用这个结构来保证线程安全。
例如:
// SAFETY: ThreadsafeFunction is safe to share between threads because... unsafe impl<T: 'static, R> Sync for ThreadsafeFunction<T, R> {} // SAFETY: ThreadsafeFunction is safe to send to another thread because... unsafe impl<T: 'static, R> Send for ThreadsafeFunction<T, R> {}这样的文档可以帮助其他开发者理解和正确使用这个结构。
crates/binding/src/js_hook.rs (1)
15-55: 考虑将复杂的类型定义抽取为 TypeScript 类型别名在第15行至第55行,
generate_end的ts_type注解包含了复杂的类型定义。为了提高可读性和维护性,建议将该类型定义抽取为 TypeScript 类型别名,并在注解中引用。示例:
在 TypeScript 代码中定义类型别名:
type GenerateEndData = { isFirstCompile: boolean; time: number; stats: { // ...(保留原有定义) }; };然后在注解中使用该类型别名:
- #[napi(ts_type = r#"(data: { ... }) => void"#)] + #[napi(ts_type = "(data: GenerateEndData) => void")]
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
Files selected for processing (8)
- Cargo.toml (1 hunks)
- crates/binding/Cargo.toml (1 hunks)
- crates/binding/src/js_hook.rs (1 hunks)
- crates/binding/src/js_plugin.rs (3 hunks)
- crates/binding/src/lib.rs (2 hunks)
- crates/binding/src/threadsafe_function.rs (1 hunks)
- crates/mako/Cargo.toml (1 hunks)
- packages/mako/binding.d.ts (2 hunks)
Files skipped from review as they are similar to previous changes (3)
- crates/binding/src/js_plugin.rs
- crates/binding/src/lib.rs
- packages/mako/binding.d.ts
Additional comments not posted (12)
Cargo.toml (3)
6-6: 新增依赖项anyhow看起来不错。添加
anyhow依赖是一个很好的选择。这个库提供了灵活的错误处理机制,可以简化错误管理并提高代码可读性。版本 1.0.71 是一个相对较新的稳定版本。
10-10:serde依赖更新看起来很好将
serde更新到版本 1.0.171 并启用 "derive" 特性是一个很好的改进。这确保了项目使用最新的稳定版本,同时 "derive" 特性的启用简化了序列化和反序列化的实现。
6-12: 总体依赖更新看起来不错,有一些小建议整体而言,
Cargo.toml文件的更新是积极的。新增的anyhow和oneshot依赖项增强了项目的错误处理和通信能力。serde的更新保持了项目的最新状态。对于mimalloc-rust和swc_core,建议考虑使用更灵活的版本约束,并记录特定配置选择的原因。这些小改进可以进一步提高项目的可维护性和透明度。crates/binding/Cargo.toml (5)
10-10: 依赖项更改看起来不错!将
anyhow依赖项更改为使用工作空间配置是一个很好的做法。这有助于在整个项目中保持一致的版本,简化了依赖管理。
15-15: 新增依赖项 oneshot 看起来合理添加
oneshot依赖项并使用工作空间配置是个好主意。这个 crate 通常用于异步上下文中的一次性通道通信,可能与napi的新 "async" 特性有关。不过,为了更好地理解这个变更:
- 能否提供一些关于
oneshot在项目中预期用途的更多信息?- 这是否与
napi特性的变更有直接关联?
16-16: 新增 serde 依赖项是个好主意添加
serde依赖项并使用工作空间配置是不错的选择。虽然serde_json已经间接引入了serde,但直接添加serde可能意味着项目将更广泛地使用其功能。为了更好地理解这个变更:
- 能否解释一下直接添加
serde的具体原因?- 项目是否计划使用
serde的一些特定功能,而这些功能不能通过serde_json获得?
10-17: 请解释移除 rayon 依赖的原因和影响注意到
rayon依赖项已被移除。考虑到rayon通常用于 Rust 中的并行计算,这个变更可能表明项目处理并行性的方法发生了变化。请提供以下信息:
- 移除
rayon的具体原因是什么?- 这是否与添加
napi的 "async" 特性有关?- 之前依赖
rayon的功能现在是如何实现的?- 这个变更会对项目的性能产生什么影响?
可以运行以下脚本来检查项目中是否仍在使用 rayon:
#!/bin/bash # 描述:检查是否仍在使用 rayon # 测试:搜索 rayon 的使用。预期:没有匹配项或很少匹配项。 echo "Searching for rayon usage:" rg --type rust 'rayon'
13-14: 依赖项版本更新良好,但需要验证功能变更
napi和napi-derive的版本更新是好的,可以获得最新的安全修复和功能改进。然而,napi的功能特性发生了变化:
- 移除了 "napi5" 和 "tokio_rt" 特性
- 添加了 "async" 特性
请确认这些更改不会对项目的功能产生负面影响。特别是,验证移除 "tokio_rt" 特性是否会影响项目中的异步操作。
可以运行以下脚本来检查项目中是否仍在使用已移除的特性:
crates/binding/src/threadsafe_function.rs (4)
3-11: 导入声明看起来很合理新增的导入项目对于实现新版本的
ThreadsafeFunction是必要的。使用anyhow::Result表明改进了错误处理机制,这是一个很好的做法。
12-15: 结构定义的改进很好,但需要澄清错误策略新的泛型结构
ThreadsafeFunction<P, R>提高了灵活性,这是一个很好的改进。然而,使用ErrorStrategy::Fatal可能需要进一步解释。请考虑添加注释说明为什么选择
Fatal错误策略,或者考虑是否可以使用更温和的错误处理方式。
18-25: Clone 实现的简化是个很好的改进新的
Clone实现更加简洁明了,直接利用了Tsfn的Clone实现。这种方式减少了代码复杂性,提高了可维护性。
1-67: 总体评价:重构改进显著,但仍有优化空间这次对
ThreadsafeFunction的重构带来了显著的改进:
- 新的泛型结构提高了灵活性。
call方法现在能够处理同步和异步返回。- 与 NAPI 系统的集成更加简便。
主要改进建议:
- 增强错误处理,避免过度使用
unwrap()和expect()。- 为
unsafe实现添加详细的安全性文档。- 考虑解释或重新评估使用
ErrorStrategy::Fatal的决定。总的来说,这是一个很好的重构,通过实施上述建议,可以进一步提高代码的健壮性和可维护性。
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 (1)
crates/binding/src/threadsafe_function.rs (1)
28-37: FromNapiValue 实现的改进建议
FromNapiValue的实现对于与 N-API 进行互操作是必要的,实现方式总体上是正确的。然而,有一个小的改进建议:impl<P: 'static + JsValuesTupleIntoVec, R> FromNapiValue for ThreadsafeFunction<P, R> { unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> napi::Result<Self> { let tsfn = Tsfn::from_napi_value(env, napi_val)?; Ok(Self { tsfn, env, _phantom: PhantomData, }) } }建议在创建
Self之前,使用map_err来提供更具体的错误信息。这样可以在出错时提供更有用的上下文信息。
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- crates/binding/src/threadsafe_function.rs (1 hunks)
Additional comments not posted (3)
crates/binding/src/threadsafe_function.rs (3)
3-11: 导入声明的改进这些新的导入声明显示了代码在错误处理和异步操作支持方面的改进。使用
anyhow进行错误处理是一个很好的实践,它提供了更灵活和表达性强的错误处理机制。同时,引入spawn和Promise表明代码现在能够更好地处理异步操作。
12-15: ThreadsafeFunction 结构体的改进新的
ThreadsafeFunction结构体定义有以下几个显著的改进:
- 泛型实现(
<P: 'static, R>)提高了代码的灵活性和复用性。- 使用
napicrate 中的Tsfn简化了实现,有助于代码维护。PhantomData<R>的使用正确处理了未使用的类型参数R,避免了编译器警告。这些改变使得
ThreadsafeFunction更加通用和强大,能够适应更多的使用场景。
18-25: Clone 实现的简化
ThreadsafeFunction的Clone实现非常简洁和高效。它正确地克隆了tsfn字段,并复制了env值。这种实现依赖于底层Tsfn类型的Clone实现,这是一个很好的做法,因为它避免了不必要的复杂性,并确保了一致的行为。
* fix: env_replacer should not replace user defined variable in scope (#1577) * fix: env_replacer should not replace user defined variable in scope * test: add test cases for env_replacer * chore: code style * release: @umijs/mako@0.8.11 * chore: bundler-mako@0.8.11 * docs: add changelog for v0.8.11 * fix(tree-shaking): detect export var side effects (#1579) * test: ✅ add a failure test * fix: 🐛 add is pure detection in export var decl * fix: bad output when chunk_loading_global containing quotation mark (#1582) * chore: ➕ add a subdot cli tool script (#1585) * fix(win): copy don't work under windows (#1587) * fix(win): module id should be win_pathed (#1588) * feat(tree-shaking): optimize import namespace used all exports to partial used of source modules (#1584) * test: ✅ add failure test case * feat: ✨ add collect prop explicit field * feat: ✨ collect explicit member prop access to optizmize used export in dep module replace USE ALL export to partial used exports * fix: dedestructuring before collect ExplicitProps * test: ✅ add back trace env var * test: ✅ update test case * fix: 🐛 add globals and helpers --------- Co-authored-by: Jinbao1001 <nodewebli@gmail.com> * fix: merge mako config (#1578) * fix: merge mako config * fix: merge mako config * fix:clear deps should not panic when module not found (#1581) * fix:clear deps should not panic when module not found * chore: use tracing warn * fix: delete log * Revert "fix: merge mako config (#1578)" (#1589) This reverts commit c08821d. * fix: watch too many file error (#1550) * fix: watch too many file error * chore: delete print * chore: delete log * release: @umijs/mako@0.8.8-rc.1 * fix: conflict * feat: support numeric module Id (#1561) * feat: moduleIdStrategy support numberous * fix: typos * fix: typos * fix: change name * fix: typos * release: @umijs/mako@0.8.12 * chore: fix typo and doc (#1591) * fix: chunk_loading_global (#1590) * fix: bad entry output when chunk_loading_global containing singe quote * test: add test cases for chunk_loading_global * docs: update * chore: update lock * chore: remove useless dependencies (#1595) * refactor: 🔥 rm ci warn logs (#1596) * fix: devServer put static serve proxy after umi proxy middleware (#1558) * fix: fix umi load html file failed, * test: add umi devServer test case * fix: typo * fix: hmr on hyper-static-file error * fix: import expect.mjs error on github workflow. * fix: import expect.mjs error on github workflow. * fix: 🐛 expect for error case * fix: 🐛 dev.hmr dont stop * fix: 🐛 add OKAM env * fix: 🐛 wait for mako server * fix: 🐛 kill by children process * test: ✅ add umi.css * refactor: 🎨 unify expect file * feat: export killMakoDevServer from test-hmr.mjs, make it public for all test case * test: ✅ unify expect file * chore: ➕ use express-http-proxy for static proxy * feat: ✨ better mako static proxy * test: ✅ support umi dev test with local mako * chore: ⬆️ update pnpm-lock * chore: 🎨 * fix: 🐛 ignore children process killed error --------- Co-authored-by: huanyu.why <huanyu.why@antgroup.com> Co-authored-by: pshu <pishu.spf@antfin.com> * fix(tree-shaking): object spread transform should go before deconstructing (#1598) * fix: 🐛 deconstructing needs object spread transform first * test: ✅ add guardian syntax * release: @umijs/mako@0.8.13-canary.20240918.1 * chore: bundler-mako@0.8.13-canary.20240918.1 * chore: 🎨 thread name after mako (#1601) * refactor: 🎨 rayon is not friendly to js users * chore: ✏️ rename tokio worker with mako * revert: import namespace optimize (#1606) * Revert "fix(tree-shaking): object spread transform should go before deconstructing (#1598)" This reverts commit 9434d99. * Revert "feat(tree-shaking): optimize import namespace used all exports to partial used of source modules (#1584)" This reverts commit 81a52f8. * chore: 🔧 update mako clean script * release: @umijs/mako@0.8.13 * chore: bundler-mako@0.8.13 * docs: change log 0923 (#1607) * docs: 📝 change log * docs: 📝 change log 0923 * chore: ✏️ * fix: 🐛 turn off express-http-proxy's keep alive (#1612) * fix: 🐛 turn off express-http-proxy's keep alive * refactor: 🔥 remove timeout config * release: @umijs/mako@0.8.14 * chore: bundler-mako@0.8.14 * refactor: napi threadsafe function (#1608) * refactor: napi threadsafe function * chore: update binding typings * refactor: code pieces * fix: catch napi tsfn promise rejection * chore: update binding typings * docs: 📝 change log 20240925 (#1613) * feat: disable webp to base64 (#1602) * feat: init * fix: context * fix: no use * fix: typos * fix: typos * fix: typos * fix: typos * fix(bundler-mako): experimental config should be merged deeply (#1617) * refactor: config codes organization (#1618) * refactor: config codes organization * fix: typos * refactor: config parse error * fix: clickToComponent don't work (#1620) * fix: duplicate_package_checker panic when no package.json is supplied (#1621) * fix: file_stem index out of bound (#1623) * feat: add resolve_id plugin hook (#1625) * feat: add resolve_id plugin hook * chore: update docs * feat: add external * release: @umijs/mako@0.8.15 * chore: bundler-mako@0.8.15 * docs: changelog for 0.8.15 * chore: update the release instruction (#1627) * refactor: code-splitting config (#1629) * feat: add loadInclude plugin hook (#1630) * feat: add { isEntry } for resolve_id plugin hook (#1631) * feat/upgrade swc (#1444) * 🚧 * 🚧 a basic working version * chore: 🚨 lint happy * refactor: 🎨 adjust to new swc * refactor: 🎨 remove deprecated methods * chore: 🚨 lint happy * feat: ✨ update swc emotion * chore: 🔧 remove useless profile in sub crate * chore: 🔧 add back emotion plugin * refactor: 🎨 add back merge source map * test: ✅ hot update js file served by hyper static, it use text/javascript * chore: 🔧 lock update * chore: 🔧 clean up swc core feature * refactor: 🎨 fix breaking change of ctxt of span * fix: 🐛 ctxt apply mark * refactor: 🎨 use DUMMY CTXT instead of SyntaxContext::empty() * chore: ⬆️ temperal use mdxjs from kdy branch * feat: ✨ re-enable mdxjs * feat: ✨ swc_core 0.100.1 * chore: 🙈 ignore fmt in fixtures * chore: 🚨 lint happy * chore: ⬆️ swc_common * chore: ✏️ typo * release: @umijs/mako@0.8.1-canary.20240812.1 * chore: bundler-mako@0.8.1-canary.20240812.1 * chore: ⬆️ swc_core 0.100.6 * release: @umijs/mako@0.8.1-canary.20240814.2 * chore: bundler-mako@0.8.1-canary.20240814.2 * chore: 🚨 lint happy * chore: 🔧 CI build bindings * chore: 🔧 fix build docker * refactor: 🔥 remove aarch64-unknown-linux-gnu * chore: 🔧 create tar * chore: 🙈 * release: @umijs/mako@0.8.3-canary.20240820.1 * chore: bundler-mako@0.8.3-canary.20240820.1 * chore: 🔧 wrong donwload param * chore: 🔧 upload download actions should be same version * chore: 🔧 try codecov in ci * refactor: 🔥 remove unnecessary target * refactor: 🎨 use swc comments * fix: 🐛 after upgrade to swc_core it should remove paren before minifiy * refactor: 🎨 move dummy ctxt defintion to ast mod * chore: 🚨 lint happy * release: @umijs/mako@0.8.8-canary.20240902.1 * chore: bundler-mako@0.8.8-canary.20240902.1 * release: @umijs/mako@0.8.8-canary.20240903.3 * chore: bundler-mako@0.8.8-canary.20240903.3 * refactor: 🎨 use VisitMut + Fold code style * chore: ⬆️ update pnpm-lock * chore: 🙈 * revert: ⏪ delete musl bindin * release: @umijs/mako@0.8.9-canary.20240909.1 * chore: bundler-mako@0.8.9-canary.20240909.1 * release: @umijs/mako@0.8.11-canary.20240910.1 * chore: bundler-mako@0.8.11-canary.20240910.1 * fix: 🐛 use chars() instead of bytes() * fix: 🐛 unescape html entity by html escape crate * release: @umijs/mako@0.8.14-canary.20240924.1 * chore: bundler-mako@0.8.14-canary.20240924.1 * release: @umijs/mako@0.8.15-canary.20240927.1 * chore: bundler-mako@0.8.15-canary.20240927.1 * fix: hash not stable (&revert import * as optimize) (#1610) * Revert "revert: import namespace optimize (#1606)" This reverts commit a485358. * fix: hash not stable * fix: deps sort not stable * fix: deps sort not stable * fix: deps sort not stable * fix: delete binding * fix: var name * chore: iter to into * fix: format * release: @umijs/mako@0.9.0 * chore: bundler-mako@0.9.0 * docs: 📝 changelog 0.9.0 * fix: duplicate_package_checker panic when package.json has no version field (#1634) * feat: magic comment chunk name (#1628) * refactor: code-splitting config * feat: support magic comment chunk name basically * fix: magic comment chunk name for webworker * refactor: use ImportOptions to represent option from magic comments * fix: dep replacer when magic comments chunk name existed * test: update test cases for magic comments chunk name * fix: dep replacer when dynamic import depencies is missing * chore: remove useless codes * refactor: code styles * docs: add todo for ChunkId * test: fix visitors::dynamic_import::tests::test_dynamic_import * test: fix test::hmr * fix: dep replacer when dynamic import css modules or moduleIdStrategy is hashed * chore: remove meaning less changes * test: enable magic comment chunk name in fixtures/umi * docs: add docs for magic comment chunk name * feat: support webpackIgnore and makoIgnore magic comment (#1636) * feat: support webpackIgnore and makoIgnore magic comment * chore: fmt * chore: rename magic_comment_chunk_name to magic_comment * chore: fix typo * feat: add transform plugin hook (#1637) * feat: add transform plugin hook * docs: add docs * chore: fmt * chore: perf * feat: add transformInclude plugin hook (#1639) * feat: add transformInclude plugin hook * chore: fmt * Fix: import namespace optimize panic with nested for of stmt (#1640) * test: ✅ add import namespace optimize panic test case * fix: 🐛 fix nested for of stmt panic * release: @umijs/mako@0.9.2-canary.20241016.1 * chore: bundler-mako@0.9.2-canary.20241016.1 * release: @umijs/mako@0.9.2 * chore: bundler-mako@0.9.2 * docs: 📝 changelog 0.9.2 * feat: add buildEnd plugin hook (#1644) * feat: add enforce plugin hook (#1646) * feat: add enforce plugin hook * chore: code style * chore: code style * chore: fix lint * chore: 🎨 add missing binding type * release: @umijs/mako@0.9.3-canary.20241016.1 * chore: bundler-mako@0.9.3-canary.20241016.1 * feat: add writeBundle plugin hook (#1650) * feat: add watch_changes plugin hook (#1651) * feat: add watch_changes plugin hook * chore: fix lint * chore: fix ts define * fix: mako on windows don't work (#1652) * fix: devtool sourcemap explosion in windows (#1653) * chore: remove dead code * fix: should not re-group when span changed (#1654) * fix: umd should be import as cjs (#1642) * fix: umd should be import as cjs * refactor: 🎨 just short circuit typeof define to prevent define takes effect * revert: ⏪ binding.d.ts --------- Co-authored-by: pshu <pishu.spf@antfin.com> * fix: 🐛 add process.env.SOCKET_SERVER define to prevent process polyfilll (#1655) * release: @umijs/mako@0.9.3-canary.20241023.1 * chore: bundler-mako@0.9.3-canary.20241023.1 * release: @umijs/mako@0.9.3 * chore: bundler-mako@0.9.3 * docs: changelog for 0.9.3 * fix: hmr with magic comment chunk name (#1663) * feat: enable magicComment features by default (#1667) * feat(bundler-mako): add moduleIdStrategy to supportMakoConfigKeys (#1664) * fix: async module in circular dependence (#1659) * test: ✅ add test async module in circular dependencies * refactor: 🎨 handle async polution by traversal * refactor: 🎨 use default over expect * feat: compatible codeSplitting config with umi (#1669) * feat: compatible codeSplitting config with umi * test: fix e2e code-splitting.granular * fix: umi codeSplitting: depPerChunk * Feat/benchmark workflows (#1671) * feat: benchmark-workflows * fix: 修改Github Secrets * release: @umijs/mako@0.9.4 * chore: bundler-mako@0.9.4 * docs: 📝 changelog 0.9.4 * chore: Optional parameters (#1679) * chore: Optional parameters * Update index.ts * fix: skip module should skip async module (#1662) * release: @umijs/mako@0.9.5 * chore: bundler-mako@0.9.5 * docs: update changelog * docs: update changelog * feat(ssu): handle dependence changing while watching (#1690) * refactor: 🎨 add after update aspect for rebuild cached modules * refactor: 🎨 add next_build aspect in build_my_modify * feat: ✨ 区分 ssu firstbuild 和 updating 两者状态 * fix: pnpm workspace watch too many files (#1684) * fix: ✅ ts annotated declare variable treat as top level variable (#1682) * test: ✅ add ts declare annotated variable as top level * refactor: 🎨 mv clean syntax context to visitors folder * fix: 🐛 strip ts/tsx first, then do normal transform * feat: move ensure runtime to entry (#1660) * feat: ✨ add ensure2 replace in dynamic replace * feat: ✨ ensure 2 runtime * feat: ✨ add experimental centralEnsure config * refactor: 🎨 add struct ReslvedReplaceInfo * feat: ✨ add central ensure plugin * refactor: 🎨 extract module ensure map * refactor: 🎨 add back chunk id in replace info * refactor: 🎨 fix case one source with different import type * refactor: 🎨 extract hmr runtime update code aspect * release: @umijs/mako@0.9.6-canary.20241107.1 * chore: bundler-mako@0.9.6-canary.20241107.1 * feat: keep unresolved nodejs require (#1689) * fix: regexpr for nodejs intenal modules igonre * feat: not replace unresolved nodejs require to __mako_require__ * fix: define util require should be __mako_require__ * feat: add expreriental.keep_unresolved_node_require * feat: add expreriental.ignore_non_literal_require * chore: 🔥 remove unused fn * release: @umijs/mako@0.9.6 * chore: bundler-mako@0.9.6 * docs: changelog for 0.9.6 * fix(SSU): 🐛 in case external not avaible to all entries (#1698) * fix(SSU): 🐛 in case external not avaible to all entries * refactor: 🎨 explict ignore the error * fix: devserver response header add cacheControl no-cache (#1692) * fix: add no-cache * feat: add cross origin * fix: resonse header add cors and no_cache for all branch (#1699) * fix: judge devServer instead of writeToDisk * fix: add branch header * refactor: 🎨 static file with 0 ages --------- Co-authored-by: pshu <pishu.spf@antfin.com> * release: @umijs/mako@0.9.7 * chore: bundler-mako@0.9.7 * docs: 📝 update changelog for 0.9.7 * chore: ✏️ remove some if (#1706) * fix: optimization.concatenateModules dts lost (#1708) * refactor: 🔥 enter ensure 使用 chunk sync dep 减少首屏 chunk 数量 (#1707) * fix: 🐛 typing of stats (#1712) * fix: 🐛 detect circular deps output file content (#1715) * chore: update @umijs/mako typings * feat: ensure esm imports exists when mode is production (#1709) * feat: ensure esm imports exists when mode is production * release: @umijs/mako@0.9.8 * chore: bundler-mako@0.9.8 * docs: update docs * fix: node ignores (#1716) * feat: supports publicPath: auto (#1717) * feat: auto resolve entry file extension (#1718) * feat: auto resolve entry file extension * fix: remove useless clone * Fix/context module source with first empty quasis (#1719) * test: ✅ add first empty quasis template string module source case * fix: 🐛 first emtpy quasis case * fix: inline css config deserialize (#1720) * fix: node ignore should support node: prefixed only built-in modules (#1721) * release: @umijs/mako@0.9.9 * docs: suggest using volta to manage node and pnpm's version * chore: bundler-mako@0.9.9 * docs: update CHANGELOG.md * feat: supports umd export (#1723) * feat: supports umd export * fix: umd config binding typing * fix: typos * fix: umd export * chore: update typings * fix: replace the "typeof __webpack_require__" content (#1688) * fix: replace the "typeof __webpack_require__" content * fix: add some other webpack string name * fix: 增加对typeof 表达式的处理 * fix: delete log * fix: rename --------- Co-authored-by: shikuan.sk <shikuan.sk@antgroup.com> * fix: umd config deserialization (#1726) * feat: support case sensitive (#1714) * feat: add CaseSensitivePlugin * FIX: update path check * fix: clippy error * fix: 调整判断 * fix: 修复目录读取 * fix: 修改参数名称 * fix: 调整测试方式添加e2e断言,并增加配置项只有mac系统下才需要开启相关配置 * fix: 删除过滤条件 * fix: 删除多余测试文件,增加更新内容 * fix: 删除多余log * fix: 测试执行 * fix: 添加测试系统 * fix: 调整顺序 * fix: 添加测试系统 * fix: 非mac环境断言 * fix: 引用遗漏 * fix: 断言 * fix: 删除默认 * fix: 默认配置 * fix: 测试覆盖 * Revert "fix: 测试覆盖" This reverts commit b0a2e66. --------- Co-authored-by: shikuan.sk <shikuan.sk@antgroup.com> * refactor: 🔥 remove unecessary transform (#1727) * feat: output filename (#1725) * refactor: 🎨 add file name template and chunk name in ChunkFile struct * feat: ✨ add config to output#filename * feat: ✨ render filename when output#filename configed * feat: ✨ calc hash in ast impl for entry * test: ✅ add test case * test: ✅ add ut * chore: 🔧 disable codecov error * refactor: 🎨 remove clone * fix: 🐛 hash when necessary * chore: 🔧 add codecov.yml * release: @umijs/mako@0.9.10-canary.20241218.1 * chore: ⬆️ update pnpm-lock * feat: native plugin init (#1691) * feat: init rust plugin * chore: delete print * Rename cargo.toml to Cargo.toml * chore: update * fix: type * fix: plugin options string * fix: cfg test * release: @umijs/mako@0.10.0 * chore: bundler-mako@0.10.0 * docs: 📝 changelog 2024.12.20 * chore: 🔧 for quick setup dep to debug (#1733) * fix: support optional chaining in environment variable (#1730) * fix: support optional chaining in environment variable * test(): add edge cases for optional chaining in env_replacer * refactor: 🎨 no need to resolve empty url in css (#1732) * refactor: 🎨 no need to resolve empty url in css * refactor: 🎨 add test case * feat: support unplugin context (#1728) * feat: support plugin context * fix: napi context * chore: revert changes * chore: improve * feat: add error * feat: warn and error support object * feat: support emit_file * ci: fix test * chore: improve * chore: update test * chore: format * chore: don't support add watch file * feat: load and transform adapter, and add unplugin-replace example * chore: test unplugin-icons * chore: update pnpm-lock.yaml * docs: improve --------- Co-authored-by: xusd320 <xusd320@gmail.com> * fix: legacy octal escape is not permitted in strict mode (#1736) * fix: legacy octal escape is not permitted in strict mode * fix: e2e inline css * release: @umijs/mako@0.11.0 * chore: bundler-mako@0.11.0 * fix: pnpm lock * docs: 📝 changelog 2024.12.26 * Revert "feat: support unplugin context (#1728)" (#1737) This reverts commit 3dd6d9d. * release: @umijs/mako@0.11.1 * chore: bundler-mako@0.11.1 * feat: support unplugin context (#1741) * feat: support plugin context * fix: napi context * chore: revert changes * chore: improve * feat: add error * feat: warn and error support object * feat: support emit_file * ci: fix test * chore: improve * chore: update test * chore: format * chore: don't support add watch file * feat: load and transform adapter, and add unplugin-replace example * chore: test unplugin-icons * chore: update pnpm-lock.yaml * docs: improve --------- Co-authored-by: xusd320 <xusd320@gmail.com> * fix: #1007 (#1738) support BinaryExpression Co-authored-by: shikuan.sk <shikuan.sk@antgroup.com> * fix: win path problem with context module and require context (#1742) * chore(mako): add debug notice for local builds (#1743) * fix: normalize Windows paths in ModuleId constructors (#1744) * fix: normalize Windows paths in Compiler output path handling (#1745) * fix: typos * release: @umijs/mako@0.11.2 * chore: bundler-mako@0.11.2 * docs: update CHANGELOG.md * feat(create-mako): refactor create-mako (#1751) * chore: add issue and pull request templates for better contribution guidelines (#1753) * fix: ensure parent directories are created when writing to disk in MemoryChunkFileCache (#1755) * chore: release @umijs/tools * release: @umijs/mako@0.11.3 * chore: update the release introduction * ci: fix ci (#1758) * chore: upgrade @umijs/tools and do github release and changelog generate and translation by script * docs: changelog for 0.11.3 * chore: add check-ecosystem-usages script (#1759) * fix: analyze don't work in safari (#1761) * fix(mako): cli delay exit (#1762) * dep: @umijs/tools@0.1.23 * fix: load wasm (#1705) * fix: 修复load .wasm文件对importObject的处理 * fix: 删除没必要的输出 * fix: 修改生成的成员表达式js代码 * fix: 变量重命名 * fix: 修复代码lint报错 * test: 补充wasm_runtime测试用例 * chore: 补充import js方式的示例 * chore: 修改import js示例wasm产物格式 * chore: wasmparser依赖包在配置文件的位置 * chore: 删除多余的.wasm load逻辑 --------- Co-authored-by: xusd320 <xusd320@gmail.com> * fix: chunk groups' order when building mpa (#1763) * feat(copy): support advanced copy configuration with custom target paths (#1711) * feat(copy): support advanced copy configuration with custom target paths - Add CopyConfig enum to support both basic and advanced copy modes - Basic mode: maintains backward compatibility with string[] format - Advanced mode: supports {from: string, to: string} format for custom paths - Update copy plugin to handle both configuration formats - Ensure target directories are created automatically Example config: { 'copy': [ 'public', // basic mode { 'from': 'assets', 'to': 'static' } // advanced mode ] } * fix(copy): prevent path traversal in copy plugin Add path canonicalization and validation to ensure target paths remain within the destination directory * chore: Update `copy` config type in Mako bundler - Updated the type of the `copy` property in the `BuildParams` interface to support both `string` and `{ from: string; to: string }`. - Ensured the `copy` configuration is properly validated to handle both types. * docs: Update `copy` config type in documentation - Updated the `copy` property type in the configuration documentation to reflect the change from `string[]` to `(string | { from: string; to: string })[]`. - Clarified that the `copy` configuration can now accept both strings and objects with `from` and `to` properties. * test(copy): add e2e tests for copy plugin from/to pattern - Update config.copy test fixtures to cover from/to pattern - Add assertions for copied files in new location - Adjust copy plugin path validation * fix(copy): improve path validation and cleanup for copy plugin - Add directory cleanup when path validation fails - Use canonicalized paths for more reliable path validation - Add concatenateModules option type to BuildParams * fix: ci (#1768) * release: @umijs/mako@0.11.4 * chore: bump version * docs: 📝 changelog 2025.02.12 * chore: update changelog 2025.02.12 * fix: plugin context gc (#1769) * fix: mako已经支持了scss 但是没有支持module.scss文件 (#1770) Co-authored-by: shikuan.sk <shikuan.sk@antgroup.com> * feat: add module federation plugin (#1764) * feat: support module federation * feat: mf exposes to remote entries * chore: code styles * feat: mf container entry impl * fix: mf container entry * fix: mf runtime initOptions * feat: add containter references * feat: impl mf remote * feat: improve mf exposes * fix: mf exposes runtime factory * fix: mf plugin execution order * chore: update mf demo * feat: generate mf manifest in rust * fix: remote stats.json * refactor: code styles * chore: add some FIXME * refactor: mf plugin mods files * refactor: mf plugin mods files * chore: remove dead code * --wip-- [skip ci] * fix: remote stats.json * fix: typos * chore: simpify mf runtime codes fmt * refactor: mf containter plugin * feat: mf shared workaround * feat: mf shared workaround * fix: runtime template and remove some useless codes * fix: mf dev server * fix: mf shared config * feat: supports chunk group exclude * feat: mf patch code splitting * feat: mf shared manifest * feat: add config hash for mf shared module * chore: update mako typings * chore: code styles * chore: fix typo * chore: code styles * perf: improve performance * chore: code styles * chore: rename types * feat: add options to disable mf manifest * feat: entry config should be defined as BTreeMap * fix: mf shared consume and supports eager config * fix: mf shared eager * fix: not generate chunk for mf remote module * fix: typos * feat: add entry filename supports * chore: remove meaning less changes * fix: entry filename and mf config * release: @umijs/mako@0.11.4-canary.20250206.0 * fix: ignore shared dep when it is been external * Revert "release: @umijs/mako@0.11.4-canary.20250206.0" This reverts commit d3105d9. * release: @umijs/mako@0.11.4-canary.20250207.0 * fix: skip serialize mf manifest remoteEntry if none * fix: mf manifest remoteEntry address * Revert "release: @umijs/mako@0.11.4-canary.20250207.0" This reverts commit 6179982. * fix: typo * fix: mako mf manifest publicPath * fix: mf manifest panic * fix: mf typings * test: add e2e test for mf * fix: typo * chore: update README * fix: update mf bingding typings * fix: typings * fix: should not generate mf remotes runtime when remotes is empty * chore: remote wrong comment * feat: add chunk matcher for mf * fix: mf binding typings * chore: remove debug print statements * docs: update moduleFederation configuration docs * fix: mf config docs * chore: update CONTRIBUTING.md * release: @umijs/mako@0.11.5 * chore: update CHANGELOG.md and versions * feat: support to disable camel2DashComponentName of transformImport (#1773) * feat: support to disable camel2DashComponentName of transformImport * fix: typings * fix: 修复sass/less-loader的路径解析 (#1771) * fix: 支持webpack中sass-loader的路径解析 * chore: 调整目录 * chore: 移除注释等 * chore: 引入loader-runner * chore: sass-loader * chore: 修改loader返回空值处理 * test: 设置loader resolver的别名 * chore: update lock * fix: loader options * refactor: 提取插件代码 * fix: getResolve * fix: 修复runLoaders中的错误处理逻辑 * release: @umijs/mako@0.11.6 * fix: pnpm-lock * chore: update changelog for v0.11.6 * chore: update changelog for v0.11.6 * chore: update changelog for v0.11.6 * fix: watch less and sass dependencies (#1779) * chore: stash * chore: stash * feat: LessModuleGraph * feat: less-import-plugin * chore: 删除多余代码 * fix: 兼容url() * chore: plugin * feat: add beforeRebuild hook * ci: clippy format * fix: paths去重 * fix: rename _path * chore: rust层增加临时过滤文件方式 * chore: 提取createParallelLoader * refactor: before_rebuild hook (#1785) * refactor: before_rebuild hook -n * fix: typos * feat: postcss-loader (#1787) * feat: 支持postcss-loader * chore: 合并postcss到options传给render * chore: 更新.gitignore以排除less.postcss的node_modules目录 * feat: 添加PostCSS插件支持并更新相关类型定义 * refactor: 简化Less和Sass插件中的选项传递 * docs: 添加postcss支持的配置说明 * feat: 添加对PostCSS的支持,更新相关插件以集成postLoaders * feat: 更新Less和Sass插件以移除postLoaders,增强PostCSS支持 * test: 补充postcss测试用例 * fix: use transpiled hmr runtime (#1813) * fix: use transpiled hmr runtime (#1814) * release: @umijs/mako@0.11.7 * fix: package-lock.json * fix: use transpiled hmr runtime entry (#1815) * fix: disable parallel sassLoader because sassOptions.function cann't be shared cross workers (#1816) * release: @umijs/mako@0.11.8 * fix: package-lock.json * fix: package-lock.json * fix: typos * chore: update changelog for v0.11.8 * fix: less,sass,postcss loader panic (#1818) * release: @umijs/mako@0.11.9 * fix: package-lock.json * chore: update changelog for v0.11.9 * fix: worker threads panic on linux (#1823) * release: @umijs/mako@0.11.10 * fix: package-lock.json * chore: update changelog for v0.11.10 * fix: dev支持inline-source-map (#1859) Co-authored-by: dongqing.mdq <dongqing.mdq@antgroup.com> * release: @umijs/mako@0.11.11 * fix: package-lock.json * chore: update changelog for v0.11.11 * Update PULL_REQUEST_TEMPLATE.md * Update PULL_REQUEST_TEMPLATE.md * fix: less resolve alias (#1906) * docs: update README.md (#1907) * Update README.md * Apply suggestions from code review Co-authored-by: Peach <scdzwyxst@gmail.com> * Update README.md * Update README.md --------- Co-authored-by: Peach <scdzwyxst@gmail.com> * Update README.md * Update README.md * release: @umijs/mako@0.11.12 * feat: update pnpm log * chore: update changelog for v0.11.12 * fix: panic on docker linux (#1909) * doc: add openomy (#1910) * release: @umijs/mako@0.11.13 * chore: update changelog for v0.11.13 * chore: remove codecov * chore: update examples/multiple-entries-heavy * feat: support inline-source-map devtool option (#1965) Co-authored-by: hanzebang.hzb <hanzebang.hzb@antgroup.com> * chore: truncate old codes --------- Co-authored-by: pshu <pishu.spf@antfin.com> Co-authored-by: chencheng (云谦) <sorrycc@gmail.com> Co-authored-by: Jinbao1001 <nodewebli@gmail.com> Co-authored-by: money <hualigushi@163.com> Co-authored-by: eisonhower <why490078184@gmail.com> Co-authored-by: huanyu.why <huanyu.why@antgroup.com> Co-authored-by: PeachScript <scdzwyxst@gmail.com> Co-authored-by: Wu-kung <1434246346@qq.com> Co-authored-by: 聪小陈 <xiaohuoni@users.noreply.github.com> Co-authored-by: akitaSummer <akitasummer@outlook.com> Co-authored-by: Shi Kuan <shikuan1992@gmail.com> Co-authored-by: shikuan.sk <shikuan.sk@antgroup.com> Co-authored-by: yezao <75713784+yezaoshu@users.noreply.github.com> Co-authored-by: 御风 <18012261618@126.com> Co-authored-by: bqxbqx <132878537+BQXBQX@users.noreply.github.com> Co-authored-by: miaodongqing <dongqing_miao@163.com> Co-authored-by: dongqing.mdq <dongqing.mdq@antgroup.com> Co-authored-by: kiner-tang(星河) <1127031143@qq.com> Co-authored-by: hanzebang <46307343+hanzebang@users.noreply.github.com> Co-authored-by: hanzebang.hzb <hanzebang.hzb@antgroup.com>
A simpler and more concise wrapper for napi threadsafe function.
Summary by CodeRabbit
LoadResult接口,包含content和type属性。WriteFile方法,允许用户写入文件。build函数的声明,增强了类型定义。JsPlugin的方法调用,简化了线程安全函数的处理。