question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for the `top-level-imports` codemod for MUI v5

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Currently the top-level-imports codemod does not support MUI v5, while the current docs still link to it. The top-level-imports codemod should support MUI v5.

Examples 🌈

I have tried running the v4 codemod on a v5 codebase without success. I also tried setting two jscodeshift args --importModule and --targetModule to @mui/material, like this:

npx @mui/codemod v4.0.0/top-level-imports myfile.tsx --jscodeshift='--importModule="@mui/material" --targetModule="@mui/material"'

This results in:

Error: Cannot find module '"@mui/material" --targetModule="@mui/material"'

The error message appears as if the two jscodeshift args were concatenated to one arg. This may well be an error on my part, so please let me know if this should work. Setting only one of the args like --jscodeshift='--importModule="@mui/material" still results in the same error though: Error: Cannot find module '"@mui/material"'.

I found a related issue (https://github.com/mui/material-ui/issues/30907), but it talks about the babel-plugin-import, not the codemod.

Motivation 🔦

I have a large codebase with several submodule imports per file like this:

import MenuItem from '@mui/material/MenuItem';
import InputLabel from '@mui/material/InputLabel';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';

I want to transform these imports into top-level imports like this without having to refactor each file manually:

import { MenuItem, InputLabel, FormControl, Select } from '@mui/material';

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mnajdovacommented, Mar 4, 2022

@greengiraffe sorry for the delay, had to run on a meeting 😄 It should be fixed with https://github.com/mui/material-ui/pull/31308 (I’ve tested locally, but would be great if you can double check). You can fetch that branch, build the @mui/codemod package locally, by going in the folder and running yarn build and then you can test it with:

node D:\workspace\mui\packages\mui-codemod\build\codemod.js v5.0.0\top-level-imports ./src/App.js

You can replace the D:\workspace with your location 😃

The alternative is to wait for the build on the branch and test with the packages build on the PR.

2reactions
mnajdovacommented, Mar 4, 2022

Taking a look @greengiraffe

Read more comments on GitHub >

github_iconTop Results From Across the Web

@mui/codemod - npm
Start using @mui/codemod in your project by running `npm i @mui/codemod`. There are 5 other projects in the npm registry using @mui/codemod.
Read more >
@material-ui/codemod - npm Package Health Analysis | Snyk
This repository contains a collection of codemod scripts based for use with JSCodeshift that help update Material-UI APIs. Setup & Run. npm install...
Read more >
Minimizing bundle size - Material UI - MUI
If you're using ES6 modules and a bundler that supports tree-shaking ... convert your existing codebase to this option with this top-level-imports codemod....
Read more >
@mui/lab | Yarn - Package Manager
@mnajdova added motion and shape design tokens to Material You package (#35384 and #35393). Many other bug fixes, documentation, ...
Read more >
mui/material/CHANGELOG.md - UNPKG
62, - @siriwatknp added support for callbacks in styleOverrides (#30524) ... 13 -->[docs] Codemod doc for overriding styles using tss (#30499) @garronej.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found