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

feat: legacy interop #1638

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat: legacy interop #1638

wants to merge 2 commits into from

Conversation

Jinbao1001
Copy link
Member

@Jinbao1001 Jinbao1001 commented Oct 15, 2024

增加 legacy 开关配置, 修改 swc_helper_interop_require_wildcard的逻辑

Summary by CodeRabbit

  • 新功能

    • 在配置模块中添加了 legacy_interop 字段,扩展了用户的配置选项。
    • 新增方法 modify_legacy_code,根据 legacy_interop 标志修改代码。
    • 创建了用于遗留互操作性的测试目录,包含新的配置文件和测试用例。
    • 在默认配置文件中添加了 "legacyInterop": false 属性。
  • 变更

    • 更新了 get_swc_helper_code 方法以接受 legacy_interop 参数。

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

在此次拉取请求中,mako 配置模块的 Config 结构体新增了一个布尔类型的字段 legacy_interop,用于 JSON 格式序列化为 "legacyInterop"。此外,MakoRuntime 结构体及其 Plugin 特征的实现也进行了修改,get_swc_helper_code 方法新增了 legacy_interop 参数,并引入了一个新方法 modify_legacy_code。最后,创建了一个新的目录用于遗留互操作性测试,包含多个相关文件。

Changes

文件路径 更改摘要
crates/mako/src/config.rs - 新增字段:pub legacy_interop: boolConfig 结构体中。
crates/mako/src/plugins/runtime.rs - 方法签名更新:fn get_swc_helper_code(path: &str) -> Result<String>fn get_swc_helper_code(path: &str, legacy_interop: bool) -> Result<String>
- 新增方法:fn modify_legacy_code(origin_code: &str, legacy_interop: bool) -> String
e2e/fixtures/config.legacy_interop/ - 新增目录及文件:mako.config.jsonsrc/a.tssrc/index.ts,并在相应文件中添加功能和测试用例。
crates/mako/src/config/mako.config.default.json - 新增属性:"legacyInterop": false 在默认配置文件中。

Possibly related PRs

  • feat: pass umi config mako #1394: 此 PR 涉及为特定的 mako 配置键添加支持,可能与主 PR 中新增的 legacy_interop 字段相关,均涉及增强 mako 的配置选项。
  • fix: merge mako config #1578: 此 PR 修改了 getMakoConfig 函数以合并配置对象,可能包括主 PR 中的新 legacy_interop 字段,表明新配置可能与现有结构集成。

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?

❤️ 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 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
Member

@sorrycc sorrycc left a comment

Choose a reason for hiding this comment

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

docs!

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: 3

🧹 Outside diff range and nitpick comments (4)
e2e/fixtures/config.legacy_interop/expect.js (2)

3-3: injectSimpleJest() 的使用看起来不错。

在导入后立即调用该函数是设置测试环境的好做法。空行的使用提高了可读性。

为了提高代码的可维护性,您可以考虑添加一个简短的注释来解释 injectSimpleJest() 的作用。例如:

// 设置 Jest 测试环境
injectSimpleJest()

5-6: 主模块的引入看起来没有问题。

使用 require 而不进行赋值表明这只是为了副作用。路径 ./dist/index.js 表明这可能是项目的编译输出。文件末尾的空行是一个好习惯。

为了提高代码的可读性和可维护性,您可以考虑添加一个注释来解释为什么需要这个模块。例如:

// 加载主模块以执行测试
require("./dist/index.js");

此外,如果这个文件的目的是运行测试,您可能想要考虑添加一些实际的测试用例。

e2e/fixtures/config.legacy_interop/src/index.ts (1)

1-2: 请考虑移除 TypeScript 忽略指令

当前代码使用了 TypeScript 忽略指令来抑制导入语句的类型检查。虽然这可能是出于测试目的,但通常不建议这样做。

建议:

  1. 如果可能,请尝试解决导致需要使用忽略指令的底层问题。
  2. 如果确实需要忽略类型检查,请添加注释解释原因,以便其他开发人员理解。

关于通配符导入,它可能是用于测试遗留互操作功能。如果是这样,请确保在测试用例中明确说明这一点。

crates/mako/src/config.rs (1)

178-179: 新增的 legacy_interop 字段看起来不错,但需要更多文档说明。

新增的 legacy_interop 布尔字段与拉取请求的目标相符,可以增强与遗留系统的互操作性。序列化注解 #[serde(rename = "legacyInterop")] 确保了与 JSON 格式的兼容性。

建议为这个新字段添加注释,解释其用途、默认值以及对系统行为的影响。这将有助于其他开发人员理解此配置选项的作用。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6b7efd9 and c65d900.

📒 Files selected for processing (6)
  • crates/mako/src/config.rs (1 hunks)
  • crates/mako/src/plugins/runtime.rs (5 hunks)
  • e2e/fixtures/config.legacy_interop/expect.js (1 hunks)
  • e2e/fixtures/config.legacy_interop/mako.config.json (1 hunks)
  • e2e/fixtures/config.legacy_interop/src/a.ts (1 hunks)
  • e2e/fixtures/config.legacy_interop/src/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • e2e/fixtures/config.legacy_interop/mako.config.json
  • e2e/fixtures/config.legacy_interop/src/a.ts
🧰 Additional context used
🔇 Additional comments (3)
e2e/fixtures/config.legacy_interop/expect.js (1)

1-1: 导入语句看起来没有问题。

导入语句使用了 CommonJS 的 require 语法,这与 Node.js 环境一致。相对路径的使用表明该文件是更大项目结构的一部分。

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

69-82: 新增 modify_legacy_code 方法以支持 legacy_interop

modify_legacy_code 方法正确实现了根据 legacy_interop 参数来修改代码的逻辑,确保了对遗留代码的兼容性。


84-84: 更新了 get_swc_helper_code 方法的签名

get_swc_helper_code 方法增加了 legacy_interop 参数,与调用方保持一致,增强了函数的灵活性。

Comment on lines +7 to +9
it('should work when config legacyInterop',()=>{
expect(a()).toBe(1)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议改进测试用例的实现和文档

当前的测试用例虽然功能正确,但可以通过以下方式进行改进:

  1. 测试描述可以更具体,明确说明正在测试遗留互操作性的哪个方面。
  2. 添加注释解释 a() 函数的预期行为及其返回值的含义。
  3. 考虑添加更多断言来全面测试遗留互操作性功能。

建议修改如下:

it('应该在启用 legacyInterop 配置时正确导入和使用模块 a', () => {
  // 验证模块 a 被正确导入并按预期工作
  expect(a()).toBe(1);
  
  // 可以添加更多断言来测试其他方面的行为
  // 例如:expect(typeof a).toBe('function');
});

Comment on lines +49 to +50
let code =
Self::get_swc_helper_code(&source, context.config.legacy_interop).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

避免使用 unwrap() 以防止潜在的崩溃

在第 49-50 行中,调用了 get_swc_helper_code 方法并直接使用了 unwrap()。如果该方法返回 Err,程序将会发生崩溃。建议使用 ? 运算符或匹配处理错误,以提高代码的稳健性。

Comment on lines +161 to +162
&Self::modify_legacy_code(origin, legacy_interop)
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

小心字符串替换的可靠性

在第 161-162 行中,使用了 modify_legacy_code 方法对 origin 代码进行字符串替换。依赖特定字符串(如 // ### legacy_interop ###)进行替换可能在上游代码改变时失效。建议使用更可靠的方法,如解析代码的 AST,来定位并修改目标代码片段,以提高代码的鲁棒性。

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 55.56%. Comparing base (1c79bd4) to head (beb113a).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/plugins/runtime.rs 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1638      +/-   ##
==========================================
- Coverage   55.66%   55.56%   -0.11%     
==========================================
  Files         172      172              
  Lines       17294    17411     +117     
==========================================
+ Hits         9627     9674      +47     
- Misses       7667     7737      +70     

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

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

🧹 Outside diff range and nitpick comments (1)
crates/mako/src/config/mako.config.default.json (1)

75-75: 新增的 legacyInterop 配置选项看起来不错

新增的 "legacyInterop": false 配置选项与 PR 的目标一致,默认值设置为 false 是个明智的选择。属性名称使用驼峰式命名法,与文件中的其他属性保持一致。

建议为这个新的配置选项添加相应的文档说明,以便其他开发者了解它的用途和影响。可以考虑在项目的 README 或配置文档中添加对 legacyInterop 选项的解释。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c65d900 and beb113a.

📒 Files selected for processing (1)
  • crates/mako/src/config/mako.config.default.json (1 hunks)
🧰 Additional context used

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.

2 participants