Skip to content

Commit

Permalink
feat(deps,docs): upgrade to latest & update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
acrazing committed Apr 2, 2022
1 parent e14bc36 commit 6a31cb6
Show file tree
Hide file tree
Showing 6 changed files with 1,676 additions and 1,646 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
npx pretty-quick --staged
158 changes: 110 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,128 @@
# dpdm

A static dependencies analyzer for your `JavaScript` and `TypeScript` projects.

## Features
<h1 align="center">
DPDM
<br/>
<img src="https://img.shields.io/npm/v/dpdm" alt="version">
<img src="https://img.shields.io/npm/dm/dpdm" alt="downloads">
<img src="https://img.shields.io/github/stars/acrazing/dpdm" alt="stars">
<img src="https://img.shields.io/librariesio/github/acrazing/dpdm" alt="dependencies">
<img src="https://img.shields.io/github/license/acrazing/dpdm" alt="license">
</h1>

<p align="center">A robust static dependency analyzer for your <code>JavaScript</code> and <code>TypeScript</code> projects.</p>

<p align="center">
<a href="#highlights">Highlights</a>
<span>&nbsp;|&nbsp;</span>
<a href="#install">Install</a>
<span>&nbsp;|&nbsp;</span>
<a href="#usage-in-command-line">Usage</a>
<span>&nbsp;|&nbsp;</span>
<a href="#options">Options</a>
<span>&nbsp;|&nbsp;</span>
<a href="#usage-as-a-package">API</a>
</p>

## Highlights

- Supports `CommonJS`, `ESM`.
- Supports `JavaScript` and `TypeScript` completely.
- Supports TypeScript [path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping).
- Supports ignore TypeScript type dependency
- Light weight: use [typescript](https://npmjs.com/package/typescript) to parse all modules.
- Supports ignore TypeScript type dependencies.
- Light weight: use [TypeScript](https://npmjs.com/package/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`.
- Stable output: This is compared to `madge`, whose results are completely inconclusive when analyze `TypeScript`.

## Install

```bash
npm i dpdm # or yarn add dpdm
1. For command line

# use as command line
npm i -g dpdm # or yarn global add dpdm
dpdm --help
```
```bash
npm i -g dpdm
# or via yarn
yarn global add dpdm
```

2. As a module

```bash
npm i -D dpdm
# or via yarn
yarn add -D dpdm
```

## Usage in command line

1. Simple usage

```bash
dpdm ./src/index.ts
```

2. Print circular dependencies only

## Usage in line
```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
```

### Options

```bash
dpdm.ts [options] files...
$ dpdm --help
dpdm [options] <files...>

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 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]
--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"]
-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]
-h, --help Show help [boolean]
```
> The result example:
> ![](./assets/screenshot.png)
### Example output
## Usage in module
![Screenshot](./assets/screenshot.png)
## Usage as a package
```typescript jsx
import { parseDependencyTree, parseCircular, prettyCircular } from 'dpdm';
Expand All @@ -69,7 +135,7 @@ parseDependencyTree('./index', {
});
```
## API
### API Reference
1. `parseDependencyTree(entries, option, output)`: parse dependencies for glob entries
Expand Down Expand Up @@ -118,12 +184,8 @@ parseDependencyTree('./index', {
export declare function parseCircular(tree: DependencyTree): string[][];
```
## TODO
## TODOs
- [ ] Supports HTML and HTML like modules
- [ ] Supports CSS and CSS like modules
- [ ] Prints interactive SVG
## LICENSE
[MIT](./LICENSE)
Binary file modified assets/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 12 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dpdm",
"version": "3.8.0",
"version": "3.9.0",
"description": "Analyze circular dependencies in your JavaScript/TypeScript projects.",
"keywords": [
"circular",
Expand Down Expand Up @@ -50,32 +50,27 @@
},
"license": "MIT",
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/jest": "^27.4.1",
"husky": "^7.0.4",
"jest": "^27.4.5",
"lint-staged": "^12.1.4",
"jest": "^27.5.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"rollup": "^2.62.0",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0"
"prettier": "^2.6.1",
"pretty-quick": "^3.1.3",
"rollup": "^2.70.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0"
},
"dependencies": {
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/yargs": "^17.0.8",
"@types/yargs": "^17.0.10",
"chalk": "^4.1.2",
"fs-extra": "^10.0.0",
"fs-extra": "^10.0.1",
"glob": "^7.2.0",
"ora": "^5.4.1",
"tslib": "^2.3.1",
"typescript": "^4.5.4",
"yargs": "^17.3.1"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,less,scss,md}": [
"prettier --write"
]
"typescript": "^4.6.3",
"yargs": "^17.4.0"
},
"jest": {
"moduleFileExtensions": [
Expand Down
8 changes: 4 additions & 4 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ describe('util', () => {
const local = await simpleResolver(__dirname, './bin/dpdm', ext);
const index = await simpleResolver(__dirname, '.', ext);
// dependents on yarn.lock
const pkg = await simpleResolver(__dirname, 'expect', ext);
const deepPkg = await simpleResolver(dirname(pkg!), 'ansi-styles', ext);
const pkg = await simpleResolver(__dirname, 'string_decoder', ext);
const deepPkg = await simpleResolver(dirname(pkg!), 'safe-buffer', ext);
const notFound = await simpleResolver(__dirname, './utils.tsx', ext);
expect([local, index, pkg, deepPkg, notFound]).toEqual([
join(__dirname, 'bin/dpdm.ts'),
join(__dirname, 'index.ts'),
join(__dirname, '../node_modules/expect/build/index.js'),
join(__dirname, '../node_modules/string_decoder/lib/string_decoder.js'),
join(
__dirname,
'../node_modules/expect/node_modules/ansi-styles/index.js',
'../node_modules/string_decoder/node_modules/safe-buffer/index.js',
),
null,
]);
Expand Down
Loading

0 comments on commit 6a31cb6

Please sign in to comment.