Analyze circular dependencies in your JavaScript/TypeScript projects with Rust.
npm install dpdm-fastA robust static dependency analyzer for your JavaScript and TypeScript projects with Rust !
Highlights
|
Install
|
Usage
|
Options
|
API
> This is fork from acrazing/dpdm, and compability with dpdm 99%. It's faster and bring a performance improvement of more than ten times!(Please use --no-progress to be fastest, progress will be slower than dpdm with node).
- Supports CommonJS, ESM.
- Supports JavaScript and TypeScript completely.
- Supports TypeScript path mapping.
- Supports ignore TypeScript type dependencies.
- Light weight: use TypeScript to parse all modules.
- Fast: use Rust and swc-parser to parse all modules. This will bring a performance improvement of more than ten times!
- Stable output: This is compared to madge, whose results are completely inconclusive when analyze TypeScript.
1. For command line
``bash`
npm i -g dpdm-fast
# or via yarn
yarn global add dpdm-fast
2. As a module
`bash`
npm i -D dpdm-fast
# or via yarn
yarn add -D dpdm-fast
1. Simple usage
`bash`
dpdm ./src/index.ts
2. Print circular dependencies only
`bash`
dpdm --no-warning --no-tree ./src/index.ts
3. Exit with a non-zero code if a circular dependency is found.
`bash`
dpdm --exit-code circular:1 ./src/index.ts
4. Ignore type dependencies for TypeScript modules
`bash`
dpdm -T ./src/index.ts
5. Find unused files by index.js in src directory:
`bash`
dpdm --no-tree --no-warning --no-circular --detect-unused-files-from 'src/*/.*' 'index.js'
6. Skip dynamic imports:
`bash`
# The value circular will only ignore the dynamic imports
# when parse circular references.
# You can set it as tree to ignore the dynamic imports
# when parse source files.
dpdm --skip-dynamic-imports circular index.js
`bash
$ dpdm --help
Analyze the files' dependencies.
Usage: dpdm [OPTIONS]
Arguments:
Options:
--context
The context directory to shorten path, default is current directory
-e, --extensions
Comma separated extensions to resolve [default: ts,tsx,mjs,js,jsx,json]
--js
Comma separated extensions indicate the file is js like [default: ts,tsx,mjs,js,jsx]
--include
Included filenames regexp in string, default includes all files [default: .*]
--exclude
Excluded filenames regexp in string, set as empty string to include all files [default: node_modules]
-o, --output
> TODO: This part has not yet been completed. So if you call the API, it will auto use dpdm-ts. Next time I will use wasm-bindgen to call rust api.
`typescript jsx
import { parseDependencyTree, parseCircular, prettyCircular } from 'dpdm';
parseDependencyTree('./index', {
/ options, see below /
}).then((tree) => {
const circulars = parseCircular(tree);
console.log(prettyCircular(circulars));
});
`
1. parseDependencyTree(entries, option, output): parse dependencies for glob entries
`typescript jsx
/**
* @param entries - the glob entries to match
* @param options - the options, see below
*/
export declare function parseDependencyTree(
entries: string | string[],
options: ParserOptions,
): Promise
/**
* the parse options
*/
export interface ParseOptions {
context: string;
extensions: string[];
js: string[];
include: RegExp;
exclude: RegExp;
tsconfig: string | undefined;
onProgress: (event: 'start' | 'end', target: string) => void;
transform: boolean;
skipDynamicImports: boolean;
}
export enum DependencyKind {
CommonJS = 'CommonJS', // require
StaticImport = 'StaticImport', // import ... from "foo"
DynamicImport = 'DynamicImport', // import("foo")
StaticExport = 'StaticExport', // export ... from "foo"
}
export interface Dependency {
issuer: string;
request: string;
kind: DependencyKind;
id: string | null; // the shortened, resolved filename, if cannot resolve, it will be null
}
// the parse tree result, key is file id, value is its dependencies
// if file is ignored, it will be null
export type DependencyTree = Record
`
2. parseCircular(tree): parse circulars in dependency tree
`typescript jsx``
export declare function parseCircular(tree: DependencyTree): string[][];
- [ ] Supports HTML and HTML like modules
- [ ] Supports CSS and CSS like modules
- [ ] Prints interactive SVG