moroshko / react-scanner

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

Add importType #33

Closed vladkosinov closed 3 years ago

vladkosinov commented 3 years ago

Hey! Thanks for a great tool!

I'm building a dashboard for tracking components usages of my company's private UI kit.

And I'm having an issue when an import of a default export of the same component using different names results in the different components in the report:

// file_1.ts
import component_1 from "module-name";
// file_2.ts
import component_2 from "module-name";

will end up with:

{
  component_1: {
  },
  component_2: {
  },
}

Since the module name is the only way to uniquely identify components with default export I can suggest only few ideas:

This PR allows users to choose their own naming strategy by providing a importType field along with other import data.

It can be used inside getComponentName callback or during processor step by merging data for components with the same module name and importType === 'ImportDefaultSpecifier'

moroshko commented 3 years ago

Thanks @vladkosinov, that's a great addition 👍 I published 0.7.0, give it a go!