Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: win path problem with context module and require context #1742

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Jan 8, 2025

Close #1693

Summary by CodeRabbit

  • 新功能

    • 引入 win_path 函数,用于跨平台路径处理
    • 优化模块导入和上下文渲染时的路径格式化
  • 改进

    • 增强了路径处理的一致性和兼容性
    • 提升了不同操作系统下的模块导入和渲染体验

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

概述

演练

这些变更主要涉及在Mako构建插件中引入win_path函数,用于处理文件路径。具体修改包括在context_module.rsrequire_context/param.rsrequire_context/render.rs中添加路径处理逻辑,确保在Windows环境下路径能够正确格式化和处理。变更旨在解决Windows平台下动态导入路径可能出现的兼容性问题。

变更

文件 变更概要
crates/mako/src/plugins/context_module.rs 新增win_path函数导入,在load方法中处理路径
crates/mako/src/plugins/require_context/param.rs 引入win_path函数,修改to_context_id方法中的路径编码
crates/mako/src/plugins/require_context/render.rs 在模块导入和渲染方法中应用win_path函数处理路径

针对链接问题的评估

目标 是否解决 说明
Windows环境下动态导入错误 通过引入win_path函数标准化路径处理

诗歌

🐰 代码兔子轻轻跳,
Windows路径不再绕弯道,
格式化魔法一挥手,
导入顺畅似清风,
兼容性问题再见啦!🚀


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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Walkthrough

This pull request addresses the Windows path issue in the context module and require context by integrating the win_path function. This change ensures that paths are correctly formatted for Windows environments, preventing potential errors related to path handling.

Changes

File Summary
crates/mako/src/plugins/context_module.rs Added win_path function to handle Windows path formatting in key-value mapping.
crates/mako/src/plugins/require_context/param.rs Integrated win_path function to format paths in the require context parameters.
crates/mako/src/plugins/require_context/render.rs Applied win_path function to format paths in module imports and added debug print statements.

@@ -24,18 +25,30 @@ impl ContextLoadMode {
let mut map_str = String::from(r#"var _map_lazy = {"#);
map.iter().for_each(|(key, value)| match self {
ContextLoadMode::Sync => {
println!(

Choose a reason for hiding this comment

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

Debug print statements like println!("... render_module_import1: {} -> {}", win_path(key), win_path(value)); should be removed or replaced with proper logging before merging, as they can clutter the output and are not suitable for production code.

));
}

ContextLoadMode::Lazy => {
println!(

Choose a reason for hiding this comment

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

Debug print statements like println!("... render_module_import2: {} -> {}", win_path(key), win_path(value)); should be removed or replaced with proper logging before merging, as they can clutter the output and are not suitable for production code.

@@ -147,11 +160,12 @@ impl VirtualContextModuleRender {
pub fn module_id_map(&self, map: &BTreeMap<String, String>, context: &Arc<Context>) -> String {
let mut map_str = String::from(r#"var _map = {"#);
for (key, value) in map.iter() {
println!("... replace key: {} -> {}", key, win_path(key));

Choose a reason for hiding this comment

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

Debug print statements like println!("... replace key: {} -> {}", key, win_path(key)); should be removed or replaced with proper logging before merging, as they can clutter the output and are not suitable for production code.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/mako/src/plugins/require_context/render.rs (2)

28-32: 移除调试打印语句

这些调试打印语句应该在发布前移除,它们不应该出现在生产代码中。

-                println!(
-                    "... render_module_import1: {} -> {}",
-                    win_path(key),
-                    win_path(value)
-                );

Also applies to: 42-46


163-163: 移除调试日志

这行调试日志应该在发布前移除。

-            println!("... replace key: {} -> {}", key, win_path(key));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c37e244 and 8da8994.

📒 Files selected for processing (3)
  • crates/mako/src/plugins/context_module.rs (2 hunks)
  • crates/mako/src/plugins/require_context/param.rs (2 hunks)
  • crates/mako/src/plugins/require_context/render.rs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: stable - i686-pc-windows-msvc - node@20
  • GitHub Check: stable - x86_64-pc-windows-msvc - node@20
  • GitHub Check: stable - aarch64-unknown-linux-musl - node@20
  • GitHub Check: Clippy
  • GitHub Check: stable - aarch64-unknown-linux-gnu - node@20
  • GitHub Check: Mako Build (macos-latest)
  • GitHub Check: stable - x86_64-unknown-linux-musl - node@20
  • GitHub Check: stable - x86_64-unknown-linux-gnu - node@20
  • GitHub Check: Cargo Test
  • GitHub Check: Code Coverage
  • GitHub Check: Mako Build (ubuntu-latest)
  • GitHub Check: stable - aarch64-apple-darwin - node@20
  • GitHub Check: stable - x86_64-apple-darwin - node@20
🔇 Additional comments (5)
crates/mako/src/plugins/require_context/param.rs (2)

11-11: 导入了 win_path 函数以处理 Windows 路径

新增了 win_path 函数的导入,用于规范化 Windows 路径格式。


38-40: 确保路径在编码前进行规范化处理

在对路径进行编码之前使用 win_path 进行规范化处理,这有助于解决 Windows 路径的兼容性问题。

crates/mako/src/plugins/require_context/render.rs (1)

36-37: 路径规范化处理的实现正确

在模块导入时对键值对的路径进行规范化处理,确保了 Windows 环境下的路径兼容性。

Also applies to: 50-51, 167-168

crates/mako/src/plugins/context_module.rs (2)

15-15: 正确导入了所需的模块

从 file 模块中导入 win_path 函数,同时保持了其他必要的导入。


123-125: 路径规范化的实现完整且正确

在生成内容时对所有值进行路径规范化处理,确保了跨平台兼容性。建议添加单元测试以验证 Windows 路径的处理。

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 12.50000% with 14 lines in your changes missing coverage. Please review.

Project coverage is 54.78%. Comparing base (c37e244) to head (8da8994).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/plugins/require_context/render.rs 0.00% 13 Missing ⚠️
crates/mako/src/plugins/context_module.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1742      +/-   ##
==========================================
- Coverage   54.82%   54.78%   -0.04%     
==========================================
  Files         180      180              
  Lines       18053    18066      +13     
==========================================
  Hits         9897     9897              
- Misses       8156     8169      +13     

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

@sorrycc sorrycc merged commit f2603f0 into master Jan 8, 2025
23 checks passed
@sorrycc sorrycc deleted the sorrycc-9in3 branch January 8, 2025 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用umi/max,在window环境下, import 动态引入会导致错误
1 participant