-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[codemod] Add jss to tss-react codemod #31802
Conversation
Initial naive implementation. Many more test cases left to add.
- Now covers @material-ui/core/styles, @material-ui/core, and @mui/styles
Here is the list of scenarios I intend to support before taking this out of draft mode:
|
@mnajdova I haven't verified this against my own code base yet so I might have follow-up tweaks once I do, but it now covers all of the scenarios that I am aware of in my code base. The main features it doesn't handle are params to |
That's great! Should we wait for your verification in your project? I think it's healthy if we have tested it on at least one project.
Alright, I may spend some time this quarter on it, or we could try to find some help from the community of tss-react cc @garronej All in all great effort @ryancogswell |
This comment was marked as outdated.
This comment was marked as outdated.
@mnajdova I believe this is now ready to merge. |
…rameters - Was previously passing `{}` as the first parameter instead of `undefined`
@mnajdova Please let me know if there’s anything I can do to help move the review of this forward. |
@garronej There are 9 pairs of test files in the You can also help by reviewing my changes to the documentation. In particular, I removed your |
@ryancogswell Yes yes, sorry, I have a lot on my plate but I will definitively have a look ASAP. |
@garronej Most of the examples are pretty straightforward, and I've already verified that they all work (at least once all the MUI imports are also transformed by other codemods), so I think it will be pretty quick to look through. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did an impressive job congratulation 👏🏻🎉
I just added some comments about what, I think, are best practice but feel free to ignore.
packages/mui-codemod/src/v5.0.0/jss-to-tss-react.test/expected-from-material-ui-core-styles.js
Show resolved
Hide resolved
packages/mui-codemod/src/v5.0.0/jss-to-tss-react.test/expected-from-material-ui-core.js
Show resolved
Hide resolved
...ges/mui-codemod/src/v5.0.0/jss-to-tss-react.test/expected-typescript-docs-example-params.tsx
Show resolved
Hide resolved
...ges/mui-codemod/src/v5.0.0/jss-to-tss-react.test/expected-typescript-docs-example-params.tsx
Show resolved
Hide resolved
@garronej Thanks for reviewing things! In looking over the migration guide I noticed a few broken links to your GitHub readme that I just fixed to go to the equivalent docs.tss-react.dev URL, so that will give people a resource for best practices in using tss-react. For now, I think I'll leave my "comprehensive example" as it is -- with the focus being to show what the codemod will do in a more complicated scenario rather than trying to duplicate the best-practices guidance that is in your documentation. |
Fair enough |
@garronej And thanks for creating tss-react! Our company's application is migrated to v5 in our testing environment with the intention of moving v5 to production this weekend. We wouldn't be able to make this transition nearly as quickly or confidently if we had needed to move the styles (700 usages of |
Hi @ryancogswell, Best regards. |
I am going to do a review on this tomorrow, looks promising @ryancogswell :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't wait till tomorrow :D Just small details added, looks great overall.
const expected = read('./jss-to-tss-react.test/expected-from-material-ui-core-styles.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
it('should be idempotent', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, if we add more features, people would be able to just run the new codemod version again 👍
:::error | ||
**WARNING**: You should drop [`clsx`](https://www.npmjs.com/package/clsx) in favor of [`cx`](https://emotion.sh/docs/@emotion/css#cx). | ||
The key advantage of `cx` is that it detects emotion generated class names ensuring styles are overwritten in the correct order. | ||
The default precedence of styles from multiple CSS classes is different between JSS and tss-react and some manual re-ordering of `cx` parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit here for applying some changes from master. Would be great if you can double check if this is the changed content on the migration guide (LGTM btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a merge of those migration guide changes yesterday, but I should have installed the merge tool that I use at work onto my home computer. I used my IDE's merge resolution instead and looks like it didn't behave the way I thought and lost a lot of the changes that I thought I was merging in. Thanks for fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of my previous migration guide changes were lost during your fix of my bad merge. I've reapplied those changes now.
npx @mui/codemod v5.0.0/jss-to-tss-react <path> | ||
``` | ||
|
||
You can find more details about migrating from JSS to tss-react in [the migration guide](https://mui.com/guides/migration-v4/#2-use-tss-react). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great if we can list here things that are not supported, for example the "TODOs" added in expected-todo-comments.js
.
This will make sure we are transparent and will help future contributors to take features one by one and add them as part of the codemod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added documentation about the scenarios that produce TODO comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @ryancogswell! Can't wait to share this with the community :)
Thank you very much @ryancogswell, you did a great job! |
Initial naive implementation. Many more test cases left to add.