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.

Codemod variant-prop doesn't change files as expected

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

After running the variant-prop codemod, no changes are applied.

Expected behavior 🤔

The script should normally add the variant="standard" to all TextField, Select, and FormControls.

Steps to reproduce 🕹

Steps:

  1. Run npx @mui/codemod v5.0.0/variant-prop <path> on a project that does has TextField, Select, and FormControls with no variant defined.

Context 🔦

The output in my console when I’m running the command just shows that the script found 144 files but for some reason it left them unmodified: npx: installed 251 in 4.335s Executing command: jscodeshift /npm/_npx/13468/lib/node_modules/@mui/codemod/node_modules/jscodeshift/bin/jscodeshift.js --transform //.npm/_npx/13468/lib/node_modules/@mui/codemod/node/v5.0.0/variant-prop.js --extensions js,ts,jsx,tsx --parser tsx --ignore-pattern **/node_modules/** Processing 144 files... Spawning 7 workers... Sending 21 files to free worker... Sending 21 files to free worker... Sending 21 files to free worker... Sending 21 files to free worker... Sending 21 files to free worker... Sending 21 files to free worker... Sending 18 files to free worker... All done. Results: 0 errors 144 unmodified 0 skipped 0 ok Time elapsed: 6.511seconds

Your environment 🌎

`npx @mui/envinfo`
System:
    OS: macOS 11.6.2
  Binaries:
    Node: 12.22.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.12 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Edge: Not Found
    Firefox: 95.0.2
    Safari: 15.2
  npmPackages:
    @emotion/react: ^11.7.1 => 11.7.1 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.62 
    @mui/icons-material: ^5.2.5 => 5.2.5 
    @mui/lab: ^5.0.0-alpha.30 => 5.0.0-alpha.62 
    @mui/material: ^5.2.5 => 5.2.6 
    @mui/private-theming:  5.2.3 
    @mui/styled-engine:  5.2.6 
    @mui/styles: ^5.2.3 => 5.2.3 
    @mui/system:  5.2.6 
    @mui/types:  7.1.0 
    @mui/utils:  5.2.3 
    @types/react:  16.9.17 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^16.12.0 => 16.12.0 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
aweygandtcommented, Dec 30, 2021

I think I found the issue, the codemod uses a regex to match “/^@material-ui/core(/TextField|/Select|/FormControl)?$/” but preset-safe rewrote the imports to “@mui/material” so they get skipped. When I change the import back, the changes were made.

1reaction
siriwatknpcommented, Jan 3, 2022

I would say that this is a bug. To give the best experience, the Codemod should be independent of each other. The fix should be pretty straightforward (updating the regex to include @mui/material). Feel free to submit a PR (otherwise I can do it this week).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Codemod variant-prop doesn't change files as expected #30422
Steps: Run npx @mui/codemod v5.0.0/variant-prop on a project that does has TextField, Select, and FormControls with no variant defined. Context ...
Read more >
Your first codemod - CodeshiftCommunity
(1) First we'll create an AST, (2) second we'll look at all nodes and return only nodes that match the ImportDeclaration and then...
Read more >
@material-ui/codemod - npm
Removes the Chip variant prop if the value is "default" . ... You can find more details about this breaking change in the...
Read more >
Breaking changes in v5, part two: core components - Material UI
This is a reference guide to all of the breaking changes introduced in Material v5, and how to handle them when migrating from...
Read more >
Codemods for React and TypeScript | Building SPAs
We will create a transform to change a kind prop on a Button element to variant . We will call the transformation button-kind-to-variant...
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