Skip to content

[codemod] Top-Level-Imports codemod adds some named imports that aren't exported from the top level packageΒ #32914

@gisheri

Description

@gisheri

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

After running the top-level-imports codemod, I found that it attempts to import some things incorrectly.

  • { TransitionProps } named import from '@mui/material' but it actually needs to be imported from '@mui/material/transitions';
  • { common } from '@mui/material' should be '@mui/material/colors'

I'm not sure if these imports were intentionally left out of the main package exports, or if that was a mistake, but the codemod doesn't make the distinction.

Expected behavior πŸ€”

The top-level-imports codemod should not change imports to named imports for items that aren't exported from the top level package.

Steps to reproduce πŸ•Ή

Steps:

  1. Create a file with: ```
    import { TransitionProps } from '@mui/material/transitions';
    import { common } from '@mui/material/colors';
2. Run `top-level-imports on that file. 
3. See it combine these into ```
    import { TransitionProps, common } from '@mui/material'
  1. Run TSC and notice that typescript informs you that these modules are not exported from '@mui/material'

Context πŸ”¦

No response

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 12.0
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Edge: Not Found
    Firefox: 98.0.2
    Safari: 15.0
  npmPackages:
    @emotion/react: ^11.7.1 => 11.7.1 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/base: ^5.0.0-alpha.68 => 5.0.0-alpha.68 
    @mui/icons-material: ^5.5.1 => 5.5.1 
    @mui/lab: ^5.0.0-alpha.67 => 5.0.0-alpha.67 
    @mui/material: ^5.4.0 => 5.4.0 
    @mui/private-theming:  5.3.0 
    @mui/styled-engine:  5.3.0 
    @mui/styles: ^5.3.0 => 5.3.0 
    @mui/system: ^5.4.0 => 5.4.0 
    @mui/types:  7.1.0 
    @mui/utils:  5.3.0 
    @types/react: ^17.0.2 => 17.0.3 
    react: 17.0.1 => 17.0.1 
    react-dom: 17.0.1 => 17.0.1 
    styled-components: 5.2.3 => 5.2.3 
    typescript: ^4.3.2 => 4.5.5 

Metadata

Metadata

Assignees

Labels

package: codemodSpecific to codemod.ready to takeHelp wanted. Guidance available. There is a high chance the change will be acceptedscope: all componentsWidespread work has an impact on almost all components.type: bugIt doesn't behave as expected.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions