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 prompt-only automigrate asking for react-removal #25215

Merged
merged 7 commits into from
Dec 18, 2023

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Dec 13, 2023

Telescoped: #25196

Works on #25179

What I did

Added an automigration prompt, asking users to remove "react" as a dependency, when it's likely they have it because we asked for it.

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/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>

Comment on lines 120 to 125
if (hasMDX) {
const mdxSuggestion = dedent`
As you are using '.mdx'-files, it might be reasonable to keep the dependency.
`;
return [start, mdxSuggestion].join('\n\n');
}
Copy link
Contributor

@valentinpalkovic valentinpalkovic Dec 13, 2023

Choose a reason for hiding this comment

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

The detectMDXEntries is pretty heavy and requires some heavy-lifting file system lookups. I don't think it's worth it just to log this one-liner to the user. What is the worst that can happen? Things might break and the user has to re-add react and react-dom. I think that's acceptable.

Copy link
Member Author

Choose a reason for hiding this comment

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

When the user uses .mdx files, they will very likely want to keep the react dependency.

I pulled this code from the override preset, it costs like <80ms. Is that heavy lifting file system lookups to you?

Copy link
Contributor

@valentinpalkovic valentinpalkovic Dec 13, 2023

Choose a reason for hiding this comment

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

I don't know in which particular project you did the measurement, but I guess that the automigration might be blocking in bigger projects.

Also, I don't quite understand what you want to achieve:

  • You only scan for mdx files, if they are part of the stories glob. If they are not defined in the stories glob, you are not checking for them. So why not directly just search for mdx in the stories glob pattern? I don't think file system lookups are necessary in this case.
  • What about MDX usage outside of Storybook. This case isn't covered here, since if the stories glob pattern doesn't mention mdx files, they also subsequently will not be found by glob. So if you want to cover this scenario, you don't have to consider the stories glob at all but create a simple glob, which considers mdx files and pass it directly to the glob function. Also, isn't this case the only relevant one? We want to keep react and react-dom if e.g. MDX is used outside of Storybook. Isn't this the case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't think this check is necessary at all. Early results in #24881 shows that it's perfectly valid to have MDX files - even ones importing React components - in a project without react and react-dom. It just works. TypeScript in the IDE might complain - I haven't tested that out yet - but I don't think that warrants this additional message.

},
prompt({ hasMDX, hasDocs, hasEssentials }) {
const addons = [hasEssentials ? 'essentials' : '', hasDocs ? 'docs' : ''].filter(Boolean);
const addonReasonText =
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like an unnecessary detail to me, I don't think it's needed.

Copy link
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

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

I think the special messages for MDX and the addons are unnecessary and we should be able to remove them to simplify the prompt without loosing value.

code/lib/cli/src/automigrate/fixes/prompt-remove-react.ts Outdated Show resolved Hide resolved
code/lib/cli/src/automigrate/fixes/prompt-remove-react.ts Outdated Show resolved Hide resolved
Base automatically changed from norbert/not-add-react-init to next December 18, 2023 12:16
@JReinhold JReinhold merged commit 9cd9f65 into next Dec 18, 2023
56 of 57 checks passed
@JReinhold JReinhold deleted the norbert/prompt-removal-react-automigration branch December 18, 2023 12:17
@github-actions github-actions bot mentioned this pull request Dec 19, 2023
22 tasks
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.

3 participants