Improve bundle tracing and tree-shaking for Shape defaults#7348
Conversation
…path between the "from" and "to" components rather than "index.js" and "to"
WalkthroughThis PR migrates two build scripts to ESM with a consistent execution guard pattern, refactors the trace-bundle utility to export reusable pathfinding functions, improves its BFS algorithm with pruning and memoization, and enables multi-source/target bundle tracing with comprehensive tests. ChangesESM Migration & Trace-Bundle Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Bundle ReportBundle size has no change ✅ |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/trace-bundle.ts (1)
29-32: 💤 Low valueConsider extracting
isExecutedAsScript()to a shared module.This helper is duplicated verbatim in
treeshaking.ts. For two script files this is acceptable, but if more scripts adopt this pattern, consider exporting it from a shared utility.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/trace-bundle.ts` around lines 29 - 32, The helper function isExecutedAsScript is duplicated across modules; extract it into a shared utility module (e.g., utils or script-utils) and export it so both trace-bundle and the treeshaking module can import it. Update the current isExecutedAsScript definition in trace-bundle (and remove the duplicate in the other module) to import the shared function instead, ensuring the implementation and behavior remain identical (uses process.argv[1] and path.resolve). Add a brief unit test or usage example in the shared module to validate correct behavior when executed as a script.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@scripts/trace-bundle.ts`:
- Around line 29-32: The helper function isExecutedAsScript is duplicated across
modules; extract it into a shared utility module (e.g., utils or script-utils)
and export it so both trace-bundle and the treeshaking module can import it.
Update the current isExecutedAsScript definition in trace-bundle (and remove the
duplicate in the other module) to import the shared function instead, ensuring
the implementation and behavior remain identical (uses process.argv[1] and
path.resolve). Add a brief unit test or usage example in the shared module to
validate correct behavior when executed as a script.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d39e2303-3205-4c7a-8c77-7cb4ea4e1e2a
📒 Files selected for processing (4)
package.jsonscripts/trace-bundle.tsscripts/treeshaking.test.tsscripts/treeshaking.ts
|
Tip All tests passed and all changes approved!🟢 UI Tests: 193 tests unchanged |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7348 +/- ##
=======================================
Coverage 89.03% 89.03%
=======================================
Files 548 548
Lines 40522 40522
Branches 5570 5570
=======================================
Hits 36079 36079
Misses 4434 4434
Partials 9 9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
1 similar comment
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
|
My AI pushed too many things in this branch, I will fix |
c65fbee to
b26c27a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/treeshaking.test.ts`:
- Around line 183-194: The test at scripts/treeshaking.test.ts assumes a
deterministic order from findShortestPaths which makes it flaky; update the
assertion to be order-insensitive by normalizing both actual and expected
results before comparing: for each path array returned by
findShortestPaths(area[0].id, dot[0].id, nodeById, 8) sort the file-string
entries (or join them) and then compare the multiset of paths (sort the list of
normalized paths or compare via Sets) against the similarly-normalized expected
array so the test passes regardless of traversal order. Ensure you reference
findShortestPaths and nodeById when locating the test to change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 697bd6cb-1994-48e1-bd23-30ca6281aa0d
📒 Files selected for processing (1)
scripts/treeshaking.test.ts
| expect(findShortestPaths(area[0].id, dot[0].id, nodeById, 8)).toEqual([ | ||
| [ | ||
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | ||
| path.resolve(__dirname, '..', 'src', 'component', 'Dots.tsx'), | ||
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | ||
| ], | ||
| [ | ||
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | ||
| path.resolve(__dirname, '..', 'src', 'component', 'ActivePoints.tsx'), | ||
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | ||
| ], | ||
| ]); |
There was a problem hiding this comment.
Make shortest-path assertion order-insensitive to avoid flaky tests.
On Line 183, the test assumes deterministic ordering of returned paths. If graph traversal order changes, this can fail despite correct behavior.
Suggested change
- expect(findShortestPaths(area[0].id, dot[0].id, nodeById, 8)).toEqual([
+ const shortestPaths = findShortestPaths(area[0].id, dot[0].id, nodeById, 8);
+ expect(shortestPaths).toHaveLength(2);
+ expect(shortestPaths).toEqual(expect.arrayContaining([
[
path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'),
path.resolve(__dirname, '..', 'src', 'component', 'Dots.tsx'),
path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'),
],
[
path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'),
path.resolve(__dirname, '..', 'src', 'component', 'ActivePoints.tsx'),
path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'),
],
- ]);
+ ]));📝 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.
| expect(findShortestPaths(area[0].id, dot[0].id, nodeById, 8)).toEqual([ | |
| [ | |
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'component', 'Dots.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | |
| ], | |
| [ | |
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'component', 'ActivePoints.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | |
| ], | |
| ]); | |
| const shortestPaths = findShortestPaths(area[0].id, dot[0].id, nodeById, 8); | |
| expect(shortestPaths).toHaveLength(2); | |
| expect(shortestPaths).toEqual(expect.arrayContaining([ | |
| [ | |
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'component', 'Dots.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | |
| ], | |
| [ | |
| path.resolve(__dirname, '..', 'src', 'cartesian', 'Area.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'component', 'ActivePoints.tsx'), | |
| path.resolve(__dirname, '..', 'src', 'shape', 'Dot.tsx'), | |
| ], | |
| ])); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/treeshaking.test.ts` around lines 183 - 194, The test at
scripts/treeshaking.test.ts assumes a deterministic order from findShortestPaths
which makes it flaky; update the assertion to be order-insensitive by
normalizing both actual and expected results before comparing: for each path
array returned by findShortestPaths(area[0].id, dot[0].id, nodeById, 8) sort the
file-string entries (or join them) and then compare the multiset of paths (sort
the list of normalized paths or compare via Sets) against the
similarly-normalized expected array so the test passes regardless of traversal
order. Ensure you reference findShortestPaths and nodeById when locating the
test to change.
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Summary
tsxand keep the trace-bundle tests aligned with that flowshapeTypeselector fromShapeso each chart component provides its own default rendererAreano longer reachesRectanglethroughActiveShapeUtilsSummary by CodeRabbit
Chores
Tests