moroshko / react-scanner

Extract React components and props usage from code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default imports don't show the correct component name

sapegin opened this issue · comments

Similar to #10 but with default imports:

import DesignSystemIcon from '@my/design-system/Icon'

The component name in the stats will be DesignSystemIcon instead of the correct one Icon.

Not sure we should detect the name automatically in this case though. Maybe taking the last part of the path and give an ability to override this behavior would be a good solution?

I think trying to automagically guess the component name from the module name/path won't scale.

How about adding a getComponentName option?

For example:

{
  ...
  getComponentName: ({ imported, local, moduleName }) => {
    const parts = moduleName.split('/');
    
    return parts[parts.length - 1];
  }
}

In #10, I basically suggest that the default is ({ imported, local }) => imported || local instead of the current ({ local }) => local.

Yeah, that would work I guess! 🦄

getComponentName is available in 0.5.0.