[codemod] Fix v5.0.0/top-level-imports codemod changing color imports - #46405
Conversation
… are not transformed
DiegoAndai
left a comment
There was a problem hiding this comment.
Thanks for submitting this @AidanLDev! The fix seems correct and the tests as well.
May I ask you to move the expected input and output test content to separate files? Similar to how it's done for other tests. You can create separate files for this test in particular, or add it to the existing files.
|
Good point, I will update the tests to follow the same style as the other ones :) |
| ClickAwayListener, | ||
| ListSubheader, | ||
| } from '@mui/material'; | ||
| import { createTheme } from '@mui/material/styles'; |
There was a problem hiding this comment.
Why is createTheme moved? Is createTheme not included on the whitelist?
There was a problem hiding this comment.
Good question, that's right it's not currently in the whitelist so to get the tests passing I moved it outside of the @mui/material import.
There was a problem hiding this comment.
This is correct. The reason it should be moved outside of the direct @mui/material root import is because in the actual.js file it is imported from the styles folder:
import { createTheme } from '@mui/material/styles';And ThemeProvider is imported directly:
import { ThemeProvider } from '@mui/material';So, it should be the same in the expected.js file and should not transform the imports because they are not in the whitelist.
To make it consistent with createTheme, I moved ThemeProvider to be imported from styles folder in actual.js file.
Before this bugfix, it was also transforming imports from @mui/material/styles which was incorrect. If it is imported from @mui/material/styles, it should keep it as is and if it is imported from @mui/material it should keep it as is for createTheme and ThemeProvider APIs.
Netlify deploy previewhttps://deploy-preview-46405--material-ui.netlify.app/ Bundle size report
|
ZeeshanTamboli
left a comment
There was a problem hiding this comment.
@AidanLDev Looks good! Thanks for the fix.
v5.0.0/top-level-imports codemod changing color imports
Summary
Fixes #45051 - Fixed logical error in top-level-imports codemod that was incorrectly transforming color imports.
Description
The
v5.0.0/top-level-importscodemod was incorrectly transforming imports from@mui/material/colors(e.g.,import { grey } from '@mui/material/colors') to@mui/material(e.g.,import { grey } from '@mui/material'). This transformation is invalid because color exports likegrey,blue, etc. are not available from the main@mui/materialpackage.Root Cause
The issue was in the whitelist check condition: