-
Notifications
You must be signed in to change notification settings - Fork 108
feat: ensure esm imports exists when mode is production #1709
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
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (3)crates/mako/src/plugins/tree_shaking/shake/find_export_source.rs (3)
在测试模块中添加了对
将 AST 的构建方式修改为
在创建 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 (
|
WalkthroughThis pull request introduces a new feature that ensures ECMAScript Module (ESM) imports exist when the mode is set to production. It adds a Changes
|
| }); | ||
| }); | ||
| if should_panic { | ||
| panic!("dependency check error!"); |
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.
Using panic! for dependency check errors in production mode can cause the entire application to crash. Consider using a more graceful error handling mechanism, such as logging the error and continuing execution, or returning a Result with an error variant.
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: 7
🧹 Outside diff range and nitpick comments (18)
crates/mako/src/plugins/dependency_checker/collect_imports.rs (1)
1-8: 结构定义看起来不错,建议添加文档注释结构体的设计很合理,使用了恰当的生命周期标注和集合类型。不过建议为结构体和字段添加文档注释,以便更好地理解其用途。
+/// 收集模块中的导入声明和导出声明 pub struct CollectImports<'a> { + /// 存储导入源与其对应的导入说明符集合的映射关系 pub imports_specifiers_with_source: &'a mut HashMap<String, HashSet<String>>, }crates/mako/src/ast/utils.rs (1)
154-171: 建议优化模块系统检测逻辑函数实现基本正确,但有以下几点建议:
Script分支中的 ESM 检测逻辑与文件中已有的is_esm函数重复,建议复用该函数- 可以考虑为
Custom类型添加注释说明选择该类型的原因建议按如下方式重构:
pub fn get_module_system(ast: &ModuleAst) -> ModuleSystem { match ast { ModuleAst::Script(module) => { - let is_esm = module - .ast - .body - .iter() - .any(|s| matches!(s, ModuleItem::ModuleDecl(_))); - if is_esm { + if is_esm(&module.ast) { ModuleSystem::ESModule } else { ModuleSystem::CommonJS } } + // CSS 和空模块使用自定义模块系统处理 crate::module::ModuleAst::Css(_) => ModuleSystem::Custom, crate::module::ModuleAst::None => ModuleSystem::Custom, } }packages/mako/src/binding.d.ts (1)
8-8: 新增的生命周期钩子需要补充使用文档这些新增的钩子函数扩展了插件系统的能力:
enforce用于控制插件执行顺序writeBundle和buildEnd用于构建完成后的处理watchChanges用于文件变更监听transform和transformInclude用于内容转换建议:
- 为每个钩子添加 JSDoc 注释,说明其用途、执行时机和使用示例
- 在 README 中补充这些新钩子的使用文档
建议添加类似以下的 JSDoc 注释:
+ /** + * 控制插件的执行顺序 + * @example + * enforce: 'pre' // 前置执行 + * enforce: 'post' // 后置执行 + */ enforce?: string;Also applies to: 54-58, 61-61, 67-71
crates/mako/src/build.rs (2)
212-212: 建议增强错误模块的模块系统处理错误模块是合成模块,建议考虑以下改进:
- 为错误模块设置一个固定的模块系统类型,避免不必要的 AST 分析
- 添加错误处理,以防
get_module_system分析失败let info = ModuleInfo { file, - module_system: get_module_system(&ast), + module_system: ModuleSystem::CommonJS, // 错误模块使用固定的模块系统类型 ast, raw, ..Default::default() };
318-318: 建议完善模块系统检测的架构设计在主要的模块构建过程中,模块系统的检测至关重要。建议考虑以下架构改进:
- 添加模块系统检测的缓存机制,避免重复分析
- 考虑在 watch 模式下的增量更新策略
- 为不同的模块系统类型添加特定的构建优化
另外,建议在
ModuleInfo结构体中添加相关文档,说明模块系统检测的重要性和使用注意事项。crates/mako/src/module.rs (1)
36-41: 建议为枚举添加文档注释枚举定义清晰且合理。建议添加文档注释来说明每个变体的具体用途,特别是
Custom变体的使用场景。建议添加如下文档注释:
+/// 表示模块系统的类型 +/// - CommonJS: 使用 require/exports 的 CommonJS 模块 +/// - ESModule: 使用 import/export 的 ES 模块 +/// - Custom: 自定义模块系统实现 #[derive(Debug, Clone, PartialEq, Eq)] pub enum ModuleSystem { CommonJS, ESModule, Custom, }crates/mako/src/plugins/tree_shaking/module.rs (2)
Line range hint
281-297: 建议重构模块系统初始化逻辑建议将以下几点改进:
- 将 ESM 检测逻辑抽取为独立函数,提高代码可维护性
- 统一
unresolved_ctxt的设置逻辑,确保一致性处理+ fn is_esm_module(module: &SwcModule) -> bool { + module.body.iter().any(|s| matches!(s, ModuleItem::ModuleDecl(_))) + } let module_system = module_info.module_system.clone(); let stmt_graph = match &module_info.ast { crate::module::ModuleAst::Script(module) => { - let is_esm = module - .ast - .body - .iter() - .any(|s| matches!(s, ModuleItem::ModuleDecl(_))); + let is_esm = is_esm_module(&module.ast); if is_esm { unresolved_ctxt = unresolved_ctxt.apply_mark(module.unresolved_mark); StatementGraph::new(&module.ast, unresolved_ctxt) } else { StatementGraph::empty() } }
Line range hint
314-322: 建议添加模块系统相关的副作用处理文档当前代码根据模块系统类型(ESModule/CommonJS/Custom)来确定副作用和导出行为,建议添加注释说明以下几点:
- 为什么 ESModule 默认无副作用
- 各种模块系统下 AllExports 初始化的差异原因
- 副作用判断逻辑的设计考虑
side_effects: module_system != ModuleSystem::ESModule, side_effect_dep_sources: Default::default(), is_async: module.info.as_ref().unwrap().is_async, +// ESModule 默认无副作用,因为其具有静态导入导出特性 +// CommonJS 和 Custom 模块系统由于其动态特性,默认视为有副作用 all_exports: match module_system { ModuleSystem::ESModule => AllExports::Precise(Default::default()), ModuleSystem::Custom | ModuleSystem::CommonJS => { AllExports::Ambiguous(Default::default()) } },crates/mako/src/plugins/dependency_checker/collect_exports.rs (2)
57-57: 请完成ExportDefaultSpecifier的实现代码中存在
//@todo注释,表示尚未处理ExportDefaultSpecifier。为确保导出收集的完整性,请实现对该情况的处理。如果需要,我可以协助提供此部分的实现,您希望我为此创建一个新的 GitHub issue 吗?
31-35: 建议使用常量替代硬编码字符串在多处直接使用了
"default".to_string(),建议将"default"定义为常量,避免魔法字符串,增强代码可维护性。可以在代码顶部添加:
const DEFAULT_EXPORT: &str = "default";并修改相关代码为:
- self.specifiers.remove(&"default".to_string()); + self.specifiers.remove(&DEFAULT_EXPORT.to_string());crates/mako/src/plugins/dependency_checker.rs (3)
28-51: 完善匹配分支,处理所有可能的ModuleSystem类型在匹配
info.module_system时,只处理了ESModule、CommonJS和Custom三种类型。若未来增加新的模块系统类型,可能会导致未匹配的情况。建议添加默认分支,确保所有可能的枚举值都被处理。修改建议:
match info.module_system { ModuleSystem::ESModule => { // existing code } ModuleSystem::CommonJS | ModuleSystem::Custom => { specifiers.clear(); + } + _ => { + // 处理其他未匹配的模块系统类型 + specifiers.clear(); } }
67-70: 简化条件判断,提高代码可读性在第68至70行的条件判断中,嵌套了多个条件,可以通过使用守卫条件来简化,提高代码的可读性。
修改建议:
- if let Some(info) = &m.info { - if !info.file.is_under_node_modules - && matches!(info.module_system, ModuleSystem::ESModule) - { + if let Some(info) = &m.info + if !info.file.is_under_node_modules + && matches!(info.module_system, ModuleSystem::ESModule) { // 收集 imports
108-115: 避免多次赋值,直接返回结果在第108至115行,
should_panic被多次赋值为true,可以在确认有未定义的导入规范符时,直接返回错误或收集所有错误后统一处理,避免重复赋值。修改建议:
- .for_each(|(source, specifiers)| { - should_panic = true; + .filter(|(_, specifiers)| !specifiers.is_empty()) + .flat_map(|(source, specifiers)| specifiers.iter().map(move |specifier| (source, specifier))) + .for_each(|(source, specifier)| { + error!( + "'{}' is undefined: import from '{}' in '{}'", + specifier, source, module_id.id + ); }); - }); -}); -if should_panic { - return Err(anyhow::anyhow!("dependency check error!")); -};crates/mako/src/compiler.rs (1)
261-263: 建议在开发模式下也启用 DependencyChecker 插件依赖检查在开发阶段同样重要,可以及早发现潜在问题,避免问题延续到生产环境。建议在开发模式下也添加
DependencyChecker插件,或者提供配置选项供用户选择是否启用。crates/mako/src/plugins/tree_shaking/shake/module_concatenate.rs (1)
26-26: 确保移除不必要的导入以提高代码清晰度在第26行,您从
crate::plugins::tree_shaking::module中不再导入ModuleSystem:use crate::plugins::tree_shaking::module::{AllExports, TreeShakeModule};如果
ModuleSystem已被正确地从其他路径导入,移除冗余的导入有助于提高代码的可读性和维护性。crates/mako/src/plugins/tree_shaking/shake.rs (3)
Line range hint
238-240: 潜在的逻辑问题:collect_all_exports_of函数中的递归循环在
collect_all_exports_of函数中,先获取了tsm的引用,然后检查是否已访问过当前module_id。如果该模块已访问过,函数会返回,但在返回前并未释放tsm的引用,可能导致重复的不可变借用,造成运行时错误。建议在获取
tsm引用之前,先检查并更新visited集合,以避免潜在的借用冲突。fn collect_all_exports_of( module_id: &ModuleId, tree_shake_modules_map: &HashMap<ModuleId, RefCell<TreeShakeModule>>, module_graph: &ModuleGraph, all_exports: &mut AllExports, visited: &mut HashSet<ModuleId>, ) { + if visited.contains(module_id) { + return; + } + visited.insert(module_id.clone()); let tsm = tree_shake_modules_map.get(module_id).unwrap().borrow(); - - if visited.contains(module_id) { - return; - } - - visited.insert(module_id.clone());
Line range hint
245-250: 性能建议:减少对strip_context函数的重复调用在处理导出和导入的标识符时,多次调用了
strip_context函数,可能导致不必要的性能开销。建议缓存处理结果或优化调用方式,以提高代码效率。
Line range hint
360-368: 代码优化:简化strip_context函数的实现
strip_context函数当前使用了split和collect方法,可以通过使用split_once方法简化实现,使代码更简洁明了。pub fn strip_context(ident: &str) -> String { - let ident_split = ident.split('#').collect::<Vec<_>>(); - ident_split[0].to_string() + ident.split_once('#') + .map_or_else(|| ident.to_string(), |(first, _)| first.to_string()) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (12)
crates/mako/src/ast/utils.rs(2 hunks)crates/mako/src/build.rs(4 hunks)crates/mako/src/compiler.rs(2 hunks)crates/mako/src/module.rs(2 hunks)crates/mako/src/plugins.rs(1 hunks)crates/mako/src/plugins/dependency_checker.rs(1 hunks)crates/mako/src/plugins/dependency_checker/collect_exports.rs(1 hunks)crates/mako/src/plugins/dependency_checker/collect_imports.rs(1 hunks)crates/mako/src/plugins/tree_shaking/module.rs(3 hunks)crates/mako/src/plugins/tree_shaking/shake.rs(1 hunks)crates/mako/src/plugins/tree_shaking/shake/module_concatenate.rs(1 hunks)packages/mako/src/binding.d.ts(4 hunks)
🔇 Additional comments (13)
crates/mako/src/plugins.rs (2)
6-6: 新模块声明看起来没有问题!
新增的 dependency_checker 模块声明与其他插件模块保持一致的可见性和命名风格。
6-6: 建议验证新模块的实现
由于这是一个新增的依赖检查器模块,需要确保其实现符合预期功能。
运行以下脚本来检查新模块的实现:
✅ Verification successful
依赖检查器模块实现完整且功能明确
经过验证,dependency_checker 模块实现了以下功能:
- 正确实现了 Plugin trait,并在 after_build 钩子中执行依赖检查
- 完整处理了 ESM 模块系统的导入导出逻辑:
- 收集并验证所有 import 声明的有效性
- 检查导入的标识符是否在依赖模块中有对应的导出
- 对未定义的导入会给出明确的错误提示
模块的实现符合预期的依赖检查功能要求。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:验证 dependency_checker 模块的实现
# 检查模块文件是否存在
fd -t f "dependency_checker.rs" "crates/mako/src"
# 检查模块中是否实现了 Plugin trait
ast-grep --pattern 'impl Plugin for DependencyChecker'
# 检查是否包含 ESM 相关的导入检查逻辑
rg -A 5 "esm|import|export" "crates/mako/src/plugins/dependency_checker"
Length of output: 15229
crates/mako/src/ast/utils.rs (1)
7-7: 导入声明看起来没有问题!
新增的导入语句清晰地引入了所需的类型,并且与现有代码风格保持一致。
packages/mako/src/binding.d.ts (1)
168-168: 配置项需要补充说明文档
新增的 inlineExcludesExtensions 配置项:
- 需要补充说明其用途和配置示例
- 建议验证此配置项是否与 PR 目标(确保生产环境下的 ESM 导入)相关
crates/mako/src/build.rs (2)
16-16: 导入声明看起来没有问题!
新增的 get_module_system 导入与其他 AST 相关的导入保持一致,并且在整个文件中被合理使用。
187-187: 建议验证外部模块的模块系统检测
对于外部模块,正确识别其模块系统类型(CommonJS/ESM)非常重要,特别是在生产环境中。建议验证以下几点:
- 外部模块的 AST 解析是否正确
get_module_system是否能正确处理外部模块的特殊情况
✅ Verification successful
Let me gather more information about the module system detection implementation.
Based on the results, I can now provide a final response as we have found the implementation of get_module_system and its usage.
外部模块的模块系统检测已得到适当处理
get_module_system 函数实现了可靠的模块系统检测机制:
- 通过检查 AST 中是否存在
ModuleDecl节点来判断是否为 ESM - 该实现同时适用于外部模块和内部模块
- 在
create_external_module中正确集成了模块系统检测
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 搜索外部模块相关的测试用例
rg -l "create_external_module|external.*module" --type rust
# 检查 get_module_system 的实现细节
ast-grep --pattern 'fn get_module_system($_) {
$$$
}'
Length of output: 774
Script:
#!/bin/bash
# 搜索 get_module_system 函数的定义和使用
rg -A 10 "get_module_system" --type rust
# 查找外部模块相关的测试代码
rg -A 5 "create_external_module.*test" --type rust
# 检查是否有专门针对模块系统的测试
rg -l "module.*system.*test" --type rust
Length of output: 3344
crates/mako/src/module.rs (2)
208-208: 验证默认值对现有代码的影响
将 module_system 默认值设置为 CommonJS 可能会影响现有的模块处理逻辑。建议验证这个默认值是否与现有代码的期望行为一致。
运行以下脚本来验证潜在影响:
✅ Verification successful
Based on the search results, I can now generate the final response since I have enough context to verify the impact of setting ModuleSystem::CommonJS as the default value.
默认使用 CommonJS 模块系统是合理的选择
代码分析显示这个默认值设置是安全的,原因如下:
- 代码中已经完整处理了 CommonJS 和 ESM 两种模块系统的场景
- 模块系统类型会根据源文件内容自动检测(通过
is_esm函数),不依赖默认值 - 即使默认设为 CommonJS,ESM 模块的处理逻辑仍然会正确执行
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查可能受默认 CommonJS 设置影响的代码
# 搜索涉及模块系统判断的代码
rg "(?i)(esmodule|commonjs|cjs|esm)" -t rust
# 搜索模块初始化相关的代码
ast-grep --pattern 'ModuleInfo::default()'
Length of output: 22646
202-202: 验证 module_system 字段的使用情况
新增的 module_system 字段需要确保在整个代码库中得到正确使用。
运行以下脚本来验证字段的使用情况:
✅ Verification successful
Let me gather more information about the get_module_system function implementation to ensure it's properly handling the new field.
Let me check one more thing to see how the module system is being determined and used in the codebase.
module_system 字段的使用已得到完整验证
根据代码分析,module_system 字段在整个代码库中得到了正确且一致的使用:
- 在
ast::utils::get_module_system中正确判断模块类型 - 在依赖检查器(dependency_checker)中用于区分处理 ESM 和 CommonJS 模块
- 在 tree-shaking 相关代码中用于优化处理
- 默认值设置为
ModuleSystem::CommonJS
所有使用场景都符合预期,没有发现任何问题。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查 module_system 字段在代码库中的使用情况
# 搜索所有对 module_system 的引用
rg "module_system" -t rust
# 搜索可能需要更新的模块系统判断逻辑
ast-grep --pattern 'if $expr.is_esm() { $$$ }'
Length of output: 1632
Script:
#!/bin/bash
# 查看 get_module_system 函数的实现
ast-grep --pattern 'fn get_module_system($$$) { $$$ }'
# 检查 ModuleSystem 枚举的定义
rg "enum ModuleSystem" -A 5 -t rust
Length of output: 317
Script:
#!/bin/bash
# 搜索 ModuleSystem 的使用上下文
rg "ModuleSystem::" -B 2 -A 2 -t rust
# 查找可能的模块系统相关配置
rg "module.*system" -i -t rust
Length of output: 7699
crates/mako/src/compiler.rs (2)
18-18: 引入新的 Mode 枚举
成功引入了 Mode 枚举,为配置添加模式支持,便于根据不同模式进行条件处理。
261-263: 在生产模式下添加 DependencyChecker 插件
当 config.mode 为 Mode::Production 时,添加了 DependencyChecker 插件,以增强对依赖项的检查,确保生产环境的稳定性。
crates/mako/src/plugins/tree_shaking/shake/module_concatenate.rs (1)
24-24: 确认 ModuleSystem 导入路径的正确性
在第24行,您从 crate::module 导入了 ModuleSystem:
use crate::module::{Dependency, ImportType, ModuleId, ModuleSystem, ResolveType};同时,第26行移除了从 crate::plugins::tree_shaking::module 导入的 ModuleSystem。请确保在本文件中使用的 ModuleSystem 类型确实应从 crate::module 导入,以避免潜在的命名冲突或类型不匹配。
您可以运行以下脚本来检查 ModuleSystem 的定义及其在代码库中的使用情况:
✅ Verification successful
Based on the results, I can now generate the final response since I have clear evidence that ModuleSystem is correctly defined in crate::module and is being used consistently across the codebase.
导入路径验证已完成,无需更改
ModuleSystem 的导入路径是正确的。通过代码分析可以确认:
ModuleSystem枚举类型确实定义在crate::module模块中- 整个代码库中的其他文件也都是从
crate::module导入ModuleSystem - 移除
crate::plugins::tree_shaking::module的导入是正确的,因为该模块只是使用而非定义ModuleSystem
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查 `ModuleSystem` 的定义位置和引用情况
# 查找 `ModuleSystem` 的定义位置
rg -A 5 "enum ModuleSystem" crates/mako/src/
# 查找引用了 `ModuleSystem` 的文件
rg "ModuleSystem" crates/mako/src/ -g '!*/module.rs'
Length of output: 2579
crates/mako/src/plugins/tree_shaking/shake.rs (2)
18-18: 建议:全面处理新增的 ModuleSystem 类型
第18行新增了对 ModuleSystem 的引用。请确保在代码中所有涉及模块系统的逻辑都正确地处理了 ModuleSystem 的所有可能变体,避免遗漏对某些模块系统类型的处理,确保模块处理的完整性和正确性。
Line range hint 83-93: 可能的逻辑错误:greater_equal_than 函数的比较逻辑
在 greater_equal_than 函数中,当参数 b < 0 时,函数返回 true。但是在调用该函数的上下文中,可能需要仔细检查这种情况下返回 true 是否符合预期,以避免潜在的逻辑错误。
请验证函数的实现是否满足预期的逻辑需求,必要时进行调整。
| fn visit_import_decl(&mut self, node: &ImportDecl) { | ||
| let source = node.src.value.to_string(); | ||
| if self.imports_specifiers_with_source.get(&source).is_none() { | ||
| self.imports_specifiers_with_source | ||
| .insert(source.clone(), HashSet::new()); | ||
| } | ||
|
|
||
| node.specifiers | ||
| .iter() | ||
| .for_each(|specifier| match specifier { | ||
| ImportSpecifier::Named(named) => { | ||
| if let Some(ModuleExportName::Ident(ident)) = &named.imported { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert(ident.sym.to_string()); | ||
| } else { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert(named.local.sym.to_string()); | ||
| } | ||
| } | ||
| ImportSpecifier::Default(_) => { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert("default".into()); | ||
| } | ||
| _ => {} | ||
| }) | ||
| } |
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.
🛠️ Refactor suggestion
建议改进错误处理机制
当前实现中多次使用了 unwrap(),这在生产环境中可能不够安全。建议使用 expect() 提供更明确的错误信息,或者使用 unwrap_or_default() 来优雅处理错误情况。
- .unwrap()
+ .expect("Import source should exist in map")另外,建议添加对 ImportSpecifier::Namespace 的处理,以支持 import * as name 语法。
Committable suggestion skipped: line range outside the PR's diff.
| fn visit_named_export(&mut self, node: &NamedExport) { | ||
| let source = node.src.clone().unwrap().value; | ||
| if self | ||
| .imports_specifiers_with_source | ||
| .get(source.as_str()) | ||
| .is_none() | ||
| { | ||
| self.imports_specifiers_with_source | ||
| .insert(source.to_string(), HashSet::new()); | ||
| } | ||
|
|
||
| if node.src.is_some() { | ||
| node.specifiers.iter().for_each(|specifier| { | ||
| if let ExportSpecifier::Named(named) = specifier { | ||
| if let ModuleExportName::Ident(ident) = &named.orig { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(source.as_str()) | ||
| .unwrap() | ||
| .insert(ident.sym.to_string()); | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
存在潜在的运行时错误风险
在处理命名导出时存在以下问题:
- 第45行直接解包
node.src,但实际上导出声明的src可能为None - 第55行的检查与之前的解包操作矛盾
建议修改如下:
- let source = node.src.clone().unwrap().value;
- if self
- .imports_specifiers_with_source
- .get(source.as_str())
- .is_none()
- {
- self.imports_specifiers_with_source
- .insert(source.to_string(), HashSet::new());
- }
-
- if node.src.is_some() {
+ if let Some(src) = &node.src {
+ let source = src.value.to_string();
+ self.imports_specifiers_with_source
+ .entry(source.clone())
+ .or_default();
+
node.specifiers.iter().for_each(|specifier| {
if let ExportSpecifier::Named(named) = specifier {
if let ModuleExportName::Ident(ident) = &named.orig {
self.imports_specifiers_with_source
- .get_mut(source.as_str())
- .unwrap()
+ .get_mut(&source)
+ .expect("Source should exist in map")
.insert(ident.sym.to_string());
}
}
})
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fn visit_named_export(&mut self, node: &NamedExport) { | |
| let source = node.src.clone().unwrap().value; | |
| if self | |
| .imports_specifiers_with_source | |
| .get(source.as_str()) | |
| .is_none() | |
| { | |
| self.imports_specifiers_with_source | |
| .insert(source.to_string(), HashSet::new()); | |
| } | |
| if node.src.is_some() { | |
| node.specifiers.iter().for_each(|specifier| { | |
| if let ExportSpecifier::Named(named) = specifier { | |
| if let ModuleExportName::Ident(ident) = &named.orig { | |
| self.imports_specifiers_with_source | |
| .get_mut(source.as_str()) | |
| .unwrap() | |
| .insert(ident.sym.to_string()); | |
| } | |
| } | |
| }) | |
| } | |
| } | |
| fn visit_named_export(&mut self, node: &NamedExport) { | |
| if let Some(src) = &node.src { | |
| let source = src.value.to_string(); | |
| self.imports_specifiers_with_source | |
| .entry(source.clone()) | |
| .or_default(); | |
| node.specifiers.iter().for_each(|specifier| { | |
| if let ExportSpecifier::Named(named) = specifier { | |
| if let ModuleExportName::Ident(ident) = &named.orig { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .expect("Source should exist in map") | |
| .insert(ident.sym.to_string()); | |
| } | |
| } | |
| }) | |
| } | |
| } |
| export interface WatchChangesParams { | ||
| event: string; | ||
| } |
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.
接口类型定义存在不一致
发现以下问题:
WatchChangesParams中的event类型与watchChanges钩子中使用的字面量类型不匹配TransformResult中的type属性应该限制为'css' | 'js'以保持类型安全
建议修改如下:
export interface WatchChangesParams {
- event: string;
+ event: 'create' | 'delete' | 'update';
}
export interface TransformResult {
content: string;
- type: string;
+ type: 'css' | 'js';
}Also applies to: 91-94
| Decl::Var(box VarDecl { decls, .. }) => decls.iter().for_each(|decl| { | ||
| if let Pat::Ident(ident) = &decl.name { | ||
| self.specifiers.remove(&ident.sym.to_string()); | ||
| } | ||
| }), |
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.
必须处理其他变量声明模式以确保完整性
当前代码在处理变量声明时仅考虑了 Pat::Ident 模式,未处理解构赋值等其他模式。这可能导致某些导出变量未被正确移除,影响功能正确性。
建议修改代码以处理更多的变量模式,示例如下:
- if let Pat::Ident(ident) = &decl.name {
- self.specifiers.remove(&ident.sym.to_string());
- }
+ match &decl.name {
+ Pat::Ident(ident) => {
+ self.specifiers.remove(&ident.sym.to_string());
+ }
+ Pat::Array(array_pat) => {
+ // 处理数组解构模式
+ for element in &array_pat.elems {
+ if let Some(Pat::Ident(ident)) = element {
+ self.specifiers.remove(&ident.sym.to_string());
+ }
+ // 递归处理嵌套模式
+ }
+ }
+ Pat::Object(object_pat) => {
+ // 处理对象解构模式
+ for prop in &object_pat.props {
+ match prop {
+ ObjectPatProp::KeyValue(kv) => {
+ if let Pat::Ident(ident) = &kv.value {
+ self.specifiers.remove(&ident.sym.to_string());
+ }
+ }
+ ObjectPatProp::Assign(assign) => {
+ self.specifiers.remove(&assign.key.sym.to_string());
+ }
+ _ => {}
+ }
+ // 递归处理嵌套模式
+ }
+ }
+ _ => {}
+ }Committable suggestion skipped: line range outside the PR's diff.
| named.specifiers.iter().for_each(|specifier| { | ||
| match &specifier { | ||
| ExportSpecifier::Named(named) => { | ||
| if let Some(ModuleExportName::Ident(ident)) = &named.exported { | ||
| self.specifiers.remove(&ident.sym.to_string()); | ||
| } | ||
| } | ||
| ExportSpecifier::Namespace(name_spacing) => { | ||
| if let ModuleExportName::Ident(ident) = &name_spacing.name { | ||
| self.specifiers.remove(&ident.sym.to_string()); | ||
| } | ||
| } | ||
| _ => { | ||
| //@todo what is ExportDefaultSpecifier? | ||
| } | ||
| } | ||
| }) |
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.
需要处理 ExportDefaultSpecifier 以完整支持所有导出情况
当前匹配逻辑未处理 ExportSpecifier::Default,这可能导致默认导出未被正确识别和处理,可能遗漏相关的导出信息。
建议在匹配语句中添加对 ExportSpecifier::Default 的处理,例如:
match &specifier {
ExportSpecifier::Named(named) => {
// 原有处理逻辑
}
ExportSpecifier::Namespace(namespace) => {
// 原有处理逻辑
}
+ ExportSpecifier::Default(default_specifier) => {
+ self.specifiers.remove(&default_specifier.exported.sym.to_string());
+ }
_ => {}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| named.specifiers.iter().for_each(|specifier| { | |
| match &specifier { | |
| ExportSpecifier::Named(named) => { | |
| if let Some(ModuleExportName::Ident(ident)) = &named.exported { | |
| self.specifiers.remove(&ident.sym.to_string()); | |
| } | |
| } | |
| ExportSpecifier::Namespace(name_spacing) => { | |
| if let ModuleExportName::Ident(ident) = &name_spacing.name { | |
| self.specifiers.remove(&ident.sym.to_string()); | |
| } | |
| } | |
| _ => { | |
| //@todo what is ExportDefaultSpecifier? | |
| } | |
| } | |
| }) | |
| named.specifiers.iter().for_each(|specifier| { | |
| match &specifier { | |
| ExportSpecifier::Named(named) => { | |
| if let Some(ModuleExportName::Ident(ident)) = &named.exported { | |
| self.specifiers.remove(&ident.sym.to_string()); | |
| } | |
| } | |
| ExportSpecifier::Namespace(name_spacing) => { | |
| if let ModuleExportName::Ident(ident) = &name_spacing.name { | |
| self.specifiers.remove(&ident.sym.to_string()); | |
| } | |
| } | |
| ExportSpecifier::Default(default_specifier) => { | |
| self.specifiers.remove(&default_specifier.exported.sym.to_string()); | |
| } | |
| _ => {} | |
| } | |
| }) |
| specifiers: &mut HashSet<String>, | ||
| ) { | ||
| if !specifiers.is_empty() { | ||
| let dep_module = module_graph.get_module(module_id).unwrap(); |
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.
🛠️ Refactor suggestion
建议避免使用 unwrap(),采用安全的错误处理
在第26行,使用了 module_graph.get_module(module_id).unwrap(),若模块不存在,将导致程序发生 panic。为了提高代码的健壮性,建议匹配返回值,妥善处理 None 情况。
可以参考以下修改:
-let dep_module = module_graph.get_module(module_id).unwrap();
+let dep_module = match module_graph.get_module(module_id) {
+ Some(module) => module,
+ None => {
+ // 处理模块不存在的情况,例如记录错误日志或返回错误
+ return;
+ }
+};Committable suggestion skipped: line range outside the PR's diff.
| if should_panic { | ||
| panic!("dependency check error!"); | ||
| }; |
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.
🛠️ Refactor suggestion
避免使用 panic!,改为返回错误以提供更好的错误处理
在第118行,直接调用 panic! 会导致程序崩溃,不利于错误的追踪和处理。建议返回 Err,让调用者决定如何处理错误,增强代码的鲁棒性。
可以参考以下修改:
if should_panic {
- panic!("dependency check error!");
+ return Err(anyhow::anyhow!("dependency check error!"));
};Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1709 +/- ##
==========================================
- Coverage 55.28% 54.91% -0.37%
==========================================
Files 175 178 +3
Lines 17696 17840 +144
==========================================
+ Hits 9783 9797 +14
- Misses 7913 8043 +130 ☔ 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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
crates/mako/src/plugins/dependency_checker/collect_exports.rs(1 hunks)crates/mako/src/plugins/dependency_checker/collect_imports.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/mako/src/plugins/dependency_checker/collect_exports.rs
🔇 Additional comments (2)
crates/mako/src/plugins/dependency_checker/collect_imports.rs (2)
1-8: 结构定义清晰且合理!
结构体 CollectImports 的设计简洁,使用了恰当的生命周期标注和集合类型。
11-42:
优化错误处理和代码健壮性
代码存在以下问题:
- 多处使用了不安全的
unwrap(),应该使用更安全的错误处理方式 - 缺少对
ImportSpecifier::Namespace的处理逻辑
建议修改如下:
fn visit_import_decl(&mut self, node: &ImportDecl) {
let source = node.src.value.to_string();
- if self.imports_specifiers_with_source.get(&source).is_none() {
- self.imports_specifiers_with_source
- .insert(source.clone(), HashSet::new());
- }
+ let specifiers = self.imports_specifiers_with_source
+ .entry(source.clone())
+ .or_default();
node.specifiers
.iter()
.for_each(|specifier| match specifier {
ImportSpecifier::Named(named) => {
if let Some(ModuleExportName::Ident(ident)) = &named.imported {
- self.imports_specifiers_with_source
- .get_mut(&source)
- .unwrap()
- .insert(ident.sym.to_string());
+ specifiers.insert(ident.sym.to_string());
} else {
- self.imports_specifiers_with_source
- .get_mut(&source)
- .unwrap()
- .insert(named.local.sym.to_string());
+ specifiers.insert(named.local.sym.to_string());
}
}
ImportSpecifier::Default(_) => {
- self.imports_specifiers_with_source
- .get_mut(&source)
- .unwrap()
- .insert("default".into());
+ specifiers.insert("default".into());
}
+ ImportSpecifier::Namespace(ns) => {
+ specifiers.insert(ns.local.sym.to_string());
+ }
_ => {}
})
}| fn visit_named_export(&mut self, node: &NamedExport) { | ||
| if let Some(src) = &node.src { | ||
| if self | ||
| .imports_specifiers_with_source | ||
| .get(src.value.as_str()) | ||
| .is_none() | ||
| { | ||
| self.imports_specifiers_with_source | ||
| .insert(src.value.to_string(), HashSet::new()); | ||
| } | ||
|
|
||
| node.specifiers.iter().for_each(|specifier| { | ||
| if let ExportSpecifier::Named(named) = specifier { | ||
| if let ModuleExportName::Ident(ident) = &named.orig { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(src.value.as_str()) | ||
| .unwrap() | ||
| .insert(ident.sym.to_string()); | ||
| } | ||
| } | ||
| }) | ||
| }; | ||
| } |
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.
🛠️ Refactor suggestion
改进导出处理逻辑的实现
当前实现存在以下问题:
- 使用了不安全的
unwrap() - 代码结构有重复,可以进一步优化
- 缺少对其他类型导出说明符的处理
建议修改如下:
fn visit_named_export(&mut self, node: &NamedExport) {
if let Some(src) = &node.src {
- if self
- .imports_specifiers_with_source
- .get(src.value.as_str())
- .is_none()
- {
- self.imports_specifiers_with_source
- .insert(src.value.to_string(), HashSet::new());
- }
+ let specifiers = self.imports_specifiers_with_source
+ .entry(src.value.to_string())
+ .or_default();
node.specifiers.iter().for_each(|specifier| {
if let ExportSpecifier::Named(named) = specifier {
if let ModuleExportName::Ident(ident) = &named.orig {
- self.imports_specifiers_with_source
- .get_mut(src.value.as_str())
- .unwrap()
- .insert(ident.sym.to_string());
+ specifiers.insert(ident.sym.to_string());
}
}
})
};
}另外建议添加单元测试以验证各种导出场景的正确性。
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fn visit_named_export(&mut self, node: &NamedExport) { | |
| if let Some(src) = &node.src { | |
| if self | |
| .imports_specifiers_with_source | |
| .get(src.value.as_str()) | |
| .is_none() | |
| { | |
| self.imports_specifiers_with_source | |
| .insert(src.value.to_string(), HashSet::new()); | |
| } | |
| node.specifiers.iter().for_each(|specifier| { | |
| if let ExportSpecifier::Named(named) = specifier { | |
| if let ModuleExportName::Ident(ident) = &named.orig { | |
| self.imports_specifiers_with_source | |
| .get_mut(src.value.as_str()) | |
| .unwrap() | |
| .insert(ident.sym.to_string()); | |
| } | |
| } | |
| }) | |
| }; | |
| } | |
| fn visit_named_export(&mut self, node: &NamedExport) { | |
| if let Some(src) = &node.src { | |
| let specifiers = self.imports_specifiers_with_source | |
| .entry(src.value.to_string()) | |
| .or_default(); | |
| node.specifiers.iter().for_each(|specifier| { | |
| if let ExportSpecifier::Named(named) = specifier { | |
| if let ModuleExportName::Ident(ident) = &named.orig { | |
| specifiers.insert(ident.sym.to_string()); | |
| } | |
| } | |
| }) | |
| }; | |
| } |
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: 3
🧹 Outside diff range and nitpick comments (1)
crates/mako/src/plugins/imports_checker/collect_exports.rs (1)
31-31: 避免不必要的字符串分配在调用
self.specifiers.remove时,可以直接使用字符串字面量,避免调用to_string()带来的不必要分配。建议修改如下:
-self.specifiers.remove(&"default".to_string()); +self.specifiers.remove("default");Also applies to: 35-35
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (7)
crates/mako/src/compiler.rs(2 hunks)crates/mako/src/config/experimental.rs(1 hunks)crates/mako/src/config/mako.config.default.json(1 hunks)crates/mako/src/plugins.rs(1 hunks)crates/mako/src/plugins/imports_checker.rs(1 hunks)crates/mako/src/plugins/imports_checker/collect_exports.rs(1 hunks)crates/mako/src/plugins/imports_checker/collect_imports.rs(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/mako/src/plugins.rs
🔇 Additional comments (5)
crates/mako/src/config/experimental.rs (1)
16-16: 新增配置字段已正确添加
imports_checker 字段已成功添加到 ExperimentalConfig 配置中,符合预期。
crates/mako/src/config/mako.config.default.json (1)
76-77: 配置文件更新正确
在 experimental 部分添加了 importsChecker 配置项,默认值为 false,符合预期。
crates/mako/src/compiler.rs (3)
18-18: 导入更改看起来没有问题!
新增的 Mode 导入与后续的生产模式检查逻辑相匹配。
261-263: 🛠️ Refactor suggestion
建议增加插件初始化的错误处理
当前的实现在添加 ImportsChecker 插件时没有处理潜在的初始化错误。建议添加错误处理逻辑以提高代码的健壮性。
建议修改为:
if config.mode == Mode::Production && config.experimental.imports_checker {
- plugins.push(Arc::new(plugins::imports_checker::ImportsChecker {}));
+ match plugins::imports_checker::ImportsChecker::new() {
+ Ok(checker) => plugins.push(Arc::new(checker)),
+ Err(e) => return Err(anyhow!("Failed to initialize ImportsChecker: {}", e)),
+ }
}Likely invalid or redundant comment.
261-264: 验证插件的执行顺序是否合理
ImportsChecker 插件被添加在内置插件之后,需要验证这个执行顺序是否会影响其功能。
✅ Verification successful
Let me analyze the implementation details further to verify the plugin execution order.
ImportsChecker 插件的执行顺序是合理的
通过分析代码实现可以确认:
- ImportsChecker 插件仅在
after_build阶段执行,用于验证导入的正确性 - 该插件只是读取已经构建好的模块图(module graph)进行验证,不会修改任何构建产物
- 它在内置插件之后执行是合理的,因为它需要等待所有模块都被正确解析和构建完成后才能进行导入检查
将此插件放在内置插件之后不会影响其功能的正常发挥。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查 ImportsChecker 插件与其他插件的依赖关系
# 搜索 ImportsChecker 的实现细节
ast-grep --pattern 'impl Plugin for ImportsChecker {
$$$
}'
# 检查其他插件是否依赖 ImportsChecker 的输出
rg -l "imports_checker" --type rust
Length of output: 6057
Script:
#!/bin/bash
# 检查插件执行顺序的相关代码
ast-grep --pattern 'fn after_build(&self, $_, $_) -> $_ {
$$$
}'
# 检查其他插件的实现
rg -A 5 "impl Plugin for" --type rust
Length of output: 22758
| .for_each(|specifier| match specifier { | ||
| ImportSpecifier::Named(named) => { | ||
| if let Some(ModuleExportName::Ident(ident)) = &named.imported { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert(ident.sym.to_string()); | ||
| } else { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert(named.local.sym.to_string()); | ||
| } | ||
| } | ||
| ImportSpecifier::Default(_) => { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(&source) | ||
| .unwrap() | ||
| .insert("default".into()); | ||
| } | ||
| _ => {} | ||
| }) |
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.
请处理遗漏的 ImportSpecifier::Namespace 情况
在 visit_import_decl 方法中,没有处理 ImportSpecifier::Namespace 的情况。这可能会导致对形如 import * as ns from 'module' 的导入未被正确收集,可能造成后续依赖解析问题。
建议在 match 分支中添加对 ImportSpecifier::Namespace 的处理,例如:
match specifier {
ImportSpecifier::Named(named) => {
// ...现有代码...
},
ImportSpecifier::Default(_) => {
// ...现有代码...
+ },
+ ImportSpecifier::Namespace(namespace) => {
+ self.imports_specifiers_with_source
+ .get_mut(&source)
+ .unwrap()
+ .insert(namespace.local.sym.to_string());
},
_ => {}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| .for_each(|specifier| match specifier { | |
| ImportSpecifier::Named(named) => { | |
| if let Some(ModuleExportName::Ident(ident)) = &named.imported { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert(ident.sym.to_string()); | |
| } else { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert(named.local.sym.to_string()); | |
| } | |
| } | |
| ImportSpecifier::Default(_) => { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert("default".into()); | |
| } | |
| _ => {} | |
| }) | |
| .for_each(|specifier| match specifier { | |
| ImportSpecifier::Named(named) => { | |
| if let Some(ModuleExportName::Ident(ident)) = &named.imported { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert(ident.sym.to_string()); | |
| } else { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert(named.local.sym.to_string()); | |
| } | |
| } | |
| ImportSpecifier::Default(_) => { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert("default".into()); | |
| } | |
| ImportSpecifier::Namespace(namespace) => { | |
| self.imports_specifiers_with_source | |
| .get_mut(&source) | |
| .unwrap() | |
| .insert(namespace.local.sym.to_string()); | |
| } | |
| _ => {} | |
| }) |
| node.specifiers.iter().for_each(|specifier| { | ||
| if let ExportSpecifier::Named(named) = specifier { | ||
| if let ModuleExportName::Ident(ident) = &named.orig { | ||
| self.imports_specifiers_with_source | ||
| .get_mut(src.value.as_str()) | ||
| .unwrap() | ||
| .insert(ident.sym.to_string()); | ||
| } | ||
| } | ||
| }) |
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.
请处理遗漏的 ExportSpecifier::Namespace 情况
在 visit_named_export 方法中,没有处理 ExportSpecifier::Namespace 的情况。这可能会导致对形如 export * as ns from 'module' 的导出未被正确收集,可能影响模块的导出分析。
建议在 for_each 循环中添加对 ExportSpecifier::Namespace 的处理,例如:
specifier => match &specifier {
ExportSpecifier::Named(named) => {
// ...现有代码...
}
+ ExportSpecifier::Namespace(namespace) => {
+ if let ModuleExportName::Ident(ident) = &namespace.name {
+ self.imports_specifiers_with_source
+ .get_mut(src.value.as_str())
+ .unwrap()
+ .insert(ident.sym.to_string());
+ }
},
// ...其他代码...
}Committable suggestion skipped: line range outside the PR's diff.
| if should_panic { | ||
| panic!("dependency check error!"); | ||
| }; |
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.
🛠️ Refactor suggestion
避免使用 panic!,改用适当的错误处理机制
在生产环境中使用 panic! 可能导致程序崩溃,影响用户体验。建议使用错误返回值或日志记录来处理错误,以提供更好的稳定性和可维护性。
可以考虑修改为:
if should_panic {
- panic!("dependency check error!");
+ return Err(anyhow::anyhow!("Dependency check error"));
};并在函数签名中调整返回类型:
-fn after_build(&self, context: &Arc<Context>, _compiler: &Compiler) -> Result<()> {
+fn after_build(&self, context: &Arc<Context>, _compiler: &Compiler) -> Result<(), anyhow::Error> {Committable suggestion skipped: line range outside the PR's diff.
* 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>
why not dev warning ?
will speed down the hmr build
Summary by CodeRabbit
版本更新说明
新功能
ImportsChecker插件,用于分析模块导入和导出。get_module_system函数,确定模块系统类型。JsHooks接口,增加多个新方法和属性以增强功能。配置变更
ExperimentalConfig结构中添加了imports_checker布尔字段。mako.config.default.json,新增importsChecker属性。文档