DEV Community

Yoshihiro Nakamura
Yoshihiro Nakamura

Posted on

module-analyzr - A simple CLI and toolkit to extract usage of module

Summary

I made a new npm package called module-analyzr. It extract the usage of a module in given files or directory or glob-pattern.

https://github.com/taneba/module-analyzr

Example

Imagine if you want to know the usage of React in your project,

# first, install it via npm
npm install -g module-analyzr


# then, in your project
module-analyzr react src
{ importedModules:
   [ { moduleName: 'Element', usageAmount: 2 },
     { moduleName: 'Component', usageAmount: 37 } ],
  importedDefault: 215,
  importedWithNameSpace: 0 }
Enter fullscreen mode Exit fullscreen mode

Output object shows the usage of React in the src directory. It means Element imported twice, and Component imported 37 times, and import React from 'react' 215 times!

If it shows importedWithNameSpace with some number, it means there are number of import * as React from 'react'.

Motivation

I am a maintainer of a component library made of React in my company. It was hard to grasp how much each component is used in which project. So When I wanted to upgrade my lib with some breaking changes, I had to ask each engineer for the usage of components. module-analyzr is most useful for this kind of situation. I'm using module-analyzr in the backend system to analyze each passed github urls and visualize how much each component is used in all of projects!

In closing

It's my first time to ship open source project, so there may be some bugs😅
I've learned much from making this and wanna engage more in the open source community😀

I hope you'll be interested in this library!

Top comments (0)