dpdm
Advanced tools
Comparing version 3.8.0 to 3.9.0
@@ -9,11 +9,11 @@ #!/usr/bin/env node | ||
const tslib_1 = require("tslib"); | ||
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk")); | ||
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra")); | ||
const ora_1 = (0, tslib_1.__importDefault)(require("ora")); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const yargs_1 = (0, tslib_1.__importDefault)(require("yargs")); | ||
const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); | ||
const ora_1 = tslib_1.__importDefault(require("ora")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const yargs_1 = tslib_1.__importDefault(require("yargs")); | ||
const parser_1 = require("../parser"); | ||
const utils_1 = require("../utils"); | ||
function main() { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const argv = yield yargs_1.default | ||
@@ -148,3 +148,3 @@ .strict() | ||
(0, parser_1.parseDependencyTree)(files, options) | ||
.then((tree) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
.then((tree) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
o.succeed(`[${ended}/${total}] Analyze done!`); | ||
@@ -167,3 +167,3 @@ const entriesDeep = yield Promise.all(files.map((g) => (0, utils_1.glob)(g))); | ||
if (circulars.length === 0) { | ||
console.log(chalk_1.default.bold.green(' ✅ Congratulations, no circular dependency were found in your project.')); | ||
console.log(chalk_1.default.bold.green(' ✅ Congratulations, no circular dependency was found in your project.')); | ||
} | ||
@@ -170,0 +170,0 @@ else { |
@@ -8,5 +8,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
(0, tslib_1.__exportStar)(require("./parser"), exports); | ||
(0, tslib_1.__exportStar)(require("./types"), exports); | ||
(0, tslib_1.__exportStar)(require("./utils"), exports); | ||
tslib_1.__exportStar(require("./parser"), exports); | ||
tslib_1.__exportStar(require("./types"), exports); | ||
tslib_1.__exportStar(require("./utils"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -9,5 +9,5 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra")); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const typescript_1 = (0, tslib_1.__importDefault)(require("typescript")); | ||
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const typescript_1 = tslib_1.__importDefault(require("typescript")); | ||
const consts_1 = require("./consts"); | ||
@@ -22,3 +22,3 @@ const utils_1 = require("./utils"); | ||
function parseTreeRecursive(context, request, options, output, resolve) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const id = yield resolve(context, request, options.extensions); | ||
@@ -108,3 +108,3 @@ if (!id || output[id]) { | ||
function parseDependencyTree(entries, options) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (!Array.isArray(entries)) { | ||
@@ -120,3 +120,3 @@ entries = [entries]; | ||
const host = typescript_1.default.createCompilerHost(compilerOptions); | ||
resolve = (context, request, extensions) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
resolve = (context, request, extensions) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const module = typescript_1.default.resolveModuleName(request, path_1.default.join(context, 'index.ts'), compilerOptions, host).resolvedModule; | ||
@@ -123,0 +123,0 @@ if (module && module.extension !== typescript_1.default.Extension.Dts) { |
@@ -9,8 +9,8 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk")); | ||
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra")); | ||
const glob_1 = (0, tslib_1.__importDefault)(require("glob")); | ||
const chalk_1 = tslib_1.__importDefault(require("chalk")); | ||
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); | ||
const glob_1 = tslib_1.__importDefault(require("glob")); | ||
const module_1 = require("module"); | ||
const path_1 = (0, tslib_1.__importDefault)(require("path")); | ||
const util_1 = (0, tslib_1.__importDefault)(require("util")); | ||
const path_1 = tslib_1.__importDefault(require("path")); | ||
const util_1 = tslib_1.__importDefault(require("util")); | ||
const allBuiltins = new Set(module_1.builtinModules); | ||
@@ -59,3 +59,3 @@ exports.glob = util_1.default.promisify(glob_1.default); | ||
function appendSuffix(request, extensions) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
for (const ext of extensions) { | ||
@@ -81,3 +81,3 @@ try { | ||
exports.appendSuffix = appendSuffix; | ||
const simpleResolver = (context, request, extensions) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
const simpleResolver = (context, request, extensions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
if (path_1.default.isAbsolute(request)) { | ||
@@ -84,0 +84,0 @@ return appendSuffix(request, extensions); |
@@ -11,3 +11,3 @@ "use strict"; | ||
describe('util', () => { | ||
it('should resolve correctly', () => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () { | ||
it('should resolve correctly', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const ext = ['', '.js', '.jsx', '.ts', '.tsx', '.json']; | ||
@@ -17,4 +17,4 @@ const local = yield (0, utils_1.simpleResolver)(__dirname, './bin/dpdm', ext); | ||
// dependents on yarn.lock | ||
const pkg = yield (0, utils_1.simpleResolver)(__dirname, 'expect', ext); | ||
const deepPkg = yield (0, utils_1.simpleResolver)((0, path_1.dirname)(pkg), 'ansi-styles', ext); | ||
const pkg = yield (0, utils_1.simpleResolver)(__dirname, 'string_decoder', ext); | ||
const deepPkg = yield (0, utils_1.simpleResolver)((0, path_1.dirname)(pkg), 'safe-buffer', ext); | ||
const notFound = yield (0, utils_1.simpleResolver)(__dirname, './utils.tsx', ext); | ||
@@ -24,4 +24,4 @@ expect([local, index, pkg, deepPkg, notFound]).toEqual([ | ||
(0, path_1.join)(__dirname, 'index.ts'), | ||
(0, path_1.join)(__dirname, '../node_modules/expect/build/index.js'), | ||
(0, path_1.join)(__dirname, '../node_modules/expect/node_modules/ansi-styles/index.js'), | ||
(0, path_1.join)(__dirname, '../node_modules/string_decoder/lib/string_decoder.js'), | ||
(0, path_1.join)(__dirname, '../node_modules/string_decoder/node_modules/safe-buffer/index.js'), | ||
null, | ||
@@ -28,0 +28,0 @@ ]); |
{ | ||
"name": "dpdm", | ||
"version": "3.8.0", | ||
"version": "3.9.0", | ||
"description": "Analyze circular dependencies in your JavaScript/TypeScript projects.", | ||
@@ -53,30 +53,24 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/jest": "^27.0.1", | ||
"husky": "^7.0.2", | ||
"jest": "^27.1.1", | ||
"lint-staged": "^11.1.2", | ||
"@types/jest": "^27.4.1", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.4.0", | ||
"rollup": "^2.56.3", | ||
"ts-jest": "^27.0.5", | ||
"ts-node": "^10.2.1" | ||
"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.12", | ||
"@types/glob": "^7.1.4", | ||
"@types/yargs": "^17.0.2", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/glob": "^7.2.0", | ||
"@types/yargs": "^17.0.10", | ||
"chalk": "^4.1.2", | ||
"fs-extra": "^10.0.0", | ||
"glob": "^7.1.7", | ||
"fs-extra": "^10.0.1", | ||
"glob": "^7.2.0", | ||
"ora": "^5.4.1", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.3", | ||
"yargs": "^17.1.1" | ||
"typescript": "^4.6.3", | ||
"yargs": "^17.4.0" | ||
}, | ||
"cliVersion": "8.8.4", | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx,json,css,less,scss,md}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"jest": { | ||
@@ -83,0 +77,0 @@ "moduleFileExtensions": [ |
154
README.md
@@ -1,61 +0,127 @@ | ||
# dpdm | ||
<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> | ||
A static dependencies analyzer for your `JavaScript` and `TypeScript` projects. | ||
<p align="center">A robust static dependency analyzer for your <code>JavaScript</code> and <code>TypeScript</code> projects.</p> | ||
## Features | ||
<p align="center"> | ||
<a href="#highlights">Highlights</a> | ||
<span> | </span> | ||
<a href="#install">Install</a> | ||
<span> | </span> | ||
<a href="#usage-in-command-line">Usage</a> | ||
<span> | </span> | ||
<a href="#options">Options</a> | ||
<span> | </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 | ||
``` | ||
## Usage in line | ||
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 | ||
```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 | ||
@@ -72,3 +138,3 @@ import { parseDependencyTree, parseCircular, prettyCircular } from 'dpdm'; | ||
## API | ||
### API Reference | ||
@@ -122,3 +188,3 @@ 1. `parseDependencyTree(entries, option, output)`: parse dependencies for glob entries | ||
## TODO | ||
## TODOs | ||
@@ -128,5 +194,1 @@ - [ ] Supports HTML and HTML like modules | ||
- [ ] Prints interactive SVG | ||
## LICENSE | ||
[MIT](./LICENSE) |
@@ -201,3 +201,3 @@ #!/usr/bin/env node | ||
chalk.bold.green( | ||
' ✅ Congratulations, no circular dependency were found in your project.', | ||
' ✅ Congratulations, no circular dependency was found in your project.', | ||
), | ||
@@ -204,0 +204,0 @@ ); |
@@ -15,4 +15,4 @@ /*! | ||
// 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); | ||
@@ -22,6 +22,6 @@ expect([local, index, pkg, deepPkg, notFound]).toEqual([ | ||
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', | ||
), | ||
@@ -28,0 +28,0 @@ null, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
192
251100
+ Added@types/node@20.14.2(transitive)
+ Addedtslib@2.6.3(transitive)
- Removed@types/node@20.14.1(transitive)
- Removedtslib@2.6.2(transitive)
Updated@types/fs-extra@^9.0.13
Updated@types/glob@^7.2.0
Updated@types/yargs@^17.0.10
Updatedfs-extra@^10.0.1
Updatedglob@^7.2.0
Updatedtypescript@^4.6.3
Updatedyargs@^17.4.0