Conversation
Walkthrough此拉取请求的更改引入了 Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 8
🧹 Outside diff range and nitpick comments (12)
e2e/fixtures/plugins/src/index.tsx (1)
7-9: 代码更改看起来不错!新添加的代码符合预期,引入了transform模块并进行了日志记录。这与PR的目标一致。
为了提高代码的可读性,建议在新添加的部分前后各添加一个空行,以便更好地分隔不同的代码块。例如:
console.log(require('resolve_id_external')); + // transform console.log(require('./transform')); +这样可以使代码结构更清晰,便于阅读和维护。
e2e/fixtures/plugins/expect.js (1)
15-17: 新增的断言看起来不错!新添加的断言正确地测试了转换钩子的功能。它与文件中现有的断言风格保持一致,并且逻辑清晰。
为了提高可读性,建议在新增的断言之前添加一个空行,以便更好地分隔不同的测试组。您可以应用以下更改:
assert(content.includes(`module.exports = resolve_id_external;`), `resolve_id hook with external works`); + // transform hook assert(content.includes(`console.log('transform_2_1');`), `transform hook works`);e2e/fixtures/plugins/plugins.config.js (1)
38-48: 新增 transform 方法这个新增的 transform 方法为特定文件提供了转换功能,这是一个很好的扩展。几点建议:
- 考虑使用更具描述性的变量名,如
originalCode替代code。- 日志输出在生产环境中可能会产生大量无用信息,建议添加一个调试模式开关。
- 可以考虑使用正则表达式来进行更复杂的内容替换。
建议对代码进行如下优化:
async transform(originalCode, id) { if (id.endsWith("transform.ts")) { if (process.env.DEBUG) { console.log("transform", originalCode, id); } return { content: originalCode.replace(/\btransform\b/g, "transform_1"), type: "ts", }; } }这样可以提高代码的可读性和灵活性。
packages/mako/binding.d.ts (2)
60-63: LGTM!建议对类型定义进行微小改进。
transform方法的添加看起来很好,符合接口的现有模式。它为转换操作提供了足够的灵活性。为了提高可读性和类型安全性,建议将输入和输出类型提取为单独的接口。例如:
interface TransformInput { content: string; type: 'css' | 'js'; } interface TransformOutput { content: string; type: 'css' | 'js'; } transform?: ( content: TransformInput, path: string, ) => Promise<TransformOutput | void> | void;这样可以使类型更加明确,并且在将来需要修改输入或输出结构时更容易维护。
80-83: 新接口看起来不错,但可以考虑进行一些改进。
LoadTransformResult接口的添加是好的,结构简单明了。然而,有几点建议可以提高代码的一致性和清晰度:
考虑将
type属性限制为 'css' | 'js',以与transform方法保持一致。可以添加注释解释这个接口的用途,特别是它与
transform方法的关系。考虑重命名接口,例如
TransformResult,以更好地反映其用途(如果它确实是与transform方法相关的)。建议的修改如下:
/** * 表示转换操作的结果。 * 这个接口与 JsHooks 中的 transform 方法相关。 */ export interface TransformResult { content: string; type: 'css' | 'js'; }这些改变将提高代码的一致性和可读性。
docs/config.zh-CN.md (6)
575-575: 新增配置项文档清晰明了新增的配置项如
experimental.magicComment、rscClient和rscServer等,文档说明详细且易于理解。这些新功能将为开发者提供更多的灵活性和控制力。建议:考虑在文档的开头添加一个变更日志或新特性概述,以便用户快速了解最新的更新。
575-575: 插件系统得到增强,建议添加使用示例新增的
transform钩子函数为插件系统提供了更强大的内容转换能力,这是一个很好的改进。建议:为了帮助开发者更好地理解和使用这个新特性,可以考虑添加一个简单的使用示例,展示如何在插件中实现
transform钩子函数。例如:{ plugins: [ { name: 'my-transform-plugin', transform: async (content, id) => { // 示例:将所有的 'foo' 替换为 'bar' const transformedContent = content.replace(/foo/g, 'bar'); return { content: transformedContent, type: 'js' }; } } ] }这样的示例将有助于开发者快速掌握新功能的使用方法。
575-575: Sass配置文档更新,建议提供更多选项说明文档中新增了关于安装
sass包的提示,这对用户很有帮助。同时,配置类型更新为Options<'async'>提供了更清晰的类型定义。建议:考虑添加更多关于可用的sass选项的详细说明。例如,可以列出一些常用的选项及其作用,如:
{ sass: { outputStyle: 'compressed', // 输出压缩的CSS includePaths: ['./node_modules'], // 设置Sass导入的搜索路径 precision: 6 // 设置小数精度 } }这将帮助开发者更全面地了解和使用sass配置。
575-575: publicPath配置说明得到改进,建议添加实际使用示例文档中新增了关于"runtime"特殊值和
__mako_public_path__的说明,这对需要动态配置publicPath的用户来说非常有价值。建议:为了使用户更好地理解这些新特性,可以考虑添加一个实际的使用示例。例如:
// 配置文件中 { publicPath: "runtime" } // 在应用的入口文件中 if (process.env.NODE_ENV === 'production') { __mako_public_path__ = 'https://cdn.example.com/assets/'; } else { __mako_public_path__ = '/dev-assets/'; }这个例子展示了如何根据环境动态设置publicPath,将帮助用户更好地理解和应用这个功能。
575-575: 别名配置说明更加清晰,建议补充解释文档中新增的两个重要说明有效地澄清了别名配置的常见误区,这对于防止配置错误非常有帮助。
建议:为了让用户更好地理解这些建议的原因,可以考虑添加简短的解释。例如:
关于不添加
/*后缀:
"我们不支持添加/*后缀是因为这可能会导致解析冲突和不可预期的行为。直接使用目录路径可以确保更一致的模块解析。"关于添加
./前缀:
"添加./前缀是为了明确指示这是一个本地路径,而不是一个npm包。这有助于防止潜在的命名冲突和错误的模块解析。"这些解释将帮助用户理解配置建议背后的原因,从而更好地遵循最佳实践。
575-575: 文档结构清晰,建议进一步提高一致性整体而言,文档结构良好,各个配置项的说明清晰明了,代码示例也很有帮助。格式的一致性贯穿整个文档,这有助于提高可读性。
建议:为了进一步提高文档质量,可以考虑以下几点:
对于所有配置项,尽可能提供默认值。这将帮助用户更好地理解每个选项的初始状态。
为每个配置项提供至少一个简单的使用示例。虽然大多数选项已经有了示例,但确保所有选项都有示例将使文档更加完整。
考虑添加一个"最佳实践"部分,汇总一些常见的配置组合或使用技巧。这将帮助新用户快速上手,也能为有经验的用户提供优化建议。
这些小改进将使文档更加全面和一致,进一步提升用户体验。
crates/binding/src/js_plugin.rs (1)
126-130: 优化match匹配以处理更多的内容类型。在处理
content时,目前只考虑了JsContent和CssContent。如果未来会有更多类型的内容,建议使用模式匹配来处理,或者为未知类型提供默认行为。可以考虑:
let content_str = match content { Content::Js(js_content) => js_content.content.clone(), Content::Css(css_content) => css_content.clone(), + other => { + eprintln!("Unsupported content variant: {:?}", other); + return Ok(None); + } };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (11)
- crates/binding/src/js_hook.rs (4 hunks)
- crates/binding/src/js_plugin.rs (2 hunks)
- crates/mako/src/build.rs (1 hunks)
- crates/mako/src/plugin.rs (2 hunks)
- docs/config.md (1 hunks)
- docs/config.zh-CN.md (1 hunks)
- e2e/fixtures/plugins/expect.js (1 hunks)
- e2e/fixtures/plugins/plugins.config.js (1 hunks)
- e2e/fixtures/plugins/src/index.tsx (1 hunks)
- e2e/fixtures/plugins/src/transform.ts (1 hunks)
- packages/mako/binding.d.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
- e2e/fixtures/plugins/src/transform.ts
🧰 Additional context used
🔇 Additional comments (12)
e2e/fixtures/plugins/plugins.config.js (3)
4-10: 代码风格更新已批准这些更改统一了字符串文字的格式,使用双引号替代了单引号。这提高了代码的一致性和可读性。
14-21: 代码格式统一性得到改善这部分的修改延续了之前的风格更新,将字符串文字从单引号改为双引号。这种一致性有助于提高代码的可维护性。
25-36: 代码结构优化和格式统一resolveId 方法的重构提高了可读性:
- 使用双引号统一了字符串格式。
- 返回对象的结构更清晰。
- 使用模板字符串来调用 path.join 是一个很好的做法。
这些更改使代码更易于理解和维护,同时保持了原有的功能。
crates/mako/src/build.rs (1)
274-279: 🛠️ Refactor suggestion新增的转换步骤可能影响性能和行为
这个新增的转换步骤引入了一些值得注意的变化:
- 内容现在是可变的,这可能会影响后续的操作。
- 新的
load_transform方法允许在进一步处理之前对内容进行额外的处理。- 使用
plugin_driver表明这个转换可以通过插件进行自定义。建议:
- 考虑添加性能测试,以评估这个额外步骤对构建时间的影响。
- 确保在文档中清楚地说明这个新的转换步骤,以及如何通过插件系统来利用它。
- 考虑添加一个配置选项,允许在不需要时跳过这个转换步骤,以优化性能。
为了验证这个变更的影响,我们可以运行以下脚本:
docs/config.md (4)
577-577: 新增了 transform 插件钩子,增强了内容转换能力在
JSHooks接口中添加了新的transform钩子函数。这个钩子允许在构建过程中对内容进行更灵活的转换。使用示例:
{ transform: async (content: string, id: string) => { // 在这里对内容进行转换 const transformedContent = someTransformFunction(content); return { content: transformedContent, type: 'js' }; } }请注意,这个新钩子可能会影响构建管道,使用时需要谨慎。
577-577: px2rem 配置选项得到了显著扩展,提供了更精细的控制
px2rem配置新增了以下选项:
propBlackList:属性黑名单propWhiteList:属性白名单selectorBlackList:选择器黑名单selectorWhiteList:选择器白名单selectorDoubleList:选择器双倍 rem 列表这些新选项允许您更精确地控制 px 到 rem 的转换过程。特别值得注意的是,选择器列表现在支持正则表达式,例如:
"selectorBlackList": [".a", "/.__CustomClass_/"]使用这些新选项时,请确保仔细考虑您的 CSS 结构,以获得最佳的转换结果。
577-577: resolve 配置中的别名使用说明得到了重要更新在
resolve配置的说明中,新增了两个重要提示:
目录别名不支持
/*后缀:{ resolve: { alias: [ - ["@/src/*", "./src/*"], + [ "@/src", "./src"], ], }, }本地路径别名必须添加
./前缀:{ resolve: { alias: [ - ["@/src", "src"], + ["@/src", "./src"], ], }, }这些更新有助于防止常见的别名配置错误。请确保在设置别名时遵循这些新的指导原则,以确保您的别名正确解析。
577-577: watch 配置新增了忽略路径的示例在
watch配置部分,新增了一个有用的示例,展示了如何忽略特定路径:{ watch: { ignorePaths: ["foo"], }, }这个示例演示了如何忽略根目录下的
foo目录。这对于需要在开发过程中排除某些目录不被监视的用户来说非常有用。您可以根据项目需求,轻松地调整ignorePaths数组来排除多个目录或文件。crates/binding/src/js_hook.rs (1)
137-142: 检查TransformResult结构体的字段类型和名称在定义
TransformResult结构体时,确保字段与预期的 TypeScript 类型匹配。当前定义为:pub struct TransformResult { pub content: String, #[napi(js_name = "type")] pub content_type: String, }其中,使用了
#[napi(js_name = "type")]来映射字段名。但要注意,type在 Rust 中是关键字,不能作为字段名。当前的处理是正确的,确保了在导出到 JavaScript 时,字段名为type。请确认这一映射是否符合预期。crates/binding/src/js_plugin.rs (2)
15-16: 确认新添加的属性是否在其他地方正确使用。
JsPlugin结构体中新增了hooks属性,请确保在代码的其他部分正确地初始化和使用了该属性,以避免潜在的None错误或未初始化问题。
132-152: 检查transform钩子的返回值处理。在调用
hook.call后,对返回的result进行了解析。请确保所有可能的返回情况都已被正确处理,尤其是None的情况,以及result.content_type可能为空或无效的情况。运行以下脚本以验证所有可能的返回值情况:
crates/mako/src/plugin.rs (1)
61-68: 添加新方法load_transform到Plugintrait
load_transform方法的定义合理,参数类型和返回值符合预期,为插件提供了内容转换的钩子。
| { | ||
| async transform(code, id) { | ||
| if (id.endsWith("transform.ts")) { | ||
| console.log("transform", code, id); | ||
| return { | ||
| content: code.replace("transform", "transform_2"), | ||
| type: "ts", | ||
| }; | ||
| } | ||
| }, |
There was a problem hiding this comment.
🛠️ Refactor suggestion
重复的 transform 方法
这个 transform 方法与前一个几乎相同,只是替换的内容不同。这种重复可能导致维护问题。建议重构以提高代码的可维护性和灵活性。
建议将两个 transform 方法合并为一个可配置的方法:
function createTransform(replacement) {
return async function transform(originalCode, id) {
if (id.endsWith("transform.ts")) {
if (process.env.DEBUG) {
console.log("transform", originalCode, id);
}
return {
content: originalCode.replace(/\btransform\b/g, replacement),
type: "ts",
};
}
};
}
module.exports = [
// ... 其他插件配置 ...
{
transform: createTransform("transform_1"),
},
{
transform: createTransform("transform_2"),
},
];这种方法可以减少代码重复,并使未来添加更多类似的转换更加容易。
| #[napi( | ||
| ts_type = "(content: { content: string, type: 'css' | 'js' }, path: string) => Promise<{ content: string, type: 'css' | 'js' } | void> | void;" | ||
| )] | ||
| pub transform: Option<JsFunction>, |
There was a problem hiding this comment.
建议检查 transform 方法的参数类型匹配
在 JsHooks 中,transform 的 TypeScript 类型定义为:
(content: { content: string, type: 'css' | 'js' }, path: string) => Promise<{ content: string, type: 'css' | 'js' } | void> | void;然而,在 Rust 中,TsFnHooks 的 transform 对应的类型为:
Option<ThreadsafeFunction<(String, String), Option<TransformResult>>>这意味着 Rust 端的参数是 (String, String),即两个字符串,但根据 TypeScript 类型定义,应该接收一个对象和一个字符串。建议在 Rust 端调整参数类型,使其与 TypeScript 类型定义一致,例如将参数类型修改为 (LoadResult, String),并相应地修改 ThreadsafeFunction 的泛型参数。
| pub resolve_id: | ||
| Option<ThreadsafeFunction<(String, String, ResolveIdParams), Option<ResolveIdResult>>>, | ||
| pub _on_generate_file: Option<ThreadsafeFunction<WriteFile, ()>>, | ||
| pub transform: Option<ThreadsafeFunction<(String, String), Option<TransformResult>>>, |
There was a problem hiding this comment.
调整 transform 的 ThreadsafeFunction 参数类型
如上所述,transform 的 ThreadsafeFunction 参数类型应与 TypeScript 定义保持一致,建议将类型修改为:
Option<ThreadsafeFunction<(LoadResult, String), Option<TransformResult>>>这样可以确保在调用时,参数类型匹配,避免潜在的类型不安全问题。
| transform: hooks.transform.as_ref().map(|hook| unsafe { | ||
| ThreadsafeFunction::from_napi_value(env.raw(), hook.raw()).unwrap() | ||
| }), |
There was a problem hiding this comment.
修改 transform 的初始化以匹配新的参数类型
在 TsFnHooks::new 方法中,初始化 transform 时,需要确保类型匹配。如果调整了 transform 的类型,需要相应地修改初始化代码。例如:
transform: hooks.transform.as_ref().map(|hook| unsafe {
ThreadsafeFunction::from_napi_value(env.raw(), hook.raw()).unwrap()
}),请确保映射的函数类型与新的参数类型一致。
| use crate::js_hook::{ | ||
| LoadResult, TransformResult, ResolveIdParams, ResolveIdResult, TsFnHooks, WriteFile, | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
建议:导入语句的排序和组织。
在第10-12行,导入的模块列表可能需要重新组织,以提高可读性和维护性。考虑按照模块名称的字母顺序或功能相关性对导入进行排序。
| fn load_transform( | ||
| &self, | ||
| content: &mut Content, | ||
| path: &str, | ||
| _context: &Arc<Context>, | ||
| ) -> Result<Option<Content>> { | ||
| if let Some(hook) = &self.hooks.transform { | ||
| let content_str = match content { | ||
| Content::Js(js_content) => js_content.content.clone(), | ||
| Content::Css(css_content) => css_content.clone(), | ||
| _ => return Ok(None), | ||
| }; | ||
|
|
||
| let result: Option<TransformResult> = hook.call((content_str, path.to_string()))?; | ||
|
|
||
| if let Some(result) = result { | ||
| match result.content_type.as_str() { | ||
| "js" | "ts" => { | ||
| return Ok(Some(Content::Js(JsContent { | ||
| content: result.content, | ||
| is_jsx: false, | ||
| }))) | ||
| } | ||
| "jsx" | "tsx" => { | ||
| return Ok(Some(Content::Js(JsContent { | ||
| content: result.content, | ||
| is_jsx: true, | ||
| }))) | ||
| } | ||
| "css" => return Ok(Some(Content::Css(result.content))), | ||
| _ => return Err(anyhow!("Unsupported content type: {}", result.content_type)), | ||
| } | ||
| } | ||
| } | ||
| Ok(None) | ||
| } |
There was a problem hiding this comment.
新增的load_transform方法功能正确,但需要注意错误处理。
load_transform方法正确地实现了内容转换的逻辑,但在处理未知的content_type时,直接返回了一个错误。建议提供更详细的错误信息,或者考虑默认处理,以提高代码的鲁棒性。
可以应用以下差异来改进错误处理:
_ => return Err(anyhow!("Unsupported content type: {}", result.content_type)),
+ _ => {
+ eprintln!("Warning: Unsupported content type '{}', skipping transformation.", result.content_type);
+ return Ok(None);
+ }📝 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 load_transform( | |
| &self, | |
| content: &mut Content, | |
| path: &str, | |
| _context: &Arc<Context>, | |
| ) -> Result<Option<Content>> { | |
| if let Some(hook) = &self.hooks.transform { | |
| let content_str = match content { | |
| Content::Js(js_content) => js_content.content.clone(), | |
| Content::Css(css_content) => css_content.clone(), | |
| _ => return Ok(None), | |
| }; | |
| let result: Option<TransformResult> = hook.call((content_str, path.to_string()))?; | |
| if let Some(result) = result { | |
| match result.content_type.as_str() { | |
| "js" | "ts" => { | |
| return Ok(Some(Content::Js(JsContent { | |
| content: result.content, | |
| is_jsx: false, | |
| }))) | |
| } | |
| "jsx" | "tsx" => { | |
| return Ok(Some(Content::Js(JsContent { | |
| content: result.content, | |
| is_jsx: true, | |
| }))) | |
| } | |
| "css" => return Ok(Some(Content::Css(result.content))), | |
| _ => return Err(anyhow!("Unsupported content type: {}", result.content_type)), | |
| } | |
| } | |
| } | |
| Ok(None) | |
| } | |
| fn load_transform( | |
| &self, | |
| content: &mut Content, | |
| path: &str, | |
| _context: &Arc<Context>, | |
| ) -> Result<Option<Content>> { | |
| if let Some(hook) = &self.hooks.transform { | |
| let content_str = match content { | |
| Content::Js(js_content) => js_content.content.clone(), | |
| Content::Css(css_content) => css_content.clone(), | |
| _ => return Ok(None), | |
| }; | |
| let result: Option<TransformResult> = hook.call((content_str, path.to_string()))?; | |
| if let Some(result) = result { | |
| match result.content_type.as_str() { | |
| "js" | "ts" => { | |
| return Ok(Some(Content::Js(JsContent { | |
| content: result.content, | |
| is_jsx: false, | |
| }))) | |
| } | |
| "jsx" | "tsx" => { | |
| return Ok(Some(Content::Js(JsContent { | |
| content: result.content, | |
| is_jsx: true, | |
| }))) | |
| } | |
| "css" => return Ok(Some(Content::Css(result.content))), | |
| _ => { | |
| eprintln!("Warning: Unsupported content type '{}', skipping transformation.", result.content_type); | |
| return Ok(None); | |
| } | |
| } | |
| } | |
| } | |
| Ok(None) | |
| } |
|
|
||
| pub fn load_transform( | ||
| &self, | ||
| content: &mut Content, | ||
| path: &str, | ||
| context: &Arc<Context>, | ||
| ) -> Result<Content> { | ||
| let mut content = content.clone(); | ||
| for plugin in &self.plugins { | ||
| if let Some(transformed) = plugin.load_transform(&mut content, path, context)? { | ||
| content = transformed; | ||
| } | ||
| } | ||
| Ok(content) | ||
| } |
There was a problem hiding this comment.
load_transform 方法的返回类型与 Plugin trait 中的定义不一致
在 Plugin trait 中,load_transform 方法的返回类型是 Result<Option<Content>>,而在 PluginDriver 中实现的返回类型是 Result<Content>。为了保持一致性,建议修改 PluginDriver 中的方法返回类型。
可以将 PluginDriver 中的 load_transform 方法的返回类型修改为 Result<Option<Content>>:
- ) -> Result<Content> {
+ ) -> Result<Option<Content>> {并在方法结束时返回 Ok(Some(content)):
- Ok(content)
+ Ok(Some(content))📝 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.
| pub fn load_transform( | |
| &self, | |
| content: &mut Content, | |
| path: &str, | |
| context: &Arc<Context>, | |
| ) -> Result<Content> { | |
| let mut content = content.clone(); | |
| for plugin in &self.plugins { | |
| if let Some(transformed) = plugin.load_transform(&mut content, path, context)? { | |
| content = transformed; | |
| } | |
| } | |
| Ok(content) | |
| } | |
| pub fn load_transform( | |
| &self, | |
| content: &mut Content, | |
| path: &str, | |
| context: &Arc<Context>, | |
| ) -> Result<Option<Content>> { | |
| let mut content = content.clone(); | |
| for plugin in &self.plugins { | |
| if let Some(transformed) = plugin.load_transform(&mut content, path, context)? { | |
| content = transformed; | |
| } | |
| } | |
| Ok(Some(content)) | |
| } |
crates/mako/src/plugin.rs
Outdated
| path: &str, | ||
| context: &Arc<Context>, | ||
| ) -> Result<Content> { | ||
| let mut content = content.clone(); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
避免不必要的克隆操作
在第 396 行,let mut content = content.clone(); 克隆了 content,这可能导致性能开销。考虑直接使用可变引用来修改 content,以避免不必要的克隆。
可以修改方法签名和实现,直接使用可变引用:
- pub fn load_transform(
- &self,
- content: &mut Content,
- path: &str,
- context: &Arc<Context>,
- ) -> Result<Content> {
- let mut content = content.clone();
+ pub fn load_transform(
+ &self,
+ content: &mut Content,
+ path: &str,
+ context: &Arc<Context>,
+ ) -> Result<Option<Content>> {并在循环中直接修改 content:
for plugin in &self.plugins {
- if let Some(transformed) = plugin.load_transform(&mut content, path, context)? {
- content = transformed;
+ if let Some(transformed) = plugin.load_transform(content, path, context)? {
+ *content = transformed;
}
}
- Ok(content)
+ Ok(Some(content.clone()))这样可以避免克隆操作,提高性能。
Committable suggestion was skipped due to low confidence.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1637 +/- ##
==========================================
+ Coverage 55.54% 55.57% +0.02%
==========================================
Files 172 172
Lines 17401 17414 +13
==========================================
+ Hits 9666 9678 +12
- Misses 7735 7736 +1 ☔ View full report in Codecov by Sentry. |
| let content_str = match content { | ||
| Content::Js(js_content) => js_content.content.clone(), | ||
| Content::Css(css_content) => css_content.clone(), | ||
| _ => return Ok(None), | ||
| }; | ||
|
|
||
| let result: Option<TransformResult> = hook.call((content_str, path.to_string()))?; | ||
|
|
||
| if let Some(result) = result { | ||
| match result.content_type.as_str() { | ||
| "js" | "ts" => { | ||
| return Ok(Some(Content::Js(JsContent { | ||
| content: result.content, | ||
| is_jsx: false, | ||
| }))) | ||
| } | ||
| "jsx" | "tsx" => { | ||
| return Ok(Some(Content::Js(JsContent { | ||
| content: result.content, | ||
| is_jsx: true, | ||
| }))) | ||
| } | ||
| "css" => return Ok(Some(Content::Css(result.content))), | ||
| _ => return Err(anyhow!("Unsupported content type: {}", result.content_type)), | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
建议提取公共函数以减少重复代码
在 load 和 load_transform 方法中,对 content_type 的匹配逻辑非常相似。建议将这些重复的代码提取到一个辅助函数中,以提高代码的可维护性和可读性。
可以创建一个辅助函数,例如:
fn content_from_result(content_type: &str, content: String) -> Result<Option<Content>> {
match content_type {
"js" | "ts" => Ok(Some(Content::Js(JsContent {
content,
is_jsx: false,
}))),
"jsx" | "tsx" => Ok(Some(Content::Js(JsContent {
content,
is_jsx: true,
}))),
"css" => Ok(Some(Content::Css(content))),
_ => Err(anyhow!("Unsupported content type: {}", content_type)),
}
}然后在 load_transform 方法中调用:
let result: Option<TransformResult> = hook.call((content_str, path.to_string()))?;
if let Some(result) = result {
- match result.content_type.as_str() {
- "js" | "ts" => {
- return Ok(Some(Content::Js(JsContent {
- content: result.content,
- is_jsx: false,
- })))
- }
- "jsx" | "tsx" => {
- return Ok(Some(Content::Js(JsContent {
- content: result.content,
- is_jsx: true,
- })))
- }
- "css" => return Ok(Some(Content::Css(result.content))),
- _ => return Err(anyhow!("Unsupported content type: {}", result.content_type)),
- }
+ return content_from_result(result.content_type.as_str(), result.content);
}* 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>
part of #1238
Summary by CodeRabbit
新功能
transform字段,用于内容处理和返回 Promise。load_transform方法,实现内容转换功能。文档
transform方法说明,并澄清现有配置项。测试