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

Revert "refactor: define env (#1499)" #1504

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Aug 16, 2024

This reverts commit 845ce1e.

Summary by CodeRabbit

  • 新功能

    • 改善了环境变量的处理方式,提升了内存效率并允许共享引用。
    • 提供了更通用的环境变量访问方法,支持在Node和浏览器环境之间区分。
  • 修复

    • 更新了测试用例,确保未定义环境变量的处理正确。

Copy link
Contributor

coderabbitai bot commented Aug 16, 2024

Walkthrough

此次更改主要集中在环境变量的处理上,通过简化环境变量引用和改进内存管理,提升了代码的性能与可维护性。EnvReplacer 结构体和相关方法的更新使得环境变量的定义、访问更加高效,并通过新增的 get_env 方法提高了对不同环境的支持。整体上,这些更改旨在优化 Transform 实现。

Changes

文件 更改摘要
crates/mako/src/build/transform.rs 简化环境变量引用,使用 NODE_ENV 代替 process.env.NODE_ENV,并将 EnvReplacer 的实例化更新为 Lrc::new(env_map)
crates/mako/src/visitors/env_replacer.rs HashMap<String, Expr> 替换为 Lrc<AHashMap<JsWord, Expr>>,更新 new 构造函数以支持新的环境变量映射,替换 get_define_envget_env,并重构 visit_mut_expr 方法以适应新环境结构。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Transform
    participant EnvReplacer

    User->>Transform: 请求环境变量
    Transform->>EnvReplacer: 获取环境映射
    EnvReplacer->>EnvReplacer: 解析环境变量
    EnvReplacer-->>Transform: 返回环境变量
    Transform-->>User: 返回请求结果
Loading

Poem

在兔子洞中欢呼雀跃,
变量的变化如春风拂面,
NODE_ENV轻松可得,
Lrc管理更聪明、稳健。
代码如花,盛开绚烂,
祝贺更新,乐无边! 🐰✨


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 as 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.

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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a79424 and cacce47.

Files selected for processing (2)
  • crates/mako/src/build/transform.rs (2 hunks)
  • crates/mako/src/visitors/env_replacer.rs (5 hunks)
Additional comments not posted (7)
crates/mako/src/visitors/env_replacer.rs (6)

27-32: 结构体 EnvReplacer 的更改看起来不错。

使用 Lrc<AHashMap<JsWord, Expr>> 提高了内存效率并支持共享引用。


36-54: 构造函数 new 的更改看起来不错。

初始化 meta_envs 并将 NODE_ENV 转换为 MODE 的逻辑是合理的。


58-62: 方法 get_env 的更改看起来不错。

通过使用枚举来区分 Node 和 Browser 环境,增强了代码的可维护性。


66-171: 方法 visit_mut_expr 的更改看起来不错。

这些更改简化了环境变量的解析过程,并有效处理了 process.envimport.meta.env 的情况。


181-186: 函数 build_env_map 的更改看起来不错。

返回类型的更改与 EnvReplacer 结构体中 AHashMap 的使用保持一致,增强了一致性。


362-383: 测试用例的更改看起来不错。

更新和新增的测试用例确保了对更改的充分测试,并涵盖了边缘情况。

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

122-128: 方法 transform 的更改看起来不错。

使用 Lrc::new(env_map) 改进了内存管理和共享所有权,有助于提升性能。

@stormslowly stormslowly merged commit 4db869a into master Aug 16, 2024
12 checks passed
@stormslowly stormslowly deleted the fix/revert_define_refactory branch August 16, 2024 07:47
xusd320 added a commit that referenced this pull request Aug 19, 2024
Jinbao1001 pushed a commit that referenced this pull request Aug 21, 2024
* Reapply "refactor: define env (#1499)" (#1504)

This reverts commit 4db869a.

* feat: reapply 1499 and fix import meta env

* fix: complicated define env replace
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