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

Codemods: Fix csf-2-to-3 ignores Typescript types #20273

Merged

Conversation

kasperpeulen
Copy link
Contributor

@kasperpeulen kasperpeulen commented Dec 14, 2022

Issue: #20219

What I did

  • Made sure that when converting to object, also the type is converted from Story/StoryFn/ComponentStory to StoryObj
  • When the export need to stay a function, update the Story/ComponentStory type to StoryFn

How to test

  • See the test

@kasperpeulen kasperpeulen self-assigned this Dec 14, 2022
@kasperpeulen kasperpeulen changed the title CSF-2-3_automigration_scripts_ignores_Typescript_types CSF-2-3 automigration scripts ignores Typescript types Dec 14, 2022
@kasperpeulen kasperpeulen force-pushed the CSF-2-3_automigration_scripts_ignores_Typescript_types branch from 4b27a40 to 60c05f1 Compare January 11, 2023 13:28
@kasperpeulen
Copy link
Contributor Author

@shilman @valentinpalkovic

I updated the logic to also convert import types to StoryObj, or Story to StoryFn.

I also made sure that we preserve line breaks by using recast:

When you call recast.parse, it makes a shadow copy of the AST before returning it to you, giving every copied AST node a reference back to the original through a special .original property. This information is what enables recast.print to detect where the AST has been modified, so that it can preserve formatting for parts of the AST that were not modified.

@kasperpeulen kasperpeulen force-pushed the CSF-2-3_automigration_scripts_ignores_Typescript_types branch 2 times, most recently from 2322343 to d782f3a Compare January 12, 2023 12:27
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.

Looks great. A few small comments

@shilman shilman changed the title CSF-2-3 automigration scripts ignores Typescript types Codemods: Fix CSF-2-3 ignores Typescript types Jan 12, 2023
@shilman shilman changed the title Codemods: Fix CSF-2-3 ignores Typescript types Codemods: Fix csf-2-to-3 ignores Typescript types Jan 12, 2023
@kasperpeulen kasperpeulen force-pushed the CSF-2-3_automigration_scripts_ignores_Typescript_types branch 2 times, most recently from 71774eb to 584fb94 Compare January 13, 2023 15:47
@kasperpeulen kasperpeulen force-pushed the CSF-2-3_automigration_scripts_ignores_Typescript_types branch from 584fb94 to 1563de3 Compare January 13, 2023 20:13
@kasperpeulen kasperpeulen force-pushed the CSF-2-3_automigration_scripts_ignores_Typescript_types branch from 5ccdf00 to 49fd31a Compare January 14, 2023 19:51
@kasperpeulen kasperpeulen merged commit 7ababb0 into next Jan 15, 2023
@kasperpeulen kasperpeulen deleted the CSF-2-3_automigration_scripts_ignores_Typescript_types branch January 15, 2023 07:59
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