Skip to content
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

CLI: Add webpack5 compiler automigration #26000

Merged
merged 24 commits into from
Feb 19, 2024

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Feb 12, 2024

Closes #25431

What I did

This PR adds an automigration for Webpack5 users to

a) remove the framework.options.builder.useSWC flag
b) set up either @storybook/addon-webpack5-compiler-swc or @storybook/addon-webpack5-compiler-babel to add a compiler to the Webpack5 builder
c) changed promptOnly prop in fixes to promptType to allow different prompt types. Now, manual, auto and notified can be used.

The frameworks @storybook/angular, @storybook/nextjs, @storybook/react-webpack5 in combination with CRA and @storybook/ember do not need an additional compiler addon, since they have their compilers built-in.

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

The auto migration is skipped in the following scenarios:

  • The builder is not Webpack5 based (The frameworks builder or a custom-defined builder via core.builder)
  • The user's framework is Angular, Ember or CRA

The auto migration should do the following things:

  • If framework.options.builder.useSWC is set, it should be removed

Next.js specific:

  • The user gets notified via prompt how Storybook detects SWC or Babel mode.

Except Next.js:

  • If framework.options.builder.useSWC === true, the @storybook/addon-webpack5-compiler-swc will be installed and added to the addons section of the main configuration file.
  • If framework.options.builder.useSWC === false | undefined, a prompt appears to ask the user, whether the babel or swc addon should be installed

Test Results

Test Candidate: https://github.com/nodejs/nodejs.org (Next.js)

  • framework.options.builder.useSWC gets removed when set
  • a prompt notifies the user how Storybook's compiler detection works

Test Candidate: https://github.com/bitwarden/clients (Angular)

  • The auto migration prompt doesn't trigger

Test Candidate: Fresh CRA project on SB7 (CRA)

  • The auto migration prompt doesn't trigger

Test Candidate: Storybook react-webpack5 sandbox (React)

  • The auto migration prompts the user to select a compiler when framework.options.builder.useSWC is set to false or not set at all
  • The chosen compiler addon gets installed and added to the addons section of .storybook/main.js. A prompt notifies the user about these actions.

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/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 pull request has been released as version 0.0.0-pr-26000-sha-e0e439e7. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-26000-sha-e0e439e7
Triggered by @valentinpalkovic
Repository storybookjs/storybook
Branch valentin/add-webpack5-compiler-automigration
Commit e0e439e7
Datetime Mon Feb 19 08:33:55 UTC 2024 (1708331635)
Workflow run 7956681990

To request a new release of this pull request, mention the @storybookjs/core team.

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

@valentinpalkovic valentinpalkovic added maintenance User-facing maintenance tasks ci:normal labels Feb 12, 2024
@valentinpalkovic valentinpalkovic self-assigned this Feb 12, 2024
@valentinpalkovic valentinpalkovic changed the title Valentin/add webpack5 compiler automigration Automigration: Add webpack5 compiler automigration Feb 12, 2024
@valentinpalkovic valentinpalkovic marked this pull request as ready for review February 13, 2024 12:28
shilman

This comment was marked as resolved.

@valentinpalkovic

This comment was marked as resolved.

@valentinpalkovic valentinpalkovic force-pushed the valentin/add-webpack5-compiler-automigration branch from 34f05f8 to 6261cdf Compare February 16, 2024 14:31
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Should be a TS error no?

code/lib/cli/src/automigrate/index.ts Outdated Show resolved Hide resolved
@valentinpalkovic valentinpalkovic merged commit 21ed4a3 into next Feb 19, 2024
54 of 57 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/add-webpack5-compiler-automigration branch February 19, 2024 11:02
@github-actions github-actions bot mentioned this pull request Feb 19, 2024
26 tasks
@shilman shilman changed the title Automigration: Add webpack5 compiler automigration CLI: Add webpack5 compiler automigration Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto migration: Add compiler addons for Webpack5-based projects
2 participants