Skip to content

A library that helps you understand how a package is being used in your projects and what APIs are used

License

Notifications You must be signed in to change notification settings

luistak/pkg-usage

Repository files navigation

📦 pkg-usage

npm

Installation

npm install pkg-usage

# or

yarn add pkg-usage

Introduction

Have you ever wondered how your library is being used in other repositories? It's your lucky day because this package aims to solve it.

Given a few options you can gets details about how your library is being imported along with its version

Usage

import { getPackagesUsages } from 'pkg-usage';

const usages: PackageUsage[] = getPackagesUsages({
  packages: ['react'],
  fileGlobs: `**/**.ts`,
  packageJsonCWD: './package.json',
  analyzeImportUsages: false,
});

console.log(usages);

Package Usage types

export type JSXElementUsage = {
  line: number;
  props: string[];
  text: string;
};

export type CallExpressionUsage = {
  line: number;
  text: string;
};

export type ValueUsage = {
  line: number;
  text: string;
};

export type PropertyAccessExpressionUsage = {
  line: number;
  property: string;
  text: string;
};

export type Usages =
  | JSXElementUsage[]
  | (CallExpressionUsage | PropertyAccessExpressionUsage | ValueUsage)[];

export type Import = {
  name: string;
  type: ExportType;
  usages?: Usages;
};

export type FileUsage = {
  name: string;
  filePath: string;
  imports: Import[];
};

export type PackageUsage = {
  name: string;
  count: number;
  files?: FileUsage[];
  version?: string;
};

CLI usage

Options Description Example
-p, --packages Packages to analyze -p vue,vuex or --packages="react,redux"
-f, --file-globs Files to analyze based on file globs -f ".(ts|tsx)" or --file-globs=".(js|jsx)"
-u, --analyze-import-usages (Experimental) Analyzes import usages -u
-cwd, --package-json-CWD Directory to start from -cwd "/path/to/start/from"

npx

npx is a package runner tool

npx pkg-usage -p "react,redux" -f "**/*.(ts|tsx)"

Or

npx pkg-usage --packages="vue,vuex" --file-globs="**/*.(js|vue)"

If you use npm 5.1 or earlier, you can't use npx. Instead, install it globally:

npm install -g pkg-usage

Now you can run:

pkg-usage -p "react,redux" --f "**/*.(ts|tsx)"

About

A library that helps you understand how a package is being used in your projects and what APIs are used

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 4

  •  
  •  
  •  
  •