Skip to content

Automigration: Refactor automigration command handling and add tests #31302

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

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Apr 29, 2025

Closes #31300

  • Introduced getAutomigrateCommand function to standardize the command generation for automigrating addons.
  • Updated postinstall.ts files for addonA11y and vitest to utilize the new command function.
  • Added unit tests for getAutomigrateCommand to ensure correct command generation.
  • Updated various fix definitions to include a generic key type for better type safety.

Closes #

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make 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/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Greptile Summary

This PR refactors automigration command handling by introducing a standardized getAutomigrateCommand function and updates various fix definitions with improved type safety across the Storybook codebase.

  • Added new code/core/src/cli/automigrate.ts with getAutomigrateCommand function for standardized command generation
  • Updated postinstall scripts in code/addons/a11y and code/addons/vitest to use the new command function
  • Added type parameter to Fix interface in code/lib/cli-storybook/src/automigrate/types.ts for better type safety
  • Modified 15+ fix definition files to use typed fix IDs, improving type checking
  • Added unit tests in code/core/src/cli/automigrate.test.ts for command generation

- Introduced `getAutomigrateCommand` function to standardize the command generation for automigrating addons.
- Updated `postinstall.ts` files for `addonA11y` and `vitest` to utilize the new command function.
- Added unit tests for `getAutomigrateCommand` to ensure correct command generation.
- Updated various fix definitions to include a generic key type for better type safety.
@valentinpalkovic valentinpalkovic force-pushed the valentin/consider-automigrate-options branch from 64d41c0 to 89531e8 Compare April 29, 2025 13:30
@valentinpalkovic valentinpalkovic self-assigned this Apr 29, 2025
Copy link

nx-cloud bot commented Apr 29, 2025

View your CI Pipeline Execution ↗ for commit 40a56bc.

Command Status Duration Result
nx run-many -t build --parallel=3 ❌ Failed 11s View ↗

☁️ Nx Cloud last updated this comment at 2025-04-29 19:46:57 UTC

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

22 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +65 to +68
export type CommandFix<ResultType = any, Key extends string = string> = {
promptType: PromptType<ResultType, 'command'>;
run: (options: RunOptions<ResultType>) => Promise<void>;
} & Omit<BaseFix<ResultType>, 'versionRange' | 'check' | 'prompt'>;
} & Omit<BaseFix<ResultType, Key>, 'versionRange' | 'check' | 'prompt'>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider making Key parameter required instead of defaulting to string to enforce strict typing

* // ['storybook', 'automigrate', 'addon-a11y-parameters', '--yes', '--config-dir', 'config', '--package-manager', 'npm']
* ```
*/
export const getAutomigrateCommand = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to have an abstraction to run Storybook CLI commands instead? And force the configDir to be passed? The problem we face happens on all Storybook CLI commands essentially, including the Storybook doctor command.

I guess it begs the question too, do we need to spawn npm commands in all places that currently do that? Or can we just call the function if the import is available? I understand it might not work in a few places like when executing something from @storybook/cli as part of create-storybook, but in other places it might work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a try!

@valentinpalkovic valentinpalkovic marked this pull request as draft May 2, 2025 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Storybook 9 - Addon vitest is not forwarding the config dir when running a11y automigrations
2 participants