dpdm
A static dependencies analyzer for your JavaScript
and TypeScript
projects.
Features
- Supports
CommonJS
, ESM
. - Supports
JavaScript
and TypeScript
completely.
- Supports TypeScript path mapping.
- Supports ignore TypeScript type dependency
- Light weight: use typescript to parse all modules.
- Fast: use asynchronous API to load modules.
- Stable output: This is compared to madge, whose results are completely inconclusive when analyze
TypeScript
.
Install
npm i dpdm
npm i -g dpdm
dpdm --help
Usage in line
dpdm.ts [options] files...
Options:
--version Show version number [boolean]
--context the context directory to shorten path, default is current directory [string]
--extensions, --ext comma separated extensions to resolve
[string] [default: ".ts,.tsx,.mjs,.js,.jsx,.json"]
--js comma separated extensions indicate the file is js like
[string] [default: ".ts,.tsx,.mjs,.js,.jsx"]
--include included filenames regexp in string, default includes all files
[string] [default: ".*"]
--exclude excluded filenames regexp in string, set as empty string to include all files
[string] [default: "\/node_modules\/"]
--output, -o output json to file [string]
--tree print tree to stdout [boolean] [default: true]
--circular print circular to stdout [boolean] [default: true]
--warning print warning to stdout [boolean] [default: true]
--tsconfig the tsconfig path, which is used for resolve path alias, default is
tsconfig.json if it exists in context directory [string]
--transform, -T transform typescript modules to javascript before analyze, it allows you to
omit types dependency in typescript [boolean] [default: false]
--exit-code exit with specified code, the value format is CASE:CODE, `circular` is the
only supported CASE, CODE should be a integer between 0 and 128. For example:
`dpdm --exit-code circular:1` the program will exit with code 1 if circular
dependency found. [string]
-h, --help Show help [boolean]
The result example:
Usage in module
import { parseDependencyTree, parseCircular, prettyCircular } from 'dpdm';
parseDependencyTree('./index', {
}).then((tree) => {
const circulars = parseCircular(tree);
console.log(prettyCircular(circulars));
});
API
-
parseDependencyTree(entries, option, output)
: parse dependencies for glob entries
export declare function parseDependencyTree(
entries: string | string[],
options: ParserOptions,
): Promise<DependencyTree>;
export interface ParseOptions {
context: string;
extensions: string[];
include: RegExp;
exclude: RegExp;
}
export enum DependencyKind {
CommonJS = 'CommonJS',
StaticImport = 'StaticImport',
DynamicImport = 'DynamicImport',
StaticExport = 'StaticExport',
}
export interface Dependency {
issuer: string;
request: string;
kind: DependencyKind;
id: string | null;
}
export type DependencyTree = Record<string, Dependency[] | null>;
-
parseCircular(tree)
: parse circulars in dependency tree
export declare function parseCircular(tree: DependencyTree): string[][];
TODO
LICENSE
MIT