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: add stats.modules config to generate modules with deps and dependents #1202

Merged
merged 1 commit into from
May 23, 2024

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented May 23, 2024

1、for #1175 , we need to know the relationship between modules
2、since module concat will modify the module graph, so we need to parse the modules before optimization

Summary by CodeRabbit

  • 新功能

    • 引入了新的统计配置(StatsConfig),允许用户配置模块统计信息。
  • 文档

    • 更新了配置文档,增加了有关 clientComponentTplemitCSSmodules 的描述。
  • 修复

    • 修改了多个配置文件中的 stats 配置,从布尔值更改为包含 modules 属性的对象。
  • 重构

    • 调整了统计信息的处理逻辑,改用 Option<StatsConfig> 代替布尔值。
    • 更新了统计信息的结构和方法,以支持模块统计。
  • 样式

    • 更新了 build.js 文件中的注释,禁用了 moduleIdStrategy: 'hashed' 配置。

@sorrycc sorrycc merged commit 56306fc into master May 23, 2024
2 checks passed
@delete-merged-branch delete-merged-branch bot deleted the sorrycc-2nrx branch May 23, 2024 10:03
Copy link
Contributor

coderabbitai bot commented May 23, 2024

Walkthrough

这些变更主要集中于配置和统计模块的改进。引入了新的 StatsConfig 结构体,并用它替换了原有的布尔类型 stats 字段。此外,还对相关方法和文件进行了相应的调整,以支持新的配置结构。

Changes

文件路径 变更摘要
crates/mako/src/config/config.rs 添加了 StatsConfig 结构体,并将 stats 字段替换为 Option<StatsConfig>
crates/mako/src/features/rsc.rs 移除了 ModuleIdStrategy 导入,新增 module_id 字段,重构了 generate_clientemit_css 方法。
crates/mako/src/generate/mod.rs 更新了 self.context.config.stats 的条件检查,新增了基于 modules 字段的条件块。
crates/mako/src/stats.rs 添加了 ModuleInfo 结构体,更新了 StatsInfo 结构体,新增了 parse_modulesget_modules 方法,调整了相关序列化结构。
docs/config.md 更新了配置文档,新增了 clientComponentTplemitCSS 描述,修改了 stats 的类型描述。
e2e/fixtures/.../mako.config.json 修改了 stats 配置,从布尔值改为包含 modules 字段的对象。
examples/rsc/build.js 修改了 stats 配置,新增了注释以禁用 moduleIdStrategy
packages/bundler-mako/index.js 修改了 makoConfig.stats 的赋值,从布尔值改为包含 modules 字段的对象。

在代码的世界里,变更如春风,
配置与统计,焕然一新。
模块信息,细致入微,
文档更新,清晰明了。
兔子欢腾,代码舞蹈,
未来之路,光辉灿烂。 🌟🐇


Note

Free review on us!

CodeRabbit is offering free reviews until Mon May 27 2024 to showcase some of the refinements we've made.

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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6190de2 and e136264.
Files selected for processing (9)
  • crates/mako/src/config/config.rs (4 hunks)
  • crates/mako/src/features/rsc.rs (4 hunks)
  • crates/mako/src/generate/mod.rs (4 hunks)
  • crates/mako/src/stats.rs (14 hunks)
  • docs/config.md (1 hunks)
  • e2e/fixtures/rsc.client.dynamic_client/mako.config.json (1 hunks)
  • e2e/fixtures/rsc.server/mako.config.json (1 hunks)
  • examples/rsc/build.js (2 hunks)
  • packages/bundler-mako/index.js (1 hunks)
Additional Context Used
LanguageTool (12)
docs/config.md (12)

Near line 17: The word ‘mako’ is not correct in this context. Consider using the plural form, adding a determiner like ‘the’ or ‘a’, or adding a preposition like ‘at’ or ‘in’.
Context: ...s" } } ``` Notice: When you're using mako with Umi, prefer to config the bundler ...


Near line 91: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ... used in server-side rendering scenarios, because when server-side rendering, you don't n...


Near line 138: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...ing a pure server-side rendering project, because assets files are not needed at this tim...


Near line 268: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ... configuration can only be used with umd, because injecting CSS is not a recommended way ...


Near line 326: Loose punctuation mark.
Context: ... Output related configuration. - path, output directory - mode, output mode,...


Near line 341: Loose punctuation mark.
Context: ...on items are supported. - skipModules, optimize the size by skipping modules w...


Near line 351: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...o set dynamicImportToRequire to true, because the runtime does not yet support node-s...


Near line 394: Loose punctuation mark.
Context: ...r to enable px2rem conversion. - root, root font size, default is 100 - `pro...


Near line 442: Loose punctuation mark.
Context: ... } resolveconfiguration. -alias, alias configuration - extensions`, fil...


Near line 474: Loose punctuation mark.
Context: ...iguration items: - clientComponentTpl, client component template, use `{{path}...


Near line 475: Loose punctuation mark.
Context: ...resent the id of the module. - emitCSS, whether to output CSS components. ### ...


Near line 486: Loose punctuation mark.
Context: ... Child configuration items: - modules, whether to generate module information,...

Additional comments not posted (29)
e2e/fixtures/rsc.client.dynamic_client/mako.config.json (1)

10-12: 配置更新正确,将 stats 从布尔值更改为对象,并添加了 modules 属性,以支持更细粒度的统计配置。

e2e/fixtures/rsc.server/mako.config.json (1)

7-9: 配置更新正确,将 stats 从布尔值更改为对象,并添加了 modules 属性,以支持更细粒度的统计配置。

examples/rsc/build.js (2)

32-34: 配置更新正确,将 stats 从布尔值更改为对象,并添加了 modules 属性,以支持更细粒度的统计配置。


73-75: 配置更新正确,将 stats 从布尔值更改为对象,并添加了 modules 属性,以支持更细粒度的统计配置。

crates/mako/src/features/rsc.rs (3)

21-24: 更新了 RscCssModules 结构,添加了 module_idmodules 字段,以支持模块的更好处理和配置。


62-66: 更新了 generate_client 函数,以使用新的模块 ID 字段。这与 PR 目标一致,旨在增强模块处理和配置。


94-97: 更新了 emit_css 函数,以使用新的 module_idmodules 字段。这与 PR 目标一致,旨在增強模块处理和配置。

docs/config.md (1)

472-487: 文档更新正确,反映了新的 stats 配置结构。这与 PR 目标一致,旨在提供更细粒度的统计配置。

packages/bundler-mako/index.js (1)

25-27: 配置更新正确,将 stats 从布尔值更改为对象,并添加了 modules 属性,以支持更细粒度的统计配置。

crates/mako/src/stats.rs (14)

7-7: 增加了对 ArcMutex 的使用,以支持线程安全的数据访问。这是处理并发数据访问的常见做法。


17-17: 引入了新的模块和上下文依赖,这有助于管理和使用不同的功能模块。


44-49: 定义了新的 ModuleInfo 结构,用于存储模块的 ID、依赖项和依赖者。这是对模块信息管理的一个重要扩展。


56-56: 在 StatsInfo 结构中添加了 modules 字段,用于存储模块信息。使用 Mutex 保证线程安全。


65-65: 初始化 modules 为一个新的空 HashMap,这是对 StatsInfo 结构的逻辑扩展。


96-120: 实现了 parse_modules 方法,用于解析模块依赖和依赖者信息。这个方法通过读取模块图来构建每个模块的 ModuleInfo,并将其存储在 modules 中。这是模块信息处理的核心功能。


122-124: 实现了 get_modules 方法,返回一个包含所有模块信息的 HashMap。这提供了一个访问所有模块数据的接口。


173-175: 定义了 StatsJsonModuleItem 结构,用于序列化模块信息。这有助于将模块数据转换为 JSON 格式,以便于传输和存储。


177-178: 定义了 StatsJsonChunkModuleItem 结构,用于处理和存储块模块的信息。这是对模块信息管理的进一步扩展。


202-202: 在 StatsJsonChunkItem 结构中添加了 modules 字段,用于存储关联的模块信息。这有助于在处理块数据时保持模块的关联性。


220-221: 在 StatsJsonMap 结构中添加了 chunk_modulesmodules 字段,用于存储块模块和模块信息。这是对统计信息结构的重要扩展。


238-239: 初始化 moduleschunk_modules 为新的空集合,这是对 StatsJsonMap 结构的逻辑扩展。


306-306: 在 create_stats_info 函数中,如果配置中启用了统计信息,将调用 write_stats 函数。这确保了只有在需要时才生成和写入统计信息。


431-433: 在 create_stats_info 函数中,从 modules_vec 中收集所有模块信息,并将其存储在 chunk_modules 中。这是对模块信息处理的最终步骤。

crates/mako/src/generate/mod.rs (4)

73-81: 在生成过程中,如果配置启用了模块统计,将调用 parse_modules 方法。这是对模块解析逻辑的直接集成,确保在生成之前正确处理模块依赖信息。


177-177: 在生成统计信息之前,检查配置是否启用了统计。这是一个好的实践,确保只在需要时执行相关操作。


261-269: 在热更新生成过程中,同样检查了统计配置,并在启用的情况下解析模块。这保持了与常规生成过程的一致性,并确保了热更新时模块依赖的正确处理。


306-306: 在热更新过程中,如果配置启用了统计,将生成并写入统计信息。这与常规生成流程保持一致,确保了统计信息的正确生成和更新。

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

190-193: 新增 StatsConfig 结构体,用于更细粒度地控制统计配置,特别是模块统计的启用与禁用。这一变更与 PR 目标一致,即允许对统计进行更详细的配置。


439-439: 修改 Config 结构体中的 stats 字段,从布尔值改为 Option<StatsConfig> 类型。这一改动是为了支持新引入的 StatsConfig 结构体,允许通过设置为 None 来显式禁用统计,或在为 Some 时进行更细粒度的配置。这一变更是支持 PR 描述的新功能所必需的。

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