### Install DPDM Globally via Yarn Source: https://github.com/acrazing/dpdm/blob/master/README.md Install the DPDM command-line interface globally using Yarn. This is an alternative to npm for global installations. ```bash yarn global add dpdm ``` -------------------------------- ### Install DPDM Globally via npm Source: https://github.com/acrazing/dpdm/blob/master/README.md Install the DPDM command-line interface globally using npm. This allows you to use DPDM commands directly from your terminal. ```bash npm i -g dpdm ``` -------------------------------- ### Install DPDM as a Development Dependency via Yarn Source: https://github.com/acrazing/dpdm/blob/master/README.md Install DPDM as a development dependency in your project using Yarn. This is an alternative to npm for adding development dependencies. ```bash yarn add -D dpdm ``` -------------------------------- ### Install DPDM as a Development Dependency via npm Source: https://github.com/acrazing/dpdm/blob/master/README.md Install DPDM as a development dependency in your project using npm. This is suitable for integrating DPDM into your build or development workflow. ```bash npm i -D dpdm ``` -------------------------------- ### Parse Dependency Tree and Find Circulars Source: https://github.com/acrazing/dpdm/blob/master/README.md Use this snippet to parse the dependency tree of a project starting from a specified entry point and then identify and display any circular dependencies found. ```typescript jsx import { parseDependencyTree, parseCircular, prettyCircular } from 'dpdm'; parseDependencyTree('./index', { /* options, see below */ }).then((tree) => { const circulars = parseCircular(tree); console.log(prettyCircular(circulars)); }); ``` -------------------------------- ### Simple dpdm Usage Source: https://github.com/acrazing/dpdm/blob/master/README.md Basic command to analyze dependencies for a given file. ```bash dpdm ./src/index.ts ``` -------------------------------- ### DPDM CLI Options Source: https://github.com/acrazing/dpdm/blob/master/README.md Overview of available command-line options for dpdm, including positional arguments and flags for configuration. ```bash dpdm [options] Analyze the files' dependencies. Positionals: files The file paths or globs [string] Options: --version Show version number [boolean] --context the context directory to shorten path, default is cwd [string] --cwd the working directory used to match files and resolve relative paths, 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"] -o, --output 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] -T, --transform 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] --progress show progress bar [boolean] [default: true] --detect-unused-files-from this file is a glob, used for finding unused files. [string] --skip-dynamic-imports Skip parse import(...) statement. [string] [choices: "tree", "circular"] --skip-imports Skip import edges from circular checks. Values are regexp ISSUER:DEPENDENCY pairs. [array] --group-by-package print dependencies and circulars grouped by nearest package.json [boolean] -h, --help Show help [boolean] ``` -------------------------------- ### Group Dependencies by Package Source: https://github.com/acrazing/dpdm/blob/master/README.md Display dependencies and circular dependencies organized by their nearest package.json file. ```bash dpdm --group-by-package './packages/*/src/index.ts' ``` -------------------------------- ### Find Unused Files Source: https://github.com/acrazing/dpdm/blob/master/README.md Detect unused files by specifying a pattern for the files to search within and a pattern for the files to consider as entry points (e.g., 'index.js'). ```bash dpdm --no-tree --no-warning --no-circular --detect-unused-files-from 'src/**/*.*' 'index.js' ``` -------------------------------- ### Exit with Non-Zero Code on Circular Dependency Source: https://github.com/acrazing/dpdm/blob/master/README.md Configure dpdm to exit with a specific non-zero code if circular dependencies are detected. ```bash dpdm --exit-code circular:1 ./src/index.ts ``` -------------------------------- ### Print Circular Dependencies Only Source: https://github.com/acrazing/dpdm/blob/master/README.md Analyze dependencies and only display circular references, suppressing warnings and the dependency tree. ```bash dpdm --no-warning --no-tree ./src/index.ts ``` -------------------------------- ### Analyze Files from Another Working Directory Source: https://github.com/acrazing/dpdm/blob/master/README.md Use the --cwd option to specify a different working directory for file matching and path resolution. ```bash dpdm --cwd ../other-project ./src/index.ts ``` -------------------------------- ### groupDependencyTreeByPackage Source: https://github.com/acrazing/dpdm/blob/master/README.md Groups the dependency tree by the nearest package.json file, organizing dependencies based on their containing npm packages. ```APIDOC ## groupDependencyTreeByPackage ### Description Groups dependencies by the nearest package.json. ### Method `groupDependencyTreeByPackage(tree, context)` ### Parameters - **tree** (DependencyTree) - Required - The dependency tree to group. - **context** (string) - Required - The context for resolving packages. ### Return Value - **DependencyTree** - The dependency tree grouped by package. ``` -------------------------------- ### Ignore Specified Imports Source: https://github.com/acrazing/dpdm/blob/master/README.md Exclude specific import paths from being considered when detecting circular dependencies. Specify pairs of issuer and dependency using a regex. ```bash dpdm ./src/index.js --skip-imports 'src/a.js:.*' src/c.js:src/d.js ``` -------------------------------- ### Skip Dynamic Imports Source: https://github.com/acrazing/dpdm/blob/master/README.md Control whether dynamic imports are parsed. The 'circular' option ignores them only when parsing circular references, while 'tree' ignores them when parsing source files. ```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 ``` -------------------------------- ### parseCircular Source: https://github.com/acrazing/dpdm/blob/master/README.md Parses the dependency tree to identify and extract circular dependencies. ```APIDOC ## parseCircular ### Description Parses circular dependencies in the dependency tree. ### Method `parseCircular(tree)` ### Parameters - **tree** (DependencyTree) - Required - The dependency tree to parse. ### Return Value - **string[][]** - An array of arrays, where each inner array represents a circular dependency path. ``` -------------------------------- ### Ignore Type Dependencies in TypeScript Source: https://github.com/acrazing/dpdm/blob/master/README.md Use the -T or --transform flag to ignore type-only dependencies when analyzing TypeScript modules. ```bash dpdm -T ./src/index.ts ``` -------------------------------- ### parseDependencyTree Source: https://github.com/acrazing/dpdm/blob/master/README.md Parses the dependency tree for specified glob entries. It analyzes the import and require statements within the files to build a comprehensive dependency graph. ```APIDOC ## parseDependencyTree ### Description Parses dependencies for glob entries. ### Method `parseDependencyTree(entries, options)` ### Parameters #### Path Parameters - **entries** (string | string[]) - Required - The glob entries to match. - **options** (ParserOptions) - Required - The options for parsing. ### Options Interface (`ParseOptions`) - **cwd** (string) - The current working directory. - **context** (string) - The context for resolving modules. - **extensions** (string[]) - Array of file extensions to consider. - **js** (string[]) - Array of JavaScript file types to consider. - **include** (RegExp) - Regular expression to include files. - **exclude** (RegExp) - Regular expression to exclude files. - **tsconfig** (string | undefined) - Path to the tsconfig file. - **onProgress** (function) - Callback function for progress events ('start' | 'end'). - **transform** (boolean) - Whether to transform the code. - **skipDynamicImports** (boolean) - Whether to skip dynamic imports. ### Return Value - **Promise** - A promise that resolves to the dependency tree. ### Dependency Types (`DependencyKind`) - **CommonJS**: `require` statements. - **StaticImport**: `import ... from "foo"` statements. - **DynamicImport**: `import("foo")` statements. - **StaticExport**: `export ... from "foo"` statements. ### Dependency Interface (`Dependency`) - **issuer** (string) - The file that imports the dependency. - **request** (string) - The requested module. - **kind** (DependencyKind) - The type of dependency. - **id** (string | null) - The resolved filename, or null if unresolved. ### Dependency Tree Type (`DependencyTree`) - **Record** - An object where keys are file IDs and values are arrays of dependencies or null if ignored. ``` -------------------------------- ### groupDependencyTreeByPackage API Definition Source: https://github.com/acrazing/dpdm/blob/master/README.md Defines the `groupDependencyTreeByPackage` function. This function is used to group dependencies within a dependency tree by their nearest package.json. ```typescript jsx export declare function groupDependencyTreeByPackage( tree: DependencyTree, context: string, ): DependencyTree; ``` -------------------------------- ### parseDependencyTree API Definition Source: https://github.com/acrazing/dpdm/blob/master/README.md Defines the `parseDependencyTree` function signature and its associated `ParserOptions` interface. Use this to understand the parameters and configuration for parsing dependencies. ```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 { cwd: string; 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; ``` -------------------------------- ### parseCircular API Definition Source: https://github.com/acrazing/dpdm/blob/master/README.md Defines the `parseCircular` function. This function takes a dependency tree and returns an array of strings representing circular dependencies. ```typescript jsx export declare function parseCircular(tree: DependencyTree): string[][]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.