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

[WIP] feat: keep unresolved nodejs require #1681

Closed
wants to merge 0 commits into from

Conversation

xusd320
Copy link
Contributor

@xusd320 xusd320 commented Nov 7, 2024

faas 场景的特殊需求,对于不能分析出依赖的 require, 保留 nodejs 原生 require。

Summary by CodeRabbit

  • 新特性

    • 增强了 MakoRequire 结构,新增 context 字段,以便在 JavaScript 转换过程中利用上下文信息。
    • 更新了 visit_mut_ident 方法,以支持平台特定的行为,确保在 Node 平台下不替换标识符。
  • 版本更新

    • 所有相关包的版本已更新至 0.9.5-canary.20241107.2

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

该拉取请求对mako crate中的transform.rsmako_require.rs文件进行了多项修改,主要是增强JavaScript转换过程的功能。新增的context字段被添加到MakoRequire结构体中,使其在转换过程中能够利用上下文信息。此外,多个package.json文件的版本号也从0.9.4更新为0.9.5-canary.20241107.2,以反映这些变更。

Changes

文件路径 修改摘要
crates/mako/src/generate/transform.rs - 在MakoRequire结构体中添加了context字段。
- 更新transform_js_generate函数以包含新的上下文参数。
crates/mako/src/visitors/mako_require.rs - 在MakoRequire结构体中添加了context字段。
- 修改visit_mut_ident方法以支持平台特定行为。
- 更新run函数以初始化MakoRequire访问者并传递context
packages/bundler-mako/package.json - 更新@umijs/mako依赖版本从0.9.40.9.5-canary.20241107.2
packages/mako/npm/darwin-arm64/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/darwin-x64/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/linux-arm64-gnu/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/linux-arm64-musl/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/linux-x64-gnu/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/linux-x64-musl/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/win32-ia32-msvc/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/npm/win32-x64-msvc/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
packages/mako/package.json - 更新版本号从0.9.40.9.5-canary.20241107.2
- 更新多个可选依赖的版本号至新版本。

Possibly related PRs

Suggested reviewers

  • stormslowly
  • sorrycc

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.

@xusd320 xusd320 closed this Nov 7, 2024
@xusd320 xusd320 reopened this Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.64%. Comparing base (7434fe5) to head (d4ca903).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1681   +/-   ##
=======================================
  Coverage   55.63%   55.64%           
=======================================
  Files         173      173           
  Lines       17528    17531    +3     
=======================================
+ Hits         9752     9755    +3     
  Misses       7776     7776           

☔ 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 (2)
crates/mako/src/visitors/mako_require.rs (2)

52-54: 建议添加注释说明平台特定逻辑

这段代码实现了在 Node 平台保留原生 require 的核心功能,建议添加注释说明这个特殊处理的目的。

建议添加如下注释:

+    // 在 Node 平台下保留原生 require,不进行替换
     if let Platform::Node = self.context.config.platform {
         return;
     }

116-116: 建议增加 Node 平台场景的测试用例

现有测试覆盖了基本的 require 转换场景,但缺少对新增的 Node 平台特殊处理的测试。

建议添加如下测试用例:

#[test]
fn test_require_in_node_platform() {
    let js_code = r#"require("foo")"#;
    let mut test_utils = TestUtils::gen_js_ast(js_code);
    test_utils.context.config.platform = Platform::Node;
    
    let ast = test_utils.ast.js_mut();
    GLOBALS.set(&test_utils.context.meta.script.globals, || {
        let mut visitor = MakoRequire {
            ignores: vec![],
            unresolved_mark: ast.unresolved_mark,
            context: test_utils.context.clone(),
        };
        ast.ast.visit_mut_with(&mut visitor);
    });
    
    // 验证在 Node 平台下 require 没有被替换
    assert_eq!(test_utils.js_ast_to_code(), r#"require("foo");"#);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7434fe5 and d4ca903.

📒 Files selected for processing (12)
  • crates/mako/src/generate/transform.rs (1 hunks)
  • crates/mako/src/visitors/mako_require.rs (3 hunks)
  • packages/bundler-mako/package.json (1 hunks)
  • packages/mako/npm/darwin-arm64/package.json (1 hunks)
  • packages/mako/npm/darwin-x64/package.json (1 hunks)
  • packages/mako/npm/linux-arm64-gnu/package.json (1 hunks)
  • packages/mako/npm/linux-arm64-musl/package.json (1 hunks)
  • packages/mako/npm/linux-x64-gnu/package.json (1 hunks)
  • packages/mako/npm/linux-x64-musl/package.json (1 hunks)
  • packages/mako/npm/win32-ia32-msvc/package.json (1 hunks)
  • packages/mako/npm/win32-x64-msvc/package.json (1 hunks)
  • packages/mako/package.json (2 hunks)
✅ Files skipped from review due to trivial changes (9)
  • packages/bundler-mako/package.json
  • packages/mako/npm/darwin-arm64/package.json
  • packages/mako/npm/darwin-x64/package.json
  • packages/mako/npm/linux-arm64-gnu/package.json
  • packages/mako/npm/linux-arm64-musl/package.json
  • packages/mako/npm/linux-x64-gnu/package.json
  • packages/mako/npm/linux-x64-musl/package.json
  • packages/mako/npm/win32-ia32-msvc/package.json
  • packages/mako/npm/win32-x64-msvc/package.json
🔇 Additional comments (4)
packages/mako/package.json (2)

3-3: 注意:这是一个金丝雀(预发布)版本

当前更改将版本从稳定版 0.9.4 更新为预发布版本 0.9.5-canary.20241107.2。由于这是一个 WIP PR,使用金丝雀版本是合适的,但请确保在最终发布前进行充分测试。


78-85: 验证所有平台构建包的可用性

所有可选依赖已更新到新版本 0.9.5-canary.20241107.2。

让我们验证这些包是否都已经发布到 npm:

✅ Verification successful

所有平台构建包已成功发布且可用

验证结果显示所有 8 个平台的构建包都已成功发布到 npm 仓库,且版本号均为 0.9.5-canary.20241107.2:

  • @umijs/mako-darwin-arm64
  • @umijs/mako-linux-arm64-gnu
  • @umijs/mako-linux-arm64-musl
  • @umijs/mako-win32-ia32-msvc
  • @umijs/mako-darwin-x64
  • @umijs/mako-win32-x64-msvc
  • @umijs/mako-linux-x64-gnu
  • @umijs/mako-linux-x64-musl
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证所有平台构建包是否已发布到 npm

echo "检查以下包的可用性:"
for pkg in \
  "@umijs/mako-darwin-arm64@0.9.5-canary.20241107.2" \
  "@umijs/mako-linux-arm64-gnu@0.9.5-canary.20241107.2" \
  "@umijs/mako-linux-arm64-musl@0.9.5-canary.20241107.2" \
  "@umijs/mako-win32-ia32-msvc@0.9.5-canary.20241107.2" \
  "@umijs/mako-darwin-x64@0.9.5-canary.20241107.2" \
  "@umijs/mako-win32-x64-msvc@0.9.5-canary.20241107.2" \
  "@umijs/mako-linux-x64-gnu@0.9.5-canary.20241107.2" \
  "@umijs/mako-linux-x64-musl@0.9.5-canary.20241107.2"
do
  npm view $pkg version || echo "$pkg 不存在"
done

Length of output: 4570

crates/mako/src/visitors/mako_require.rs (1)

1-2: 结构变更符合设计要求!

新增的 Arc<Context> 字段能够安全地共享上下文信息,这对于处理 Node.js require 场景是必要的。使用 Arc 确保了线程安全性,同时避免了重复克隆上下文数据。

Also applies to: 9-10, 17-17

crates/mako/src/generate/transform.rs (1)

250-250: 代码变更符合预期且实现正确

这个改动通过向 MakoRequire 添加 context 来支持保留未解析的 nodejs require,这与 PR 的目标相符。使用 Arc::clone 来共享 context 是正确的做法,因为它只会增加引用计数而不会深度克隆数据。

让我们验证一下 MakoRequire 结构体的定义是否正确更新:

@xusd320 xusd320 force-pushed the feat/keep-unresolved-nodejs-require branch from d4ca903 to 6cd0fe8 Compare November 8, 2024 05:45
@xusd320 xusd320 closed this Nov 8, 2024
@xusd320 xusd320 force-pushed the feat/keep-unresolved-nodejs-require branch from 6cd0fe8 to eacee04 Compare November 8, 2024 08:23
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.

1 participant