moroshko / react-scanner

Extract React components and props usage from code.
MIT License
564 stars 40 forks source link

Aliased imports don't show the true imported component #10

Closed RareSecond closed 3 years ago

RareSecond commented 3 years ago

When a component is imported like

import { Icon as DesignSystemIcon } from '@my/design-system'

the generated output is

{
  "DesignSystemIcon": {
    "instances": 1,
    "props": {
      "color": 1,
      "flex": 1
    }
  }
}

Is there a possibility to get the actual name of the imported component, and not the Alias it was imported as?

moroshko commented 3 years ago

Yeah, makes sense.

If one file has:

import { Button } from "design-system";

and in another file you decided to alias the Button for some reason:

import { Button as MyButton } from "design-system";

you'd want them to go to the same bucket, right?

{
  Button: {
    instances: [
      { ... },
      { ... }
    ]
  }
}

Would knowing the alias MyButton still be valuable?

{
  Button: {
    instances: [
      { ... },
      {
        importAlias: "MyButton",
        ...
      }
    ]
  }
}
RareSecond commented 3 years ago

Well sure, the more info the better I guess!

sapegin commented 3 years ago

Yup, knowing the alias is useful: if some component is often aliased, it might suggest that the name is conflicting with other dependencies on the project.

moroshko commented 3 years ago

This is fixed in 0.5.0. Also, added importInfo to component instances. You can use it to find aliases.