module-analyzr

1.2.2 • Public • Published

module-analyzr

module-analyzr is a simple CLI and toolbox to analyze the usage of a package.

input:

import defaultExport from "test-module";
import * as name from "test-module";
import { export as alias } from "test-module";

import { export1, export2 } from "test-module";
import { export1 } from "test-module";

output:

{
  importedModules: [
    { moduleName: 'export', usageAmount: 1 },
    { moduleName: 'export1', usageAmount: 2 },
    { moduleName: 'export2', usageAmount: 1 }
  ],
  importedDefault: 1,
  importedWithNameSpace: 1
}

install

npm install -g module-analyzr

CLI

After installing, you can use module-analyzr command in any directory in your system:

  Usage: module-analyzr <moduleName> <path> [options]

    moduleName    A name of module.
    path          File path or directory path or glob pattern

  Options:
    -i   File path or directory path or glob pattern to ignore. Default: [node_modules]
    --type=typescript  passes typescript plugin to the parser
    --type=flow  passes flow plugin to the parser

# example and output
module-analyzr react src/**/*.js

{ importedModules:
   [ { moduleName: 'Component', usageAmount: 10 },
     { moduleName: 'Node', usageAmount: 2 },
     { moduleName: 'Fragment', usageAmount: 1 } ],
  importedDefault: 20,
  importedWithNameSpace: 23 }

API

const analyzr = require('module-analyzr')
const usageInfo = analyzr('react', 'src/**/*.js')

output JSON

Parameter Description
importModules Array of {moduleName: <string>, usageAmount: <number>} which shows usage count of named export.
importedDefault Number of usage count of default exports
importedWithNameSpace Number of usage count of named export, but all of exports with * (eg. import * as Module from 'module').

Motivation

module-analyzr is simple tool to analyze usage of a module in a file or directory(likely project). It is helpful for module's maintainer to grasp how their module used in projects. Also, it is helpful for application engineer when upgrade the module or remove the module. In my case, as a creator of UI Library, it was nervous to add a breaking change. That is why I created module-analyzr.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i module-analyzr

Weekly Downloads

2

Version

1.2.2

License

MIT

Unpacked Size

143 kB

Total Files

17

Last publish

Collaborators

  • taneba