-
Notifications
You must be signed in to change notification settings - Fork 21
refactor(utils): Extract packages - use forEach instead of reduce #4288
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
base: master
Are you sure you want to change the base?
Conversation
#12464 Bundle Size — 382.46KiB (0%).c443349(current) vs 19b2c70 master#12458(baseline) Warning Bundle contains 2 duplicate packages – View duplicate packages Bundle metrics
|
| Current #12464 |
Baseline #12458 |
|
|---|---|---|
334.85KiB |
334.85KiB |
|
47.61KiB |
47.61KiB |
|
0% |
28.65% |
|
3 |
3 |
|
4 |
4 |
|
701 |
701 |
|
0 |
0 |
|
0% |
0% |
|
39 |
39 |
|
1 |
1 |
Bundle size by type no changes
| Current #12464 |
Baseline #12458 |
|
|---|---|---|
334.85KiB |
334.85KiB |
|
47.61KiB |
47.61KiB |
Bundle analysis report Branch refactor-package-extraction Project dashboard
Generated by RelativeCI Documentation Report issue
6bdd18b to
b167eed
Compare
WalkthroughThe pull request refactors the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 0
🧹 Nitpick comments (2)
packages/utils/src/webpack/extract/modules-packages.ts (2)
114-117: Update the comment to accurately reflect the logic.The comment "Same package name, but different paths" is misleading as the code is actually checking for packages with the same path, which could indicate symlinks.
- // Same package name, but different paths (eg: symlinks) + // Check for packages with the same path (eg: symlinks)
131-137: Consider simplifying the max calculation.The max calculation could be simplified using optional chaining and more descriptive variable names.
- const lastIndex = - max( - Object.keys(packages) - .map((id) => id.split('~')) - .filter(([id]) => id === packageMeta.id) - .map(([__, index]) => parseInt(index, 10)), - ) || 0; + const existingIndices = Object.keys(packages) + .map((id) => id.split('~')) + .filter(([id]) => id === packageMeta.id) + .map(([__, index]) => parseInt(index, 10)); + const lastIndex = max(existingIndices) ?? 0;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/utils/src/webpack/extract/modules-packages.ts(1 hunks)
🔇 Additional comments (3)
packages/utils/src/webpack/extract/modules-packages.ts (3)
82-82: LGTM! Clean initialization with proper type annotation.
84-90: Great refactor! The forEach implementation improves readability.The control flow is now more straightforward with clear early returns for invalid cases. This is a good example of choosing the right tool for the job - forEach is more intuitive than reduce for this use case.
84-146: Verify test coverage for the refactored implementation.While the refactoring improves readability and maintainability, let's ensure all edge cases are still covered by the test suite.
✅ Verification successful
Test coverage verified successfully
The test suite comprehensively covers all scenarios in the refactored implementation, including package identification, value accumulation, path handling, and duplicate package scenarios. The refactoring maintains full compatibility with existing test cases.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for related test files fd -e test.ts -e spec.ts modules-packages # Look for test cases covering different package scenarios rg -A 5 "describe.*modules-packages"Length of output: 82
Script:
#!/bin/bash # Search for test files in the webpack/extract directory with various extensions fd -e test.ts -e spec.ts -e test.tsx -e spec.tsx . packages/utils/src/webpack/extract # Search for files importing or using modules-packages rg -l "modules-packages" packages/utils/src # Search for test cases mentioning packages or modules extraction rg -A 5 "describe.*\b(package|module|extract)" packages/utils/srcLength of output: 11133
Script:
#!/bin/bash # Get the content of the main test file cat packages/utils/src/webpack/extract/__tests__/modules-packages.tsLength of output: 11330
b167eed to
c443349
Compare
Summary by CodeRabbit