CLI: Skip a11y addon automigration prompting when not applicable#35376
Conversation
…ng to do The check only evaluated the "already migrated" skip conditions when both .storybook/vitest.setup.* and .storybook/preview.* existed. Projects without a vitest.setup file (the norm since the vitest plugin auto-provisions preview annotations in 10.3+) were always prompted, even when preview already had parameters.a11y.test configured — and running the migration was a no-op. The skip flags are now computed independently per file: a missing setup file counts as nothing-to-transform on the setup side, and the preview file is checked on its own. This also fixes re-transforming an already-migrated setup file (duplicate a11yAddonAnnotations import) when no preview file existed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe automigration for the a11y addon test now computes ChangesIndependent Skip-Flag Migration Logic
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.ts (1)
80-96: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueFiles are read twice (once here, once in
getTransformedSetupCode/getTransformedPreviewCode).
vitestSetupFile/previewFileare each read viareadFileSynchere to compute skip flags, then read again insidegetTransformedSetupCode/getTransformedPreviewCode(Lines 108, 121) if not skipped. Since this pattern predates this diff, it's not a regression, but caching the source read once would avoid redundant I/O and reduce inconsistency risk (e.g., file changing between reads).🤖 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 `@code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.ts` around lines 80 - 96, The `add`/skip-flag logic in `addon-a11y-addon-test.ts` reads `vitestSetupFile` and `previewFile` twice, once in this precheck block and again in `getTransformedSetupCode`/`getTransformedPreviewCode`. Refactor the flow so the file contents are read once, cached, and reused to compute `skipVitestSetupTransformation`/`skipPreviewTransformation` and to feed the transformation helpers, avoiding duplicate `readFileSync` calls and inconsistent reads.
🤖 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 `@code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.ts`:
- Around line 198-232: The current coverage only exercises the case where
vitest.setup is missing and the preview file is already transformed, but it
misses the mirrored path where previewFile is absent and vitest.setup is already
migrated. Add a symmetric test in addonA11yAddonTest.check that mocks the
preview file as missing while providing a migrated vitest.setup, and assert it
returns null; this will cover the skipPreviewTransformation default behavior in
the same check flow.
In `@code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.ts`:
- Around line 77-100: The default handling for preview transformation is
incomplete in check(), causing a migration result even when previewFile is
absent. Update add-on-a11y addon test logic so skipPreviewTransformation is
initialized from !previewFile, and keep the existing preview-file
read/shouldPreviewFileBeTransformed flow only when previewFile exists. Verify
the early return in check() now skips the auto flow when both transformations
are unavailable, and add a test covering the missing-preview case.
---
Nitpick comments:
In `@code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.ts`:
- Around line 80-96: The `add`/skip-flag logic in `addon-a11y-addon-test.ts`
reads `vitestSetupFile` and `previewFile` twice, once in this precheck block and
again in `getTransformedSetupCode`/`getTransformedPreviewCode`. Refactor the
flow so the file contents are read once, cached, and reused to compute
`skipVitestSetupTransformation`/`skipPreviewTransformation` and to feed the
transformation helpers, avoiding duplicate `readFileSync` calls and inconsistent
reads.
🪄 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: 7c36610b-bcd6-430d-b1f5-3c41b996b152
📒 Files selected for processing (2)
code/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.test.tscode/lib/cli-storybook/src/automigrate/fixes/addon-a11y-addon-test.ts
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 73 | 72 | 🎉 -1 🎉 |
| Self size | 21.95 MB | 21.94 MB | 🎉 -16 KB 🎉 |
| Dependency size | 36.65 MB | 36.44 MB | 🎉 -213 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/cli
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 205 | 204 | 🎉 -1 🎉 |
| Self size | 825 KB | 821 KB | 🎉 -4 KB 🎉 |
| Dependency size | 92.16 MB | 91.93 MB | 🎉 -229 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
@storybook/codemod
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 198 | 197 | 🎉 -1 🎉 |
| Self size | 32 KB | 32 KB | 🚨 +4 B 🚨 |
| Dependency size | 90.64 MB | 90.41 MB | 🎉 -229 KB 🎉 |
| Bundle Size Analyzer | Link | Link |
create-storybook
| Before | After | Difference | |
|---|---|---|---|
| Dependency count | 74 | 73 | 🎉 -1 🎉 |
| Self size | 1.09 MB | 1.09 MB | 🎉 -153 B 🎉 |
| Dependency size | 58.61 MB | 58.38 MB | 🎉 -229 KB 🎉 |
| Bundle Size Analyzer | node | node |
Closes #
What I did
The
addon-a11y-addon-testautomigration was prompted for projects where it had nothing to do. Itscheck()only evaluated the "already migrated" skip conditions when both.storybook/vitest.setup.*and.storybook/preview.*existed:Projects without a
vitest.setupfile — the norm since the vitest plugin auto-provisions preview annotations (10.3+) — skipped that block entirely, so the migration was always prompted even whenpreviewalready hadparameters.a11y.testconfigured. Selecting it was a complete no-op (it rewrotepreviewwith identical content).This PR computes the two skip flags independently per file:
vitest.setupfile → nothing to transform on the setup side (the plugin auto-provisions annotations, including addon-a11y's). Projects that keep the optional setup file are still checked and transformed exactly as before.return nullnow runs whenever both flags are set.This also fixes a second latent bug the old gating had: a project with an already-migrated setup file but no preview file skipped the "already has
@storybook/addon-a11y" detection and re-transformed the setup file, injecting a duplicatea11yAddonAnnotationsimport.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Includes a regression test for the false-positive scenario (no setup file + preview already configured →
check()returnsnull), and un-skips the previously skipped "preview file only" test with a corrected expectation.Manual testing
@storybook/addon-a11yand@storybook/addon-vitestinmain.ts, no.storybook/vitest.setup.*file, andparameters: { a11y: { test: 'todo' } }already set in.storybook/preview.*(e.g. https://github.com/yannbf/mealdrop).npx storybook@next upgrade(oryarn automigratefrom a linked CLI build).addon-a11y-addon-testautomigration is prompted and does nothing when run. After: it is not prompted..storybook/vitest.setup.tslacking the a11y annotations still gets prompted and transformed as before.Documentation
MIGRATION.MD
Checklist for Maintainers
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.tsqa:neededorqa:skip🤖 Generated with Claude Code
Summary by CodeRabbit