Bug: Skip re-processing already transformed config files for CSF factories#34273
Conversation
|
View your CI Pipeline Execution ↗ for commit 99d3ce0
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the CSF factories codemod by avoiding unnecessary re-printing/re-formatting when a config file is already in the target defineMain/definePreview form, preventing platform-specific line-ending churn (notably on Windows).
Changes:
- Adds an early-return check that detects
export default defineMain(...)/export default definePreview(...)and returns the original source when no named exports need merging.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDetects when a config file is already a CSF factory export (e.g., Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/lib/cli-storybook/src/codemod/helpers/config-to-csf-factory.ts`:
- Around line 45-47: The early return that checks isAlreadyTransformed and
!hasNamedExports (returning info.source) can skip the import normalization/fixup
logic; change the guard in that conditional (around isAlreadyTransformed and
hasNamedExports) so it only returns early when the module's required framework
imports are already present and valid, or alternatively move/ensure the
import-normalization code (the import fixup block) runs before returning; locate
the conditional using the symbols isAlreadyTransformed, hasNamedExports, and
info.source and adjust it so files like export default defineMain({}) still go
through the import repair path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 585c4df8-5b94-4fdd-a71f-a3581c66247d
📒 Files selected for processing (1)
code/lib/cli-storybook/src/codemod/helpers/config-to-csf-factory.ts
…ry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…bookjs/storybook into fix/recast_windows_lf_crlf
Bug: Skip re-processing already transformed config files for CSF factories (cherry picked from commit da2f32e)
…orues
Fix in next release
What I did
configTOCsfFactorieshad no early return for already transformed codeTHe failing test was for
the test title state that there's nothing to change but the issue is that
dedentapplies \n to the code, thentransformappliesrecastuppon the code which apply platform line break. on windows it would be\r\n. Then the test would breakChecklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit