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

fix: entry support sub paths #1547

Merged
merged 1 commit into from
Aug 29, 2024
Merged

fix: entry support sub paths #1547

merged 1 commit into from
Aug 29, 2024

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Aug 28, 2024

e.g.

{
  "entry": { "foo/foo": "src/foo.ts" }
}

需求方:式夏

Summary by CodeRabbit

  • 新功能

    • 添加了新的模块映射 "hoo/hoo" 至配置文件,扩展了构建过程的功能。
    • 引入了新的 hoo.ts 文件,提供简单的日志记录功能。
    • 新增 TransformOutput 接口,提升了类型安全性和清晰度。
  • 改进

    • 重构了文件写入逻辑,提升了代码可读性和可维护性。
    • 增强了测试覆盖率,确保模块 hoo/hoo.js 在配置中被正确包含。
    • 改进了构建结果解析功能,支持处理嵌套目录中的文件。

Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

此次更改涉及多处文件的重构和增强,包括引入新的辅助函数以改善文件写入逻辑、增加对模块的测试覆盖、扩展配置文件以支持新源文件、添加接口以增强类型定义、以及改进构建结果解析功能以处理嵌套目录。这些更改共同提升了代码的可维护性和测试的全面性。

Changes

文件路径 更改摘要
crates/mako/src/generate.rs 重构 emit_chunk_file 函数,新增 write_to_file 辅助函数以简化文件写入逻辑。
e2e/fixtures/config.entry/expect.js 增加断言以验证 names 数组中包含模块 hoo/hoo.js
e2e/fixtures/config.entry/mako.config.json entry 对象中新增 "hoo/hoo": "src/hoo.ts" 映射。
e2e/fixtures/config.entry/src/hoo.ts 新增文件 hoo.ts,包含简单的日志输出功能。
packages/mako/binding.d.ts 新增接口 TransformOutput,包含 code 和可选的 map 属性。
scripts/test-utils.js 改进 parseBuildResult 函数以支持读取 dist 目录中的嵌套文件。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Config
    participant FileSystem
    participant TestUtils

    User->>Config: Add new entry for "hoo/hoo"
    Config->>FileSystem: Update configuration file
    User->>TestUtils: Run tests
    TestUtils->>FileSystem: Verify module inclusion
    FileSystem-->>TestUtils: Return results
    TestUtils->>User: Report test outcomes
Loading

🐇 在代码的世界里跳跃,
文件与函数齐舞蹈。
新增模块与接口,
让程序更聪明更高效。
兔子欢呼,代码更美妙! ✨


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c6eb7be and 45758fe.

Files selected for processing (6)
  • crates/mako/src/generate.rs (4 hunks)
  • e2e/fixtures/config.entry/expect.js (1 hunks)
  • e2e/fixtures/config.entry/mako.config.json (1 hunks)
  • e2e/fixtures/config.entry/src/hoo.ts (1 hunks)
  • packages/mako/binding.d.ts (1 hunks)
  • scripts/test-utils.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • e2e/fixtures/config.entry/src/hoo.ts
Additional comments not posted (16)
e2e/fixtures/config.entry/mako.config.json (2)

4-4: 代码更改通过!

该行正确地添加了一个新的条目 foo,与现有结构一致。

代码更改已通过。


5-5: 代码更改通过!

该行正确地添加了一个新的条目 hoo/hoo,并保持了 JSON 结构。

代码更改已通过。

e2e/fixtures/config.entry/expect.js (1)

11-11: 代码更改通过!

该行正确地添加了一个断言,以确保 names 数组中存在 hoo/hoo.js

代码更改已通过。

scripts/test-utils.js (12)

10-10: 代码更改通过!

该行正确地初始化了变量 fileOrDir 以处理文件和目录。

代码更改已通过。


11-11: 代码更改通过!

该行正确地检查了路径是否为文件。

代码更改已通过。


12-12: 代码更改通过!

该行正确地读取了文件内容。

代码更改已通过。


13-13: 代码更改通过!

该行正确地结束了 if 代码块。

代码更改已通过。


14-14: 代码更改通过!

该行正确地读取了目录的内容。

代码更改已通过。


15-15: 代码更改通过!

该行正确地遍历了目录中的每个文件。

代码更改已通过。


16-16: 代码更改通过!

该行正确地构建了每个子文件的路径。

代码更改已通过。


17-17: 代码更改通过!

该行正确地读取了每个子文件的内容。

代码更改已通过。


18-18: 代码更改通过!

该行正确地指定了读取子文件的编码。

代码更改已通过。


19-19: 代码更改通过!

该行正确地结束了 readFileSync 调用。

代码更改已通过。


20-20: 代码更改通过!

该行正确地结束了 forEach 循环。

代码更改已通过。


21-21: 代码更改通过!

该行正确地结束了 else 代码块。

代码更改已通过。

packages/mako/binding.d.ts (1)

6-9: 新增的 TransformOutput 接口定义正确

接口定义包含必需的 code 属性和可选的 map 属性,符合类型安全和清晰度的要求。

代码更改已批准。

Comment on lines +653 to +659
fn write_to_file(path: &str, content: &Vec<u8>) -> std::io::Result<()> {
if let Some(parent) = std::path::Path::new(path).parent() {
if !parent.exists() {
fs::create_dir_all(parent)?;
}
}
fs::write(path, content)
Copy link
Contributor

Choose a reason for hiding this comment

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

改进错误处理和日志记录

write_to_file 函数正确处理了目录创建和文件写入,但可以通过以下方式进一步改进:

  • 添加目录创建和文件写入的错误处理。
  • 添加文件写入成功的日志记录。

建议应用以下 diff 进行改进:

 fn write_to_file(path: &str, content: &Vec<u8>) -> std::io::Result<()> {
     if let Some(parent) = std::path::Path::new(path).parent() {
         if !parent.exists() {
             fs::create_dir_all(parent).map_err(|e| {
+                eprintln!("Failed to create directory {}: {}", parent.display(), e);
                 e
             })?;
         }
     }
-    fs::write(path, content)
+    fs::write(path, content).map_err(|e| {
+        eprintln!("Failed to write file {}: {}", path, e);
+        e
+    })?;
+    println!("Successfully wrote file {}", path);
+    Ok(())
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn write_to_file(path: &str, content: &Vec<u8>) -> std::io::Result<()> {
if let Some(parent) = std::path::Path::new(path).parent() {
if !parent.exists() {
fs::create_dir_all(parent)?;
}
}
fs::write(path, content)
fn write_to_file(path: &str, content: &Vec<u8>) -> std::io::Result<()> {
if let Some(parent) = std::path::Path::new(path).parent() {
if !parent.exists() {
fs::create_dir_all(parent).map_err(|e| {
eprintln!("Failed to create directory {}: {}", parent.display(), e);
e
})?;
}
}
fs::write(path, content).map_err(|e| {
eprintln!("Failed to write file {}: {}", path, e);
e
})?;
println!("Successfully wrote file {}", path);
Ok(())
}

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.89%. Comparing base (e7b5e07) to head (45758fe).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/generate.rs 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1547      +/-   ##
==========================================
- Coverage   60.97%   60.89%   -0.08%     
==========================================
  Files         126      126              
  Lines       15091    15125      +34     
==========================================
+ Hits         9201     9210       +9     
- Misses       5890     5915      +25     

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

@stormslowly
Copy link
Member

what about /sub1/sub2/sub3

@sorrycc
Copy link
Member Author

sorrycc commented Aug 29, 2024

what about /sub1/sub2/sub3

it's work.

@sorrycc sorrycc merged commit 95a1a21 into master Aug 29, 2024
17 of 18 checks passed
@sorrycc sorrycc deleted the sorrycc-ef01 branch August 29, 2024 03:40
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