-
Notifications
You must be signed in to change notification settings - Fork 85
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: auto resolve entry file extension #1718
Conversation
Walkthrough此次变更涉及对 Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
WalkthroughThis pull request introduces a feature to automatically resolve entry file extensions in the configuration. It modifies the logic to dynamically check for JavaScript extensions when determining entry files, enhancing flexibility and reducing the need for hardcoded paths. Changes
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (1)
crates/mako/src/config.rs (1)
337-344
: 建议优化默认入口文件的查找逻辑当前实现是可行的,但可以通过以下方式优化:
- 使用
find_map
替代嵌套循环- 提取路径数组为常量
建议重构为:
-let file_paths = ["src/index", "index"]; -'outer: for file_path in file_paths { - for ext in JS_EXTENSIONS { - let file_path = root.join(file_path).with_extension(ext); - if file_path.exists() { - config.entry.insert("index".to_string(), file_path); - break 'outer; - } - } -} +const DEFAULT_ENTRY_PATHS: &[&str] = &["src/index", "index"]; +if let Some(file_path) = DEFAULT_ENTRY_PATHS + .iter() + .find_map(|path| { + JS_EXTENSIONS.iter().find_map(|ext| { + let file_path = root.join(path).with_extension(ext); + file_path.exists().then_some(file_path) + }) + }) +{ + config.entry.insert("index".to_string(), file_path); +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
crates/mako/src/config.rs
(3 hunks)e2e/fixtures/config.entry/expect.js
(1 hunks)e2e/fixtures/config.entry/mako.config.json
(1 hunks)e2e/fixtures/config.entry/src/soo.ts
(1 hunks)e2e/fixtures/config.entry/src/yoo/index.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- e2e/fixtures/config.entry/src/soo.ts
- e2e/fixtures/config.entry/src/yoo/index.ts
🔇 Additional comments (4)
e2e/fixtures/config.entry/mako.config.json (1)
5-7
: 配置更改展示了新的文件扩展名自动解析功能!
配置文件很好地展示了新旧两种入口配置方式的兼容性:
hoo/hoo
保持了显式的.ts
扩展名soo
和yoo
使用了新的无扩展名方式
e2e/fixtures/config.entry/expect.js (1)
12-13
: 测试用例完整覆盖了新功能!
新增的断言验证了构建系统能够:
- 正确解析无扩展名的入口文件
- 在输出中生成正确的
.js
文件
crates/mako/src/config.rs (2)
77-77
: 复用现有常量是个好选择!
从 build::load
模块导入 JS_EXTENSIONS
常量,避免了重复定义支持的文件扩展名列表。
386-393
: 别名解析逻辑简化得很好!
使用 iter_mut
进行原地更新是个很好的选择,代码简洁且高效。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1718 +/- ##
==========================================
- Coverage 54.92% 54.90% -0.03%
==========================================
Files 178 178
Lines 17843 17856 +13
==========================================
+ Hits 9800 9803 +3
- Misses 8043 8053 +10 ☔ View full report in Codecov by Sentry. |
Close #924
Summary by CodeRabbit
新特性
"soo": "src/soo"
和"yoo": "src/yoo"
。测试
soo.js
和yoo.js
的存在性检查。