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: support runtime global module registry #1574

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

xusd320
Copy link
Contributor

@xusd320 xusd320 commented Sep 6, 2024

Close #1559

Summary by CodeRabbit

  • 新功能

    • 添加了全局模块注册功能,用户可以在配置中启用或禁用此选项。
    • 新增了多个模块和配置文件,以支持全局模块注册的逻辑和测试。
  • 文档

    • 更新了文档,新增了关于全局模块注册选项的说明,提供用户更多的模块管理控制。
  • 修复

    • 改进了模块管理逻辑,以便更灵活地处理模块的加载和注册。

@xusd320 xusd320 requested a review from sorrycc September 6, 2024 06:55
Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Walkthrough

此次更改引入了一个新的布尔字段 global_module_registry,用于管理全局模块注册。该字段被添加到多个结构体中,并在运行时和配置文件中得到了相应的集成。这些更改旨在增强模块管理的灵活性,允许在多入口的环境中共享模块,从而优化资源的使用和加载策略。

Changes

文件路径 更改摘要
crates/mako/src/config/config.rs 新增布尔字段 global_module_registryOutputConfig 结构体,更新默认配置字符串。
crates/mako/src/generate/chunk_pot/util.rs runtime_code 函数中添加 global_module_registry 字段,增强模块管理能力。
crates/mako/src/generate/runtime.rs AppRuntimeTemplate 结构体中新增 global_module_registry 字段,影响实例化和状态管理。
crates/mako/templates/app_runtime.stpl 根据 global_module_registry 的值条件初始化 modulesRegistry 变量,优化模块注册逻辑。
e2e/fixtures/config.global-module-registry/expect.js 新增测试文件 expect.js,验证全局模块注册功能,确保两个模块的公共导出一致。
e2e/fixtures/config.global-module-registry/mako.config.json 新增配置文件 mako.config.json,定义多个模块的入口点及全局模块注册选项。
e2e/fixtures/config.global-module-registry/src/common.ts 新增导出常量 common,提供共享配置。
e2e/fixtures/config.global-module-registry/src/entryA.ts 新增模块 entryA.ts,导出 common 实体,简化导入路径。
e2e/fixtures/config.global-module-registry/src/entryB.ts 新增模块 entryB.ts,导出 common 实体,优化模块导出结构。

Assessment against linked issues

Objective Addressed Explanation
共享模块注册跨多个入口 (#1559)
允许运行时获取全局模块注册表的选项 (#1559)

🐰 在草地上跳跃欢快,
新模块注册来助力,
共享资源如春风,
代码清晰又灵动,
兔子乐在其中,
欢庆新变化,心中喜悦。 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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
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, codebase verification and nitpick comments (1)
crates/mako/src/generate/runtime.rs (1)

15-15: 结构体修改审查

AppRuntimeTemplate 结构体新增了一个布尔字段 global_module_registry,用于启用/禁用全局模块注册表功能。建议为此字段添加适当的文档,说明其用途和工作方式,以便于其他开发者理解和使用。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b447d1 and 93e912c.

Files selected for processing (9)
  • crates/mako/src/config/config.rs (2 hunks)
  • crates/mako/src/generate/chunk_pot/util.rs (1 hunks)
  • crates/mako/src/generate/runtime.rs (1 hunks)
  • crates/mako/templates/app_runtime.stpl (1 hunks)
  • e2e/fixtures/config.global-module-registry/expect.js (1 hunks)
  • e2e/fixtures/config.global-module-registry/mako.config.json (1 hunks)
  • e2e/fixtures/config.global-module-registry/src/common.ts (1 hunks)
  • e2e/fixtures/config.global-module-registry/src/entryA.ts (1 hunks)
  • e2e/fixtures/config.global-module-registry/src/entryB.ts (1 hunks)
Files skipped from review due to trivial changes (3)
  • e2e/fixtures/config.global-module-registry/src/common.ts
  • e2e/fixtures/config.global-module-registry/src/entryA.ts
  • e2e/fixtures/config.global-module-registry/src/entryB.ts
Additional comments not posted (5)
e2e/fixtures/config.global-module-registry/expect.js (1)

1-4: 测试实现审查

此测试通过 require 加载模块并使用 assert 断言不同入口点的模块实例是否相同,直接关联到 PR 的目标。测试实现简单且恰当,适合验证全局模块注册表的功能。

e2e/fixtures/config.global-module-registry/mako.config.json (1)

1-25: 配置设置审查

此配置文件结构清晰,包括了入口定义、代码分割策略和全局模块注册表选项。globalModuleRegistry 选项设置为 true,符合 PR 的目标,支持新功能的测试。配置设置适当,支持所引入的功能。

crates/mako/src/generate/chunk_pot/util.rs (1)

118-118: 新增字段 global_module_registry 已正确集成

代码更改已经通过审查。请确保 global_module_registry 字段的集成不会影响现有功能。

运行以下脚本以验证新字段的集成:

Verification successful

global_module_registry 字段已正确集成

global_module_registry 字段在代码库中的集成是正确的,并且没有对现有功能产生负面影响。该字段在多个文件中定义和使用,符合其作为全局模块注册表的用途。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 `global_module_registry` 字段的集成。

# 测试:搜索函数使用。预期:只有新签名的出现。
rg --type rust -A 5 $'global_module_registry'

Length of output: 1051

crates/mako/templates/app_runtime.stpl (1)

2-8: 条件块正确实现

createRuntime 函数中的条件块已经正确实现,允许基于全局上下文灵活管理模块。请确保此逻辑不会引入任何副作用。

运行以下脚本以验证条件逻辑的正确性:

Verification successful

条件逻辑正确实现

在模板文件中的条件逻辑已正确实现,与 hmr_runtime.js 中的模块管理使用模式一致。modulesRegistry 的初始化确保了在热模块替换场景中模块状态的正确管理。无需进一步操作。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 `modulesRegistry` 的条件逻辑。

# 测试:搜索条件块使用。预期:只有正确的条件逻辑。
rg --type rust -A 5 $'modulesRegistry'

Length of output: 37


Script:

#!/bin/bash
# 描述:验证 `modulesRegistry` 的条件逻辑。

# 测试:搜索模板文件或 JavaScript 文件中的条件块使用。
rg --type js --type-add 'template:*.stpl' -A 5 'modulesRegistry'

Length of output: 3679

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

125-125: 新增布尔字段 global_module_registry 已正确集成

OutputConfig 结构中的新增字段已经通过审查。请确保此字段的集成不会影响现有功能。

运行以下脚本以验证新字段的集成:

Verification successful

global_module_registry 字段已成功集成

OutputConfig 结构中新增的 global_module_registry 字段已正确集成,并在代码库中被使用。没有发现任何影响现有功能的问题。

  • crates/mako/src/config/config.rs: 字段声明。
  • crates/mako/src/generate/chunk_pot/util.rs: 字段使用。
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 `global_module_registry` 字段的集成。

# 测试:搜索结构使用。预期:只有新字段的出现。
rg --type rust -A 5 $'global_module_registry'

Length of output: 1051

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.01%. Comparing base (f95e626) to head (da64525).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1574      +/-   ##
==========================================
+ Coverage   61.92%   62.01%   +0.08%     
==========================================
  Files         127      127              
  Lines       15311    15347      +36     
==========================================
+ Hits         9481     9517      +36     
  Misses       5830     5830              

☔ 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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 93e912c and da64525.

Files selected for processing (2)
  • docs/config.md (1 hunks)
  • docs/config.zh-CN.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • docs/config.zh-CN.md

@@ -12,4 +12,5 @@ pub struct AppRuntimeTemplate {
pub is_browser: bool,
pub concatenate_enabled: bool,
pub cross_origin_loading: Option<String>,
pub global_module_registry: bool,
Copy link
Member

Choose a reason for hiding this comment

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

guess: how many fields will be hold in this struct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know ...

@xusd320 xusd320 requested a review from stormslowly September 6, 2024 09:12
@xusd320 xusd320 merged commit 60f8c90 into master Sep 9, 2024
19 checks passed
@xusd320 xusd320 deleted the feat/runtime-global-module-registry branch September 9, 2024 02:53
This was referenced Sep 13, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 17, 2024
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.

[Feature Request]: share moduleRegistry cross multi entries
2 participants